# File lib/tablecloth/ingredient.rb, line 4 def initialize(params) @qty = params[:qty] @unit = params[:unit] @item = params[:item] @qty = 1 if @qty == :na && @unit != :na end
simple comparison operator
# File lib/tablecloth/ingredient.rb, line 23 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 30 def is_free_text? @qty == :na && @unit == :na end
alias for qty
# File lib/tablecloth/ingredient.rb, line 13 def quantity @qty end
This method formats an ingredient into a readable string
# File lib/tablecloth/ingredient.rb, line 35 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 18 def units @unit end