Class: Iev::Section
- Inherits:
-
Object
- Object
- Iev::Section
- Defined in:
- lib/iev/section.rb
Overview
Immutable value object representing an IEV section (e.g. “103-01”).
A section belongs to exactly one area, identified by area_code.
Instance Attribute Summary collapse
-
#area_code ⇒ Object
readonly
Returns the value of attribute area_code.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(code:, title:, area_code:) ⇒ Section
constructor
A new instance of Section.
- #to_h ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(code:, title:, area_code:) ⇒ Section
Returns a new instance of Section.
13 14 15 16 17 18 |
# File 'lib/iev/section.rb', line 13 def initialize(code:, title:, area_code:) @code = code.to_s @title = title.to_s @area_code = area_code.to_s freeze end |
Instance Attribute Details
#area_code ⇒ Object (readonly)
Returns the value of attribute area_code.
8 9 10 |
# File 'lib/iev/section.rb', line 8 def area_code @area_code end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
8 9 10 |
# File 'lib/iev/section.rb', line 8 def code @code end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
8 9 10 |
# File 'lib/iev/section.rb', line 8 def title @title end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
28 29 30 |
# File 'lib/iev/section.rb', line 28 def ==(other) other.is_a?(self.class) && code == other.code end |
#hash ⇒ Object
33 34 35 |
# File 'lib/iev/section.rb', line 33 def hash code.hash end |
#to_h ⇒ Object
24 25 26 |
# File 'lib/iev/section.rb', line 24 def to_h { "code" => code, "title" => title } end |
#uri ⇒ Object
20 21 22 |
# File 'lib/iev/section.rb', line 20 def uri "section-#{code}" end |