Class: Vehicles::Plates::Jurisdiction

Inherits:
Object
  • Object
show all
Defined in:
lib/vehicles/plates/jurisdiction.rb

Overview

One issuing jurisdiction — a country, or a state where plates are state-issued ("us-fl"; a bare "us" will never exist). Wraps the raw dataset YAML: authority, binding (vehicle vs owner), the jurisdiction-wide charset law, and every series.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, raw:) ⇒ Jurisdiction

Returns a new instance of Jurisdiction.



17
18
19
20
21
22
23
24
25
26
# File 'lib/vehicles/plates/jurisdiction.rb', line 17

def initialize(code:, raw:)
  @code           = code
  @authority_name = raw.dig("authority", "name")
  @authority_url  = raw.dig("authority", "url")
  @binding        = raw["binding"]
  @charset        = (raw["charset_defaults"] || {}).freeze
  @series         = (raw["series"] || []).map { |entry| Series.new(entry) }
    .sort_by { |s| [ s.klass == "standard" ? 0 : 1, s.klass, s.period["start"] || 0 ] }.freeze
  freeze
end

Instance Attribute Details

#authority_nameObject (readonly)

Returns the value of attribute authority_name.



10
11
12
# File 'lib/vehicles/plates/jurisdiction.rb', line 10

def authority_name
  @authority_name
end

#authority_urlObject (readonly)

Returns the value of attribute authority_url.



10
11
12
# File 'lib/vehicles/plates/jurisdiction.rb', line 10

def authority_url
  @authority_url
end

#bindingObject (readonly)

Returns the value of attribute binding.



10
11
12
# File 'lib/vehicles/plates/jurisdiction.rb', line 10

def binding
  @binding
end

#charsetObject (readonly)

Returns the value of attribute charset.



10
11
12
# File 'lib/vehicles/plates/jurisdiction.rb', line 10

def charset
  @charset
end

#codeObject (readonly)

Returns the value of attribute code.



10
11
12
# File 'lib/vehicles/plates/jurisdiction.rb', line 10

def code
  @code
end

#seriesObject (readonly)

Returns the value of attribute series.



10
11
12
# File 'lib/vehicles/plates/jurisdiction.rb', line 10

def series
  @series
end

Class Method Details

.load(path) ⇒ Object



12
13
14
15
# File 'lib/vehicles/plates/jurisdiction.rb', line 12

def self.load(path)
  raw = YAML.safe_load_file(path, aliases: true)
  new(code: File.basename(path, ".yml"), raw: raw)
end

Instance Method Details

#inspectObject



29
# File 'lib/vehicles/plates/jurisdiction.rb', line 29

def inspect = %(#<Vehicles::Plates::Jurisdiction #{code} (#{series.size} series)>)

#to_sObject



28
# File 'lib/vehicles/plates/jurisdiction.rb', line 28

def to_s = code