Class: Vehicles::Plates::Jurisdiction
- Inherits:
-
Object
- Object
- Vehicles::Plates::Jurisdiction
- 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
-
#authority_name ⇒ Object
readonly
Returns the value of attribute authority_name.
-
#authority_url ⇒ Object
readonly
Returns the value of attribute authority_url.
-
#binding ⇒ Object
readonly
Returns the value of attribute binding.
-
#charset ⇒ Object
readonly
Returns the value of attribute charset.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#series ⇒ Object
readonly
Returns the value of attribute series.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code:, raw:) ⇒ Jurisdiction
constructor
A new instance of Jurisdiction.
- #inspect ⇒ Object
- #to_s ⇒ Object
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_name ⇒ Object (readonly)
Returns the value of attribute authority_name.
10 11 12 |
# File 'lib/vehicles/plates/jurisdiction.rb', line 10 def @authority_name end |
#authority_url ⇒ Object (readonly)
Returns the value of attribute authority_url.
10 11 12 |
# File 'lib/vehicles/plates/jurisdiction.rb', line 10 def @authority_url end |
#binding ⇒ Object (readonly)
Returns the value of attribute binding.
10 11 12 |
# File 'lib/vehicles/plates/jurisdiction.rb', line 10 def binding @binding end |
#charset ⇒ Object (readonly)
Returns the value of attribute charset.
10 11 12 |
# File 'lib/vehicles/plates/jurisdiction.rb', line 10 def charset @charset end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
10 11 12 |
# File 'lib/vehicles/plates/jurisdiction.rb', line 10 def code @code end |
#series ⇒ Object (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
#inspect ⇒ Object
29 |
# File 'lib/vehicles/plates/jurisdiction.rb', line 29 def inspect = %(#<Vehicles::Plates::Jurisdiction #{code} (#{series.size} series)>) |
#to_s ⇒ Object
28 |
# File 'lib/vehicles/plates/jurisdiction.rb', line 28 def to_s = code |