Class: Unlocodes::Entry

Inherits:
Lutaml::Model::Serializable
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.function_description(letter) ⇒ String?

Look up the human-readable description for a function letter.

Parameters:

  • letter (String)

    single-letter function code (case-insensitive)

Returns:

  • (String, nil)

    description, or nil if the letter is unknown



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

Returns:

  • (Boolean)


63
64
65
# File 'lib/unlocodes/entry.rb', line 63

def airport?
  function?('A')
end

#coordinatesObject



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

Returns:

  • (Boolean)


83
84
85
# File 'lib/unlocodes/entry.rb', line 83

def eql?(other)
  self == other
end

#function?(letter) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/unlocodes/entry.rb', line 49

def function?(letter)
  function_codes&.include?(letter.to_s.upcase)
end

#hashObject



79
80
81
# File 'lib/unlocodes/entry.rb', line 79

def hash
  code&.hash || super
end

#port?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/unlocodes/entry.rb', line 59

def port?
  function?('B')
end

#rail_terminal?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/unlocodes/entry.rb', line 67

def rail_terminal?
  function?('R')
end

#road_terminal?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/unlocodes/entry.rb', line 71

def road_terminal?
  function?('T')
end

#to_sObject



87
88
89
# File 'lib/unlocodes/entry.rb', line 87

def to_s
  "#{code} #{name}".strip
end