Class: Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrients

Inherits:
Array
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prediction, page_id) ⇒ NutritionFactsLabelV1Nutrients

Returns a new instance of NutritionFactsLabelV1Nutrients.

Parameters:

  • prediction (Array)
  • page_id (Integer, nil)
[View source]

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

#entriesArray<NutritionFactsLabelV1Nutrient> (readonly)

Entries.

Returns:


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.

Parameters:

  • char (String)

    Character to use as a separator.

Returns:

  • (String)
[View source]

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_sString

Returns:

  • (String)
[View source]

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