Class: Iev::SubjectArea
- Inherits:
-
Object
- Object
- Iev::SubjectArea
- Defined in:
- lib/iev/subject_area.rb
Overview
Immutable value object representing an IEV subject area (e.g. “102”).
A subject area is the aggregate root for its sections. Navigation: area → sections (direct), section → area (via registry).
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(code:, title:, sections: []) ⇒ SubjectArea
constructor
A new instance of SubjectArea.
- #section(section_code) ⇒ Object
- #to_h ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(code:, title:, sections: []) ⇒ SubjectArea
Returns a new instance of SubjectArea.
14 15 16 17 18 19 |
# File 'lib/iev/subject_area.rb', line 14 def initialize(code:, title:, sections: []) @code = code.to_s @title = title.to_s @sections = sections freeze end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
9 10 11 |
# File 'lib/iev/subject_area.rb', line 9 def code @code end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
9 10 11 |
# File 'lib/iev/subject_area.rb', line 9 def sections @sections end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/iev/subject_area.rb', line 9 def title @title end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
37 38 39 |
# File 'lib/iev/subject_area.rb', line 37 def ==(other) other.is_a?(self.class) && code == other.code end |
#hash ⇒ Object
42 43 44 |
# File 'lib/iev/subject_area.rb', line 42 def hash code.hash end |
#section(section_code) ⇒ Object
25 26 27 |
# File 'lib/iev/subject_area.rb', line 25 def section(section_code) sections.find { |s| s.code == section_code.to_s } end |
#to_h ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/iev/subject_area.rb', line 29 def to_h { "code" => code, "title" => title, "sections" => sections.map(&:to_h), } end |
#uri ⇒ Object
21 22 23 |
# File 'lib/iev/subject_area.rb', line 21 def uri "area-#{code}" end |