Class: CocinaDisplay::Language

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina_display/language.rb

Overview

A language associated with part or all of a Cocina object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cocina) ⇒ Language

Create a Language object from Cocina structured data.

Parameters:

  • cocina (Hash)


11
12
13
# File 'lib/cocina_display/language.rb', line 11

def initialize(cocina)
  @cocina = cocina
end

Instance Attribute Details

#cocinaObject (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

#codeString?

The language code, e.g. an ISO 639 code like “eng” or “spa”.

Returns:

  • (String, nil)


23
24
25
# File 'lib/cocina_display/language.rb', line 23

def code
  cocina["code"]
end

#decoded_valueString?

Decoded name of the language based on the code, if present.

Returns:

  • (String, nil)


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_strString?

The language name for display.

Returns:

  • (String, nil)


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.

Returns:

  • (Boolean)

See Also:



36
37
38
# File 'lib/cocina_display/language.rb', line 36

def searchworks_language?
  Vocabularies::SEARCHWORKS_LANGUAGES.value?(display_str)
end