Class: Cooklang::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/cooklang/section.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, steps: []) ⇒ Section

Returns a new instance of Section.



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

def initialize(name:, steps: [])
  @name = name&.to_s&.freeze
  @steps = steps.freeze
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/cooklang/section.rb', line 5

def name
  @name
end

#stepsObject (readonly)

Returns the value of attribute steps.



5
6
7
# File 'lib/cooklang/section.rb', line 5

def steps
  @steps
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
26
27
# File 'lib/cooklang/section.rb', line 23

def ==(other)
  other.is_a?(Section) &&
    name == other.name &&
    steps == other.steps
end

#hashObject



29
30
31
# File 'lib/cooklang/section.rb', line 29

def hash
  [name, steps].hash
end

#to_hObject



16
17
18
19
20
21
# File 'lib/cooklang/section.rb', line 16

def to_h
  {
    name: name,
    steps: steps.map(&:to_h)
  }.compact
end

#to_sObject



12
13
14
# File 'lib/cooklang/section.rb', line 12

def to_s
  name || "Section"
end