parsley/app/models/ingredient_unit.rb

17 lines
417 B
Ruby
Raw Normal View History

2016-10-14 12:19:00 -05:00
class IngredientUnit < ApplicationRecord
2016-07-05 16:31:36 -05:00
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