Class: CocinaDisplay::Language
- Inherits:
-
Object
- Object
- CocinaDisplay::Language
- Defined in:
- lib/cocina_display/language.rb
Overview
A language associated with part or all of a Cocina object.
Instance Attribute Summary collapse
-
#cocina ⇒ Object
readonly
Returns the value of attribute cocina.
Instance Method Summary collapse
-
#code ⇒ String?
The language code, e.g.
-
#decoded_value ⇒ String?
Decoded name of the language based on the code, if present.
-
#display_str ⇒ String?
The language name for display.
-
#initialize(cocina) ⇒ Language
constructor
Create a Language object from Cocina structured data.
-
#iso_639? ⇒ Boolean
True if the language has a code sourced from the ISO 639 vocabulary.
-
#searchworks_language? ⇒ Boolean
True if the language is recognized by Searchworks.
Constructor Details
#initialize(cocina) ⇒ Language
Create a Language object from Cocina structured data.
11 12 13 |
# File 'lib/cocina_display/language.rb', line 11 def initialize(cocina) @cocina = cocina end |
Instance Attribute Details
#cocina ⇒ Object (readonly)
Returns the value of attribute cocina.
7 8 9 |
# File 'lib/cocina_display/language.rb', line 7 def cocina @cocina end |
Instance Method Details
#code ⇒ String?
The language code, e.g. an ISO 639 code like “eng” or “spa”.
23 24 25 |
# File 'lib/cocina_display/language.rb', line 23 def code cocina["code"] end |
#decoded_value ⇒ String?
Decoded name of the language based on the code, if present.
29 30 31 |
# File 'lib/cocina_display/language.rb', line 29 def decoded_value Vocabularies::SEARCHWORKS_LANGUAGES[code] || (Iso639[code] if iso_639?) end |
#display_str ⇒ String?
The language name for display.
17 18 19 |
# File 'lib/cocina_display/language.rb', line 17 def display_str cocina["value"] || decoded_value end |
#iso_639? ⇒ Boolean
True if the language has a code sourced from the ISO 639 vocabulary.
43 44 45 |
# File 'lib/cocina_display/language.rb', line 43 def iso_639? cocina.dig("source", "code")&.start_with? "iso639" end |
#searchworks_language? ⇒ Boolean
True if the language is recognized by Searchworks.
36 37 38 |
# File 'lib/cocina_display/language.rb', line 36 def searchworks_language? Vocabularies::SEARCHWORKS_LANGUAGES.value?(display_str) end |