Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use only first letter of alphabetical indicators #509

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions fixtures/merger/instance_parse/subcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,17 @@
"extent_type": "folder",
"number": 5
}]
},
{
"source": [{
"sub_container": {
"indicator_2": "Ar - Be",
"type_2": "folder"
}
}],
"parsed": [{
"extent_type": "folder",
"number": 2
}]
}
]
6 changes: 4 additions & 2 deletions merger/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ def indicator_to_integer(indicator):
"""Converts an instance indicator to an integer.

An indicator can be an integer (23) a combination of integers and letters (23b)
or just a letter (B).
or just letters (B, Be). In cases where indicator data only consists of letters,
the function will return an integer based on the ordinal value of the lowercased
first letter in the indicator.
"""
try:
integer = int(indicator)
except ValueError:
parsed = re.sub("[^0-9]", "", indicator)
if len(parsed):
return indicator_to_integer(parsed)
integer = ord(indicator.lower()) - 97
integer = ord(indicator[0].lower()) - 97
return integer


Expand Down