# File lib/tablecloth/ingredient.rb, line 6 def initialize(params) @qty = params[:qty] @unit = params[:unit] @item = params[:item] @qty = 1 if @qty == :na && @unit != :na end
parse a single line from the ingredients list
# File lib/tablecloth/ingredient.rb, line 47 def self.parse str, units_hash str = presub str qty = get_qty str units = get_units str, units_hash item = get_item str, units != :na Ingredient.new :qty => qty, :unit => units, :item => item end
simple comparison operator
# File lib/tablecloth/ingredient.rb, line 25 def ==(other_ingredient) @qty == other_ingredient.qty && @unit == other_ingredient.unit && @item == other_ingredient.item end
returns true if this ingredient did not specify a qty or a unit
# File lib/tablecloth/ingredient.rb, line 32 def is_free_text? @qty == :na && @unit == :na end
alias for qty
# File lib/tablecloth/ingredient.rb, line 15 def quantity @qty end
This method formats an ingredient into a readable string
# File lib/tablecloth/ingredient.rb, line 37 def to_s #singular return "#{@qty} #{@unit} of #{item}" if @qty == "1" #basic pluralization "#{@qty} #{@unit}s of #{item}" end
alias for unit
# File lib/tablecloth/ingredient.rb, line 20 def units @unit end