计量单位转换宝石

Ant*_*nAL 5 gem units-of-measurement ruby-on-rails-plugins ruby-on-rails-3

对于我的Rails项目,我正在寻找一个可以转换质量,体积和其他单位的库.

我需要将kilogramms转换为gramms,升转换成汤匙等.

我想,它应该是这样的:

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
)
Run Code Online (Sandbox Code Playgroud)

这样的宝石是否存在?

谢谢.

yba*_*art 5

你可能想尝试ruby-units:

您可以检查单位定义,看看这个是否适合您!