class Mg2en::Ingredient
This class holds an ingredient.
Attributes
description[R]
direction[R]
group[R]
group?[R]
ingredients[R]
link[R]
link?[R]
measurement[R]
quantity[R]
Public Class Methods
new(i)
click to toggle source
# 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
Public Instance Methods
to_s()
click to toggle source
# 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()
click to toggle source
# 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