Class: Mg2en::Ingredient
- Inherits:
-
Object
- Object
- Mg2en::Ingredient
- Defined in:
- lib/mg2en/ingredient.rb
Overview
This class holds an ingredient.
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#group ⇒ Object
(also: #group?)
readonly
Returns the value of attribute group.
-
#ingredients ⇒ Object
readonly
Returns the value of attribute ingredients.
-
#link ⇒ Object
(also: #link?)
readonly
Returns the value of attribute link.
-
#measurement ⇒ Object
readonly
Returns the value of attribute measurement.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
Instance Method Summary collapse
-
#initialize(i) ⇒ Ingredient
constructor
A new instance of Ingredient.
- #to_s ⇒ Object
- #without_quantity ⇒ Object
Constructor Details
#initialize(i) ⇒ Ingredient
Returns a new instance of Ingredient.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mg2en/ingredient.rb', line 9 def initialize(i) if i.key?('DESCRIPTION') @group = false @quantity = i['QUANTITY'] @measurement = i['MEASUREMENT'] @description = i['DESCRIPTION'] @direction = i['DIRECTION'] @link = i['INCLUDED_RECIPE_ID'] > 0 elsif i.key?('DIVIDER_INGREDIENT') @group = true @description = i['DIVIDER_INGREDIENT']['DESCRIPTION'] @ingredients = [] ingts = i['INGREDIENTS'] ingts.each do |ing| ingredient = Mg2en::Ingredient.new(ing) @ingredients.push ingredient end else fail 'Did not recognize input' end end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/mg2en/ingredient.rb', line 4 def description @description end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
4 5 6 |
# File 'lib/mg2en/ingredient.rb', line 4 def direction @direction end |
#group ⇒ Object (readonly) Also known as: group?
Returns the value of attribute group.
4 5 6 |
# File 'lib/mg2en/ingredient.rb', line 4 def group @group end |
#ingredients ⇒ Object (readonly)
Returns the value of attribute ingredients.
4 5 6 |
# File 'lib/mg2en/ingredient.rb', line 4 def ingredients @ingredients end |
#link ⇒ Object (readonly) Also known as: link?
Returns the value of attribute link.
4 5 6 |
# File 'lib/mg2en/ingredient.rb', line 4 def link @link end |
#measurement ⇒ Object (readonly)
Returns the value of attribute measurement.
4 5 6 |
# File 'lib/mg2en/ingredient.rb', line 4 def measurement @measurement end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
4 5 6 |
# File 'lib/mg2en/ingredient.rb', line 4 def quantity @quantity end |
Instance Method Details
#to_s ⇒ Object
31 32 33 34 35 36 |
# File 'lib/mg2en/ingredient.rb', line 31 def to_s return @description if self.group? output = '' output << @quantity unless @quantity.empty? output << without_quantity end |
#without_quantity ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/mg2en/ingredient.rb', line 38 def without_quantity output = '' output << ' ' << @measurement unless @measurement.empty? output << ' ' << @description output << ', ' << @direction unless @direction.empty? output end |