Module: Brewscribe::Conversion
- Included in:
- Carbonation, Equipment, Grain, Hops, Mash, Mash::Step, Recipe, Style, Yeast
- Defined in:
- lib/brewscribe/conversion.rb
Constant Summary collapse
- BOOLEAN_CONV =
->(k) { k == '1' }
- FLOAT_CONV =
->(k) { k.to_f }
- PERCENT_CONV =
->(k) { k.to_f * 0.001 }
- INT_CONV =
->(k) { k.to_i }
- DATE_CONV =
->(k) { Date.parse k }
Instance Method Summary collapse
Instance Method Details
#data_to_properties(data) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/brewscribe/conversion.rb', line 11 def data_to_properties data data.each_key do |key| if self.class.const_get(:KEY_CONVERSION).has_key? key value = self.class.const_get(:KEY_CONVERSION)[key].call(data[key]) else value = data[key] end self.instance_variable_set "@#{key}".to_sym, value end end |