Class: Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Document
- Inherits:
-
Mindee::Parsing::Common::Prediction
- Object
- Mindee::Parsing::Common::Prediction
- Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Document
- Includes:
- Mindee::Parsing::Standard
- Defined in:
- lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb
Overview
Nutrition Facts Label API version 1.0 document data.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#added_sugars ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1AddedSugar
readonly
The amount of added sugars in the product.
-
#calories ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Calorie
readonly
The amount of calories in the product.
-
#cholesterol ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Cholesterol
readonly
The amount of cholesterol in the product.
-
#dietary_fiber ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1DietaryFiber
readonly
The amount of dietary fiber in the product.
-
#nutrients ⇒ Array<Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrient>
readonly
The amount of nutrients in the product.
-
#protein ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Protein
readonly
The amount of protein in the product.
-
#saturated_fat ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1SaturatedFat
readonly
The amount of saturated fat in the product.
-
#serving_per_box ⇒ Mindee::Parsing::Standard::AmountField
readonly
The number of servings in each box of the product.
-
#serving_size ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1ServingSize
readonly
The size of a single serving of the product.
-
#sodium ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Sodium
readonly
The amount of sodium in the product.
-
#total_carbohydrate ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TotalCarbohydrate
readonly
The total amount of carbohydrates in the product.
-
#total_fat ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TotalFat
readonly
The total amount of fat in the product.
-
#total_sugars ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TotalSugar
readonly
The total amount of sugars in the product.
-
#trans_fat ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TransFat
readonly
The amount of trans fat in the product.
Instance Method Summary collapse
-
#initialize(prediction, page_id) ⇒ NutritionFactsLabelV1Document
constructor
A new instance of NutritionFactsLabelV1Document.
- #to_s ⇒ String
Constructor Details
#initialize(prediction, page_id) ⇒ NutritionFactsLabelV1Document
Returns a new instance of NutritionFactsLabelV1Document.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 69 def initialize(prediction, page_id) super() @added_sugars = NutritionFactsLabelV1AddedSugar.new(prediction['added_sugars'], page_id) @calories = NutritionFactsLabelV1Calorie.new(prediction['calories'], page_id) @cholesterol = NutritionFactsLabelV1Cholesterol.new(prediction['cholesterol'], page_id) @dietary_fiber = NutritionFactsLabelV1DietaryFiber.new(prediction['dietary_fiber'], page_id) @nutrients = [] prediction['nutrients'].each do |item| @nutrients.push(NutritionFactsLabelV1Nutrient.new(item, page_id)) end @protein = NutritionFactsLabelV1Protein.new(prediction['protein'], page_id) @saturated_fat = NutritionFactsLabelV1SaturatedFat.new(prediction['saturated_fat'], page_id) @serving_per_box = AmountField.new(prediction['serving_per_box'], page_id) @serving_size = NutritionFactsLabelV1ServingSize.new(prediction['serving_size'], page_id) @sodium = NutritionFactsLabelV1Sodium.new(prediction['sodium'], page_id) @total_carbohydrate = NutritionFactsLabelV1TotalCarbohydrate.new(prediction['total_carbohydrate'], page_id) @total_fat = NutritionFactsLabelV1TotalFat.new(prediction['total_fat'], page_id) @total_sugars = NutritionFactsLabelV1TotalSugar.new(prediction['total_sugars'], page_id) @trans_fat = NutritionFactsLabelV1TransFat.new(prediction['trans_fat'], page_id) end |
Instance Attribute Details
#added_sugars ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1AddedSugar (readonly)
The amount of added sugars in the product.
26 27 28 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 26 def added_sugars @added_sugars end |
#calories ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Calorie (readonly)
The amount of calories in the product.
29 30 31 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 29 def calories @calories end |
#cholesterol ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Cholesterol (readonly)
The amount of cholesterol in the product.
32 33 34 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 32 def cholesterol @cholesterol end |
#dietary_fiber ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1DietaryFiber (readonly)
The amount of dietary fiber in the product.
35 36 37 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 35 def dietary_fiber @dietary_fiber end |
#nutrients ⇒ Array<Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrient> (readonly)
The amount of nutrients in the product.
38 39 40 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 38 def nutrients @nutrients end |
#protein ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Protein (readonly)
The amount of protein in the product.
41 42 43 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 41 def protein @protein end |
#saturated_fat ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1SaturatedFat (readonly)
The amount of saturated fat in the product.
44 45 46 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 44 def saturated_fat @saturated_fat end |
#serving_per_box ⇒ Mindee::Parsing::Standard::AmountField (readonly)
The number of servings in each box of the product.
47 48 49 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 47 def serving_per_box @serving_per_box end |
#serving_size ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1ServingSize (readonly)
The size of a single serving of the product.
50 51 52 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 50 def serving_size @serving_size end |
#sodium ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Sodium (readonly)
The amount of sodium in the product.
53 54 55 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 53 def sodium @sodium end |
#total_carbohydrate ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TotalCarbohydrate (readonly)
The total amount of carbohydrates in the product.
56 57 58 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 56 def total_carbohydrate @total_carbohydrate end |
#total_fat ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TotalFat (readonly)
The total amount of fat in the product.
59 60 61 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 59 def total_fat @total_fat end |
#total_sugars ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TotalSugar (readonly)
The total amount of sugars in the product.
62 63 64 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 62 def total_sugars @total_sugars end |
#trans_fat ⇒ Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TransFat (readonly)
The amount of trans fat in the product.
65 66 67 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 65 def trans_fat @trans_fat end |
Instance Method Details
#to_s ⇒ String
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb', line 91 def to_s serving_size = @serving_size.to_s calories = @calories.to_s total_fat = @total_fat.to_s saturated_fat = @saturated_fat.to_s trans_fat = @trans_fat.to_s cholesterol = @cholesterol.to_s total_carbohydrate = @total_carbohydrate.to_s dietary_fiber = @dietary_fiber.to_s total_sugars = @total_sugars.to_s added_sugars = @added_sugars.to_s protein = @protein.to_s sodium = @sodium.to_s nutrients = nutrients_to_s out_str = String.new out_str << "\n:Serving per Box: #{@serving_per_box}".rstrip out_str << "\n:Serving Size:" out_str << serving_size out_str << "\n:Calories:" out_str << calories out_str << "\n:Total Fat:" out_str << total_fat out_str << "\n:Saturated Fat:" out_str << saturated_fat out_str << "\n:Trans Fat:" out_str << trans_fat out_str << "\n:Cholesterol:" out_str << cholesterol out_str << "\n:Total Carbohydrate:" out_str << total_carbohydrate out_str << "\n:Dietary Fiber:" out_str << dietary_fiber out_str << "\n:Total Sugars:" out_str << total_sugars out_str << "\n:Added Sugars:" out_str << added_sugars out_str << "\n:Protein:" out_str << protein out_str << "\n:sodium:" out_str << sodium out_str << "\n:nutrients:" out_str << nutrients out_str[1..].to_s end |