Skip to content
Snippets Groups Projects
Commit b5414af6 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

DOC: Fix docstring format

parent fe4d858a
No related branches found
No related tags found
2 merge requests!217TST: Make NamedTemporaryFiles Windows-compatible,!199Match properties feature for DictElementConverter
Pipeline #57830 passed
......@@ -9,8 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ###
- DictElementConverters can now make use of `match_properties` which works analogous to `match_properties` in ROCrateEntityConverter and `match_attrib` in XMLConverter.
- `match_properties` is a method of class Converter and can for example be used by CustomConverters.
- DictElementConverters can now make use of `match_properties` which
works analogous to `match_properties` in ROCrateEntityConverter and
`match_attrib` in XMLConverter.
- `match_properties` is a method of class Converter and can for
example be used by CustomConverters.
### Changed ###
......
......@@ -457,32 +457,34 @@ class Converter(object, metaclass=ABCMeta):
values.update(m)
def match_properties(self, properties: dict, vardict: dict, label: str = "match_properties"):
"""
This method can be used to generically match 'match_properties' from the cfood definition
"""This method can be used to generically match 'match_properties' from the cfood definition
with the behavior described as follows:
'match_properties' is a dictionary of key-regexps and value-regexp pairs. Each key matches
a property name and the corresponding value matches its property value.
What a property means in the context of the respective converter can be different, examples:
XMLTag: attributes of the node
ROCrate: properties of the ROCrateEntity
DictElement: properties of the dict
* XMLTag: attributes of the node
* ROCrate: properties of the ROCrateEntity
* DictElement: properties of the dict
label can be used to customize the name of the dictionary in the definition.
This method is not called by default, but can be called from child classes.
Typically it would be used like this from methods overwriting `match`:
> if not self.match_properties(<properties>, vardict):
> return None
Typically it would be used like this from methods overwriting `match`::
if not self.match_properties(<properties>, vardict):
return None
vardict will be updated in place when there are matches.
<properties> is a dictionary taken from the structure element that contains the properties in the
context of this converter.
vardict will be updated in place when there are
matches. <properties> is a dictionary taken from the structure
element that contains the properties in the context of this
converter.
Arguments:
Parameters
----------
properties: dict
......@@ -492,13 +494,18 @@ class Converter(object, metaclass=ABCMeta):
This dictionary will be used to store the variables created during the matching.
label: str
Default "match_properties". Can be used to change the name of the property in the definition. E.g. the
xml converter uses "match_attrib" which makes more sense in the context of xml trees.
Default "match_properties". Can be used to change the name
of the property in the definition. E.g. the xml converter
uses "match_attrib" which makes more sense in the context
of xml trees.
Returns
-------
Returns:
--------
: bool
Returns True when properties match and False
otherwise. The vardict dictionary is updated in place.
Returns True when properties match and False otherwise. The vardict dictionary is updated in place.
"""
if label in self.definition:
# This matcher works analogously to the attributes matcher in the XMLConverter
......
......@@ -207,7 +207,7 @@ following.
ValueWithUnitElt:
type: TextElement
match_name: ^my_prop$
match_value: "^(?P<number>\\d+\\.?\\d*)\s+(?P<unit>.+)" # Extract value and unit from a string which
match_value: "^(?P<number>\\d+\\.?\\d*)\\s+(?P<unit>.+)" # Extract value and unit from a string which
# has a number followed by at least one whitespace
# character followed by a unit.
records:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment