Class: FoodNutritionix::Food

Inherits:
Object
  • Object
show all
Defined in:
lib/foodnutritionix/food.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Food

Returns a new instance of Food.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/foodnutritionix/food.rb', line 6

def initialize(data)
  @food_name = data['food_name']
  @consumed_at = DateTime.parse(data['consumed_at'])
  @serving_qty = data['serving_qty']
  @serving_unit = data['serving_unit']
  @serving_weight_grams = data['serving_weight_grams']
  @nf_calories = data['nf_calories']
  @nf_total_fat = data['nf_total_fat']
  @nf_saturated_fat = data['nf_saturated_fat']
  @nf_cholesterol = data['nf_cholesterol']
  @nf_sodium = data['nf_sodium']
  @nf_total_carbohydrate = data['nf_total_carbohydrate']
  @nf_dietary_fiber = data['nf_dietary_fiber']
  @nf_sugars = data['nf_sugars']
  @nf_protein = data['nf_protein']
  @nf_potassium = data['nf_potassium']
  @photo = data['photo']
end

Instance Attribute Details

#consumed_atObject (readonly)

Returns the value of attribute consumed_at.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def consumed_at
  @consumed_at
end

#food_nameObject (readonly)

Returns the value of attribute food_name.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def food_name
  @food_name
end

#nf_caloriesObject (readonly)

Returns the value of attribute nf_calories.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def nf_calories
  @nf_calories
end

#nf_cholesterolObject (readonly)

Returns the value of attribute nf_cholesterol.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def nf_cholesterol
  @nf_cholesterol
end

#nf_dietary_fiberObject (readonly)

Returns the value of attribute nf_dietary_fiber.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def nf_dietary_fiber
  @nf_dietary_fiber
end

#nf_potassiumObject (readonly)

Returns the value of attribute nf_potassium.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def nf_potassium
  @nf_potassium
end

#nf_proteinObject (readonly)

Returns the value of attribute nf_protein.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def nf_protein
  @nf_protein
end

#nf_saturated_fatObject (readonly)

Returns the value of attribute nf_saturated_fat.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def nf_saturated_fat
  @nf_saturated_fat
end

#nf_sodiumObject (readonly)

Returns the value of attribute nf_sodium.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def nf_sodium
  @nf_sodium
end

#nf_sugarsObject (readonly)

Returns the value of attribute nf_sugars.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def nf_sugars
  @nf_sugars
end

#nf_total_carbohydrateObject (readonly)

Returns the value of attribute nf_total_carbohydrate.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def nf_total_carbohydrate
  @nf_total_carbohydrate
end

#nf_total_fatObject (readonly)

Returns the value of attribute nf_total_fat.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def nf_total_fat
  @nf_total_fat
end

#photoObject (readonly)

Returns the value of attribute photo.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def photo
  @photo
end

#serving_qtyObject (readonly)

Returns the value of attribute serving_qty.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def serving_qty
  @serving_qty
end

#serving_unitObject (readonly)

Returns the value of attribute serving_unit.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def serving_unit
  @serving_unit
end

#serving_weight_gramsObject (readonly)

Returns the value of attribute serving_weight_grams.



4
5
6
# File 'lib/foodnutritionix/food.rb', line 4

def serving_weight_grams
  @serving_weight_grams
end

Class Method Details

.search(*tags) ⇒ Object



25
26
27
28
# File 'lib/foodnutritionix/food.rb', line 25

def self.search(*tags)
  data = FoodNutrixClient.search_foods(tags)
  new(data)
end