Class: Cooklang::Section
- Inherits:
-
Object
- Object
- Cooklang::Section
- Defined in:
- lib/cooklang/section.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #hash ⇒ Object
-
#initialize(name:, steps: []) ⇒ Section
constructor
A new instance of Section.
- #to_h ⇒ Object
- #to_s ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/cooklang/section.rb', line 5 def name @name end |
#steps ⇒ Object (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 |
#hash ⇒ Object
29 30 31 |
# File 'lib/cooklang/section.rb', line 29 def hash [name, steps].hash end |
#to_h ⇒ Object
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_s ⇒ Object
12 13 14 |
# File 'lib/cooklang/section.rb', line 12 def to_s name || "Section" end |