parsley/app/models/ingredient.rb

38 lines
584 B
Ruby
Raw Normal View History

2018-09-12 17:17:15 -05:00
class Ingredient < ApplicationRecord
self.abstract_class = true
class << self
def find_by_ingredient_id(ingredient_id)
case ingredient_id
when /^R(\d+)$/
Recipe.find($1)
when /^F(\d+)$/
Food.find($1)
else
raise ActiveRecord::RecordNotFound
end
end
end
def ingredient_id
case self
when Recipe
"R#{id}"
when Food
"F#{id}"
else
raise 'Unknown ingredient'
end
end
def nutrition_errors
[]
end
def density?
!self.density.nil?
end
end