Class: CocinaDisplay::Events::Location
- Inherits:
-
Object
- Object
- CocinaDisplay::Events::Location
- Defined in:
- lib/cocina_display/events/location.rb
Overview
A single location represented in a Cocina event, like a publication place.
Constant Summary collapse
- MARC_COUNTRIES_FILE_PATH =
CocinaDisplay.root / "config" / "marc_countries.yml"
Instance Attribute Summary collapse
-
#cocina ⇒ Object
readonly
Returns the value of attribute cocina.
Class Method Summary collapse
-
.marc_countries ⇒ Hash{String => String}
A hash mapping MARC country codes to their names.
Instance Method Summary collapse
-
#country_name ⇒ String?
Decoded country name if the location is encoded with a MARC country code.
-
#initialize(cocina) ⇒ Location
constructor
Initialize a Location object with Cocina structured data.
-
#to_s ⇒ String?
The name of the location.
-
#unencoded_value? ⇒ Boolean
Is there an unencoded value (name) for this location?.
Constructor Details
#initialize(cocina) ⇒ Location
Initialize a Location object with Cocina structured data.
17 18 19 |
# File 'lib/cocina_display/events/location.rb', line 17 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/events/location.rb', line 7 def cocina @cocina end |
Class Method Details
.marc_countries ⇒ Hash{String => String}
A hash mapping MARC country codes to their names.
11 12 13 |
# File 'lib/cocina_display/events/location.rb', line 11 def self.marc_countries @marc_countries ||= YAML.safe_load_file(MARC_COUNTRIES_FILE_PATH) end |
Instance Method Details
#country_name ⇒ String?
Decoded country name if the location is encoded with a MARC country code.
36 37 38 |
# File 'lib/cocina_display/events/location.rb', line 36 def country_name Location.marc_countries[code] if marc_country? && valid_country_code? end |
#to_s ⇒ String?
The name of the location. Decodes a MARC country code if present and no value was present.
24 25 26 |
# File 'lib/cocina_display/events/location.rb', line 24 def to_s cocina["value"] || country_name end |
#unencoded_value? ⇒ Boolean
Is there an unencoded value (name) for this location?
30 31 32 |
# File 'lib/cocina_display/events/location.rb', line 30 def unencoded_value? cocina["value"].present? end |