Class: Iev::Section

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

Instance Method Summary collapse

Constructor Details

#initialize(code:, title:, area_code:) ⇒ Section

Returns a new instance of Section.

Parameters:

  • code (#to_s)

    section code, e.g. “103-01”

  • title (#to_s)

    section title, e.g. “General concepts on functions”

  • area_code (#to_s)

    parent area code, e.g. “103”



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_codeObject (readonly)

Returns the value of attribute area_code.



8
9
10
# File 'lib/iev/section.rb', line 8

def area_code
  @area_code
end

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/iev/section.rb', line 8

def code
  @code
end

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

#hashObject



33
34
35
# File 'lib/iev/section.rb', line 33

def hash
  code.hash
end

#to_hObject



24
25
26
# File 'lib/iev/section.rb', line 24

def to_h
  { "code" => code, "title" => title }
end

#uriObject



20
21
22
# File 'lib/iev/section.rb', line 20

def uri
  "section-#{code}"
end