Class: Iev::IevCode
Overview
Immutable value object that decomposes an IEV concept code into its structural parts: area code, section code, and number.
The IEV code format is AAA-BB-CC where:
AAA = area code (e.g. "103")
BB = section sub-code (e.g. "01")
CC = concept number (e.g. "02")
Instance Attribute Summary collapse
-
#area_code ⇒ Object
readonly
Returns the value of attribute area_code.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#section_code ⇒ Object
readonly
Returns the value of attribute section_code.
Class Method Summary collapse
-
.parse(code) ⇒ IevCode?
Safe constructor that returns nil for codes that don’t parse.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #area_uri ⇒ Object
- #hash ⇒ Object
-
#initialize(code) ⇒ IevCode
constructor
A new instance of IevCode.
- #section_uri ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(code) ⇒ IevCode
Returns a new instance of IevCode.
33 34 35 36 37 38 39 40 |
# File 'lib/iev/iev_code.rb', line 33 def initialize(code) @raw = code.to_s parts = @raw.split("-") @area_code = parts[0] @section_code = parts.length >= 2 ? "#{parts[0]}-#{parts[1]}" : nil @number = parts.length >= 3 ? parts[2] : nil freeze end |
Instance Attribute Details
#area_code ⇒ Object (readonly)
Returns the value of attribute area_code.
30 31 32 |
# File 'lib/iev/iev_code.rb', line 30 def area_code @area_code end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
30 31 32 |
# File 'lib/iev/iev_code.rb', line 30 def number @number end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
30 31 32 |
# File 'lib/iev/iev_code.rb', line 30 def raw @raw end |
#section_code ⇒ Object (readonly)
Returns the value of attribute section_code.
30 31 32 |
# File 'lib/iev/iev_code.rb', line 30 def section_code @section_code end |
Class Method Details
.parse(code) ⇒ IevCode?
Safe constructor that returns nil for codes that don’t parse.
74 75 76 77 78 |
# File 'lib/iev/iev_code.rb', line 74 def self.parse(code) new(code) rescue ArgumentError nil end |
Instance Method Details
#<=>(other) ⇒ Object
67 68 69 |
# File 'lib/iev/iev_code.rb', line 67 def <=>(other) to_s <=> other.to_s end |
#==(other) ⇒ Object Also known as: eql?
58 59 60 |
# File 'lib/iev/iev_code.rb', line 58 def ==(other) other.is_a?(self.class) && raw == other.raw end |
#area_uri ⇒ Object
42 43 44 |
# File 'lib/iev/iev_code.rb', line 42 def area_uri "area-#{area_code}" end |
#hash ⇒ Object
63 64 65 |
# File 'lib/iev/iev_code.rb', line 63 def hash raw.hash end |
#section_uri ⇒ Object
46 47 48 |
# File 'lib/iev/iev_code.rb', line 46 def section_uri "section-#{section_code}" if section_code end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/iev/iev_code.rb', line 50 def to_s @raw end |
#to_str ⇒ Object
54 55 56 |
# File 'lib/iev/iev_code.rb', line 54 def to_str @raw end |