Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
* Use 'cls' when calling class or static methods from class method
* Create submethod for 'get_locations'
  • Loading branch information
jonavellecuerdo committed Jul 30, 2024
1 parent 2d2f83e commit 891cbce
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions transmogrifier/sources/xml/marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def _get_language_names(
language_name
for language_code in list(dict.fromkeys(language_codes))
if (
language_name := Marc.loc_crosswalk_code_to_name(
language_name := cls.loc_crosswalk_code_to_name(
language_code,
cls.language_code_crosswalk,
cls.get_source_record_id(source_record),
Expand Down Expand Up @@ -826,21 +826,9 @@ def get_locations(cls, source_record: Tag) -> list[timdex.Location] | None:
"kind": "Hierarchical Place Name",
},
]

# get locations (place of publication) from control field 008/15-17
if (
fixed_location_code := cls._get_control_field(source_record)[15:18].strip()
) and (
location_name := Marc.loc_crosswalk_code_to_name(
code=fixed_location_code,
crosswalk=cls.country_code_crosswalk,
record_id=cls.get_source_record_id(source_record),
code_type="country",
)
):
locations.append(
timdex.Location(value=location_name, kind="Place of Publication")
)
if place_of_publication := cls._get_location_publication(source_record):
locations.append(place_of_publication)

# get locations from data fields
for location_marc_field in location_marc_fields:
Expand All @@ -866,6 +854,21 @@ def get_locations(cls, source_record: Tag) -> list[timdex.Location] | None:
)
return locations or None

@classmethod
def _get_location_publication(cls, source_record: Tag) -> timdex.Location | None:
if (
fixed_location_code := cls._get_control_field(source_record)[15:18].strip()
) and (
location_name := cls.loc_crosswalk_code_to_name(
code=fixed_location_code,
crosswalk=cls.country_code_crosswalk,
record_id=cls.get_source_record_id(source_record),
code_type="country",
)
):
return timdex.Location(value=location_name, kind="Place of Publication")
return None

@classmethod
def get_notes(cls, source_record: Tag) -> list[timdex.Note] | None:
notes = []
Expand Down

0 comments on commit 891cbce

Please sign in to comment.