Class: FoodInfo::Adapters::FatSecret::Data::FoodServing

Inherits:
Hashie::Trash
  • Object
show all
Defined in:
lib/food_info/adapters/fat_secret/data/food_serving.rb

Constant Summary collapse

DECIMALS =
%w(calories carbohydrate protein fat saturated_fat polyunsaturated_fat monounsaturated_fat trans_fat cholesterol sodium potassium fiber sugar)
INTEGERS =
%w(vitamin_a vitamin_c calcium iron)

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ FoodServing

Returns a new instance of FoodServing.



22
23
24
25
# File 'lib/food_info/adapters/fat_secret/data/food_serving.rb', line 22

def initialize(*args)
  super(*args)
  normalize_data
end

Instance Method Details

#normalize_dataObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/food_info/adapters/fat_secret/data/food_serving.rb', line 27

def normalize_data
  self[:metric_serving_amount] = self[:metric_serving_amount].to_f
  self[:number_of_units] = self[:number_of_units].to_f
  
  INTEGERS.each do |n|
    self[n.to_sym] = self[n.to_sym].to_i
  end

  DECIMALS.each do |n|
    self[n.to_sym] = self[n.to_sym].to_f
  end
end