41 lines
670 B
Ruby
41 lines
670 B
Ruby
class Ingredient < ApplicationRecord
|
|
self.abstract_class = true
|
|
|
|
class << self
|
|
|
|
def find_by_ingredient_id(ingredient_id)
|
|
puts "looking up |#{ingredient_id}|"
|
|
case ingredient_id
|
|
when /^R(\d+)$/
|
|
puts 'rec'
|
|
Recipe.find($1)
|
|
when /^F(\d+)$/
|
|
puts 'food'
|
|
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 |