I am using the gem Alchemist to make unit conversions. Given this working in my model:
class Item < ApplicationRecord
def converted
quantity = 1
quantity.kg.to.g
end
end
How do I make kg and g dynamic? Like:
quantity.unit_purchase.to.unit_inventory
unit_purchase and unit_inventory are attributes (strings) of the class, corresponding to values such as kg, g and so on.
So perhaps something like:
x = self.unit_purchase
y = self.unit_inventory
quantity.x.to.y
But I'm having hard time to find the syntax.