class IngredientUnit < ActiveRecord::Base
  belongs_to :ingredient, inverse_of: :ingredient_units

  validates :name, presence: true
  validates :gram_weight, presence: true

  def matches?(unit)
    case
      when unit.empty? && ['each', 'ech', 'item', 'per'].include?(self.name.downcase)
        true
      when unit.downcase.singularize == self.name.downcase
        true
      else
        false
    end
  end
end