Skip to content
Snippets Groups Projects
Commit 87844728 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

ENH: BIDSFile.match option to disable suffix match

parent cbf70da9
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
.. autosummary:: .. autosummary::
:nosignatures: :nosignatures:
BIDSFile
isBIDSDir isBIDSDir
inBIDSDir inBIDSDir
isBIDSFile isBIDSFile
...@@ -57,20 +58,34 @@ class BIDSFile(object): ...@@ -57,20 +58,34 @@ class BIDSFile(object):
self.suffix = suffix self.suffix = suffix
def match(self, other): def __str__(self):
"""Return a strimg representation of this ``BIDSFile``. """
return 'BIDSFile({})'.format(self.filename)
def __repr__(self):
"""Return a strimg representation of this ``BIDSFile``. """
return str(self)
def match(self, other, suffix=True):
"""Compare this ``BIDSFile`` to ``other``. """Compare this ``BIDSFile`` to ``other``.
:arg other: ``BIDSFile`` to compare :arg other: ``BIDSFile`` to compare
:returns: ``True`` if ``self.suffix == other.suffix`` and if
all of the entities in ``other`` are present in ``self``, :arg suffix: Defaults to ``True``. If ``False``, the comparison
``False`` otherwise. is made solely on the entity values.
:returns: ``True`` if ``self.suffix == other.suffix`` (unless
``suffix`` is ``False``) and if all of the entities in
``other`` are present in ``self``, ``False`` otherwise.
""" """
suffix = self.suffix == other.suffix suffix = (not suffix) or (self.suffix == other.suffix)
entities = True entities = True
for key, value in other.entities.items(): for key, value in other.entities.items():
entities = entities and self.entities.get(key, None) == value entities = entities and (self.entities.get(key, None) == value)
return suffix and entities return suffix and entities
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment