-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i2069: Add a new field for specific languages on the Show page
- Loading branch information
1 parent
e3b8467
commit 0677f2a
Showing
10 changed files
with
844 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,4 +91,4 @@ end | |
|
||
gem "omniauth-rails_csrf_protection" | ||
|
||
gem "human_languages", "~> 0.6.0" | ||
gem "human_languages", "~> 0.7" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# A class to pull out language information from | ||
# a MARC record | ||
class LanguageExtractor | ||
def initialize(language_service, marc_record) | ||
@marc_record = marc_record | ||
@language_service = language_service | ||
end | ||
|
||
def specific_codes | ||
codes = [] | ||
codes << fixed_field_code if fixed_field_code | ||
|
||
if iso_041_fields.any? | ||
codes.concat(iso_041_codes) | ||
elsif all_041_fields.any? | ||
codes.concat(all_041_codes) | ||
end | ||
codes.reject { |general_code| includes_more_specific_version?(codes, general_code) } | ||
end | ||
|
||
def specific_names | ||
specific_codes.map { |code| @language_service.code_to_name(code) } | ||
.compact | ||
end | ||
|
||
private | ||
|
||
def includes_more_specific_version?(codes, code_to_check) | ||
codes.any? { |individual| @language_service.macrolanguage_codes(individual).include? code_to_check } | ||
end | ||
|
||
def iso_041_fields | ||
all_041_fields.select { |field| field['2'] == 'iso639-3' } | ||
end | ||
|
||
def all_041_fields | ||
@marc_record.fields('041') | ||
end | ||
|
||
def fixed_field_code | ||
value = @marc_record['008']&.value | ||
fixed_field_code = value ? value[35, 3] : nil | ||
end | ||
|
||
def iso_041_codes | ||
return [] unless iso_041_fields.any? | ||
extract_from_multiple_041s(iso_041_fields) | ||
end | ||
|
||
def all_041_codes | ||
return [] unless all_041_fields.any? | ||
extract_from_multiple_041s(all_041_fields) | ||
end | ||
|
||
def extract_from_multiple_041s(fields) | ||
fields.map do |field| | ||
field.subfields.select { |sf| %(a h).include? sf.code } | ||
.map(&:value) | ||
end.flatten | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.