对于我的 Rails 项目,我正在寻找一个可以转换质量、体积和其他单位的库。
我需要将千克转换为克,将升转换为汤匙等。
我想,它应该是这样的:
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
)
这样的宝石真的存在吗?
谢谢。