Class: Cooklang::Recipe
- Inherits:
-
Object
- Object
- Cooklang::Recipe
- Defined in:
- lib/cooklang/recipe.rb
Instance Attribute Summary collapse
-
#cookware ⇒ Object
readonly
Returns the value of attribute cookware.
-
#ingredients ⇒ Object
readonly
Returns the value of attribute ingredients.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#timers ⇒ Object
readonly
Returns the value of attribute timers.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #ingredients_hash ⇒ Object
-
#initialize(**components) ⇒ Recipe
constructor
A new instance of Recipe.
- #steps_text ⇒ Object
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(**components) ⇒ Recipe
Returns a new instance of Recipe.
7 8 9 10 11 12 13 14 15 |
# File 'lib/cooklang/recipe.rb', line 7 def initialize(**components) @ingredients = freeze_component(components[:ingredients]) @cookware = freeze_component(components[:cookware]) @timers = freeze_component(components[:timers]) @steps = freeze_component(components[:steps]) @metadata = components[:metadata] || Metadata.new @sections = freeze_component(components[:sections]) @notes = freeze_component(components[:notes]) end |
Instance Attribute Details
#cookware ⇒ Object (readonly)
Returns the value of attribute cookware.
5 6 7 |
# File 'lib/cooklang/recipe.rb', line 5 def cookware @cookware end |
#ingredients ⇒ Object (readonly)
Returns the value of attribute ingredients.
5 6 7 |
# File 'lib/cooklang/recipe.rb', line 5 def ingredients @ingredients end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/cooklang/recipe.rb', line 5 def @metadata end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
5 6 7 |
# File 'lib/cooklang/recipe.rb', line 5 def notes @notes end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
5 6 7 |
# File 'lib/cooklang/recipe.rb', line 5 def sections @sections end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
5 6 7 |
# File 'lib/cooklang/recipe.rb', line 5 def steps @steps end |
#timers ⇒ Object (readonly)
Returns the value of attribute timers.
5 6 7 |
# File 'lib/cooklang/recipe.rb', line 5 def timers @timers end |
Instance Method Details
#==(other) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/cooklang/recipe.rb', line 46 def ==(other) return false unless other.is_a?(Recipe) comparable_attributes.all? do |attr| send(attr) == other.send(attr) end end |
#eql?(other) ⇒ Boolean
61 62 63 |
# File 'lib/cooklang/recipe.rb', line 61 def eql?(other) self == other end |
#hash ⇒ Object
65 66 67 |
# File 'lib/cooklang/recipe.rb', line 65 def hash [ingredients, cookware, timers, steps, ].hash end |
#ingredients_hash ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/cooklang/recipe.rb', line 25 def ingredients_hash @ingredients.each_with_object({}) do |ingredient, hash| hash[ingredient.name] = { quantity: ingredient.quantity, unit: ingredient.unit }.compact end end |
#steps_text ⇒ Object
34 35 36 |
# File 'lib/cooklang/recipe.rb', line 34 def steps_text @steps.map(&:to_text) end |
#to_h ⇒ Object
38 39 40 |
# File 'lib/cooklang/recipe.rb', line 38 def to_h Formatters::Hash.new(self).generate end |
#to_json(*args) ⇒ Object
42 43 44 |
# File 'lib/cooklang/recipe.rb', line 42 def to_json(*args) Formatters::Json.new(self).generate(*args) end |