Class: Recipe
- Inherits:
-
Object
- Object
- Recipe
- Defined in:
- lib/practica8/recipe.rb
Instance Attribute Summary collapse
-
#ingredients ⇒ Object
Returns the value of attribute ingredients.
-
#instructions ⇒ Object
Returns the value of attribute instructions.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #ingredient(name, options = {}) ⇒ Object
-
#initialize(name, &block) ⇒ Recipe
constructor
A new instance of Recipe.
- #step(text, options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Recipe
Returns a new instance of Recipe.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/practica8/recipe.rb', line 4 def initialize(name, &block) self.name = name self.ingredients = [] self.instructions = [] if block_given? if block.arity == 1 yield self else instance_eval &block end end end |
Instance Attribute Details
#ingredients ⇒ Object
Returns the value of attribute ingredients.
2 3 4 |
# File 'lib/practica8/recipe.rb', line 2 def ingredients @ingredients end |
#instructions ⇒ Object
Returns the value of attribute instructions.
2 3 4 |
# File 'lib/practica8/recipe.rb', line 2 def instructions @instructions end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/practica8/recipe.rb', line 2 def name @name end |
Instance Method Details
#ingredient(name, options = {}) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/practica8/recipe.rb', line 30 def ingredient(name, = {}) ingredient = name ingredient << " (#{[:amount]})" if [:amount] ingredients << ingredient end |
#step(text, options = {}) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/practica8/recipe.rb', line 37 def step(text, = {}) instruction = text instruction << " (#{[:during]})" if [:during] instructions << instruction end |
#to_s ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/practica8/recipe.rb', line 18 def to_s output = name output << "\n#{'=' * name.size}\n\n" output << "Ingredients: #{ingredients.join(', ')}\n\n" instructions.each_with_index do |instruction, index| output << "#{index + 1}) #{instruction}\n" end output end |