Class: Iev::SubjectArea

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(code:, title:, sections: []) ⇒ SubjectArea

Returns a new instance of SubjectArea.

Parameters:

  • code (#to_s)

    area code, e.g. “103”

  • title (#to_s)

    area title, e.g. “Mathematics - Functions”

  • sections (Array<Iev::Section>) (defaults to: [])

    child sections



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

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/iev/subject_area.rb', line 9

def code
  @code
end

#sectionsObject (readonly)

Returns the value of attribute sections.



9
10
11
# File 'lib/iev/subject_area.rb', line 9

def sections
  @sections
end

#titleObject (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

#hashObject



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_hObject



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

#uriObject



21
22
23
# File 'lib/iev/subject_area.rb', line 21

def uri
  "area-#{code}"
end