Class: Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrients
- Inherits:
-
Array
- Object
- Array
- Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrients
- Defined in:
- lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rb
Overview
The amount of nutrients in the product.
Instance Attribute Summary collapse
-
#entries ⇒ Array<NutritionFactsLabelV1Nutrient>
readonly
Entries.
Class Method Summary collapse
-
.line_items_separator(char) ⇒ String
Creates a line of rST table-compliant string separators.
Instance Method Summary collapse
-
#initialize(prediction, page_id) ⇒ NutritionFactsLabelV1Nutrients
constructor
A new instance of NutritionFactsLabelV1Nutrients.
- #to_s ⇒ String
Constructor Details
#initialize(prediction, page_id) ⇒ NutritionFactsLabelV1Nutrients
Returns a new instance of NutritionFactsLabelV1Nutrients.
28 29 30 31 32 33 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rb', line 28 def initialize(prediction, page_id) entries = prediction.map do |entry| NutritionFactsLabel::NutritionFactsLabelV1Nutrient.new(entry, page_id) end super(entries) end |
Instance Attribute Details
#entries ⇒ Array<NutritionFactsLabelV1Nutrient> (readonly)
Entries.
24 25 26 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rb', line 24 def entries @entries end |
Class Method Details
.line_items_separator(char) ⇒ String
Creates a line of rST table-compliant string separators.
38 39 40 41 42 43 44 45 46 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rb', line 38 def self.line_items_separator(char) out_str = String.new out_str << "+#{char * 13}" out_str << "+#{char * 22}" out_str << "+#{char * 10}" out_str << "+#{char * 13}" out_str << "+#{char * 6}" out_str end |
Instance Method Details
#to_s ⇒ String
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rb', line 49 def to_s return '' if empty? lines = map do |entry| "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" end.join out_str = String.new out_str << ("\n#{self.class.line_items_separator('-')}\n ") out_str << ' | Daily Value' out_str << ' | Name ' out_str << ' | Per 100g' out_str << ' | Per Serving' out_str << ' | Unit' out_str << (" |\n#{self.class.line_items_separator('=')}") out_str + lines end |