class Ingredient

Attributes

item[RW]
qty[RW]
unit[RW]

Public Class Methods

new(params) click to toggle source
# 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

Public Instance Methods

==(other_ingredient) click to toggle source

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
is_free_text?() click to toggle source

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
quantity() click to toggle source

alias for qty

# File lib/tablecloth/ingredient.rb, line 13
def quantity
  @qty
end
to_s() click to toggle source

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
units() click to toggle source

alias for unit

# File lib/tablecloth/ingredient.rb, line 18
def units
  @unit
end