for my Rails project, I'm looking for a library, that can convert mass, volume and other units.
I need to convert kilogramms to gramms, liters to tablespoons etc.
I think, it should look like this:
class Product < ActiveRecord:Base
acts_as_physical_unit, :volume, :mass, :count
end
class Ingredient < ActiveRecord:Base
acts_as_physical_unit, :volume, :mass, :count
end
olive_oil = Product.new(:name => "Olive Oil", :volume => "1000 ml")
caesar_salad = Recipe.new(:name => "Caesar salad",
:ingredients => [
Ingredient.new(:product => [olive_oil], :volume => "5 tablespoons")
]
# In ingredients of "Caesar Salad" are 5 tablespoons of "Olive Oil" specified.
# We should create "Caesar Salad" for 50 persons.
# How mutch bottles of "Olive Oil" should be ordered ?
order = OrderItem.new(
:product => olive_oil,
:count => olive_oil.count_for(caesar_salad.ingredients.first)) * 50
)
Does such a gem even exists ?
Thanks.