Class: Unlocodes::Entry
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Unlocodes::Entry
- Defined in:
- lib/unlocodes/entry.rb
Overview
A single UN/LOCODE entry.
Stores wire-level fields as lutaml-model attributes and exposes typed
helpers (#coordinates, .function_description) for ergonomic queries. The
LOCODE itself is the 5-character composite of country (ISO 3166-1
alpha-2) + the 3-character location alpha. The code attribute is the
canonical 5-char string.
latitude and longitude are decimal degrees (WGS-84), populated when
the source vocabulary provides geo:lat / geo:long.
Constant Summary collapse
- FUNCTION_DESCRIPTIONS =
UN/LOCODE manual function classifier letters and their human-readable descriptions. Source: UN/LOCODE manual, "Code list for function".
{ 'B' => 'Port (sea)', 'R' => 'Rail terminal', 'T' => 'Road terminal', 'A' => 'Airport', 'P' => 'Postal exchange office', 'I' => 'Inland water transport (river)', 'F' => 'Ferry port', 'V' => 'Pipeline', 'O' => 'Other (border crossing, etc.)', '0' => 'Function not known', '1' => 'Not provided' }.freeze
Class Method Summary collapse
-
.function_description(letter) ⇒ String?
Look up the human-readable description for a function letter.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #airport? ⇒ Boolean
- #coordinates ⇒ Object
- #eql?(other) ⇒ Boolean
- #function?(letter) ⇒ Boolean
- #hash ⇒ Object
- #port? ⇒ Boolean
- #rail_terminal? ⇒ Boolean
- #road_terminal? ⇒ Boolean
- #to_s ⇒ Object
Class Method Details
.function_description(letter) ⇒ String?
Look up the human-readable description for a function letter.
45 46 47 |
# File 'lib/unlocodes/entry.rb', line 45 def self.function_description(letter) FUNCTION_DESCRIPTIONS[letter.to_s.upcase] end |
Instance Method Details
#==(other) ⇒ Object
75 76 77 |
# File 'lib/unlocodes/entry.rb', line 75 def ==(other) other.is_a?(Entry) && code == other.code end |
#airport? ⇒ Boolean
63 64 65 |
# File 'lib/unlocodes/entry.rb', line 63 def airport? function?('A') end |
#coordinates ⇒ Object
53 54 55 56 57 |
# File 'lib/unlocodes/entry.rb', line 53 def coordinates return Coordinates.new(latitude: nil, longitude: nil) if latitude.nil? && longitude.nil? Coordinates.new(latitude: latitude, longitude: longitude) end |
#eql?(other) ⇒ Boolean
83 84 85 |
# File 'lib/unlocodes/entry.rb', line 83 def eql?(other) self == other end |
#function?(letter) ⇒ Boolean
49 50 51 |
# File 'lib/unlocodes/entry.rb', line 49 def function?(letter) function_codes&.include?(letter.to_s.upcase) end |
#hash ⇒ Object
79 80 81 |
# File 'lib/unlocodes/entry.rb', line 79 def hash code&.hash || super end |
#port? ⇒ Boolean
59 60 61 |
# File 'lib/unlocodes/entry.rb', line 59 def port? function?('B') end |
#rail_terminal? ⇒ Boolean
67 68 69 |
# File 'lib/unlocodes/entry.rb', line 67 def rail_terminal? function?('R') end |
#road_terminal? ⇒ Boolean
71 72 73 |
# File 'lib/unlocodes/entry.rb', line 71 def road_terminal? function?('T') end |
#to_s ⇒ Object
87 88 89 |
# File 'lib/unlocodes/entry.rb', line 87 def to_s "#{code} #{name}".strip end |