加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 测量单位转换宝石

发布时间:2020-12-17 03:20:16 所属栏目:百科 来源:网络整理
导读:对于我的Rails项目,我正在寻找一个可以转换质量,体积和其他单位的库. 我需要将kilogramms转换为gramms,升转换成汤匙等. 我想,它应该是这样的: class Product ActiveRecord:Base acts_as_physical_unit,:volume,:mass,:countendclass Ingredient ActiveRecor
对于我的Rails项目,我正在寻找一个可以转换质量,体积和其他单位的库.

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

我想,它应该是这样的:

class Product < ActiveRecord:Base
  acts_as_physical_unit,:volume,:mass,:count
end

class Ingredient < ActiveRecord:Base
  acts_as_physical_unit,: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
)

这样的宝石是否存在?

谢谢.

解决方法

您可能想尝试 ruby-units:

您可以查看unit definitions以查看这个是否适合您!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读