Skip to content

Commit 1428be7

Browse files
authored
Merge pull request #88 from ArcanaFramework/docs-update
updated docs to include optional content types
2 parents 8010f0f + d80a713 commit 1428be7

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

docs/source/detection.rst

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ To check whether a format matches without attempting to initialise the object us
3737
...
3838
3939
40-
Directories are classified by the contents of the files within them, via the
41-
``content_types`` class attribute, e.g.
40+
Formats that consists of directories with specific nested file formats within them can
41+
be defined using the ``TypedDirectory`` with ``content_types`` class attribute, e.g.
4242

4343
.. code-block:: python
4444
@@ -48,7 +48,7 @@ Directories are classified by the contents of the files within them, via the
4848
magic_number = b"DICM"
4949
magic_number_offset = 128
5050
51-
class DicomDir(Directory):
51+
class DicomDir(TypedDirectory):
5252
content_types = (Dicom,)
5353
5454
@@ -71,7 +71,30 @@ despite the presence of the ``.DS_Store`` directory and the ``catalog.xml`` file
7171
├── 1024.dcm
7272
└── catalog.xml
7373
74-
In addition to statically defining `Directory` formats such as the Dicom example above,
74+
The file-sets contained within the directory can be accessed via the ``contents`` attribute
75+
76+
.. code-block:: python
77+
78+
dicom_dir = DicomDir("dicom-directory")
79+
for dicom_file in dicom_dir.contents:
80+
assert isinstance(dicom_file, Dicom)
81+
82+
For types with optional content types, the ``content_types`` attribute can be set to
83+
an "optional", i.e. ``Xml | None``, and the ``contents`` attribute will include these
84+
optional types in addition to the required types
85+
86+
87+
.. code-block:: python
88+
89+
class CatalogedDicomDir(TypedDirectory):
90+
content_types = (Dicom, Xml | None)
91+
92+
dicom_dir = DicomDir("dicom-directory")
93+
for dicom_file in dicom_dir.contents:
94+
assert isinstance(dicom_file, (Dicom, Xml))
95+
96+
97+
In addition to statically defining `TypedDirectory` formats such as the Dicom example above,
7598
dynamic directory types can be created on the fly by providing the content types as
7699
"classifier" arguments to the `DirectoryOf[]` class (see :ref:`Classifiers`),
77100
e.g.

0 commit comments

Comments
 (0)