Class: Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrient
- Inherits:
- 
      Mindee::Parsing::Standard::FeatureField
      
        - Object
- Mindee::Parsing::Standard::AbstractField
- Mindee::Parsing::Standard::FeatureField
- Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrient
 
- Includes:
- Mindee::Parsing::Standard
- Defined in:
- lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb
Overview
The amount of nutrients in the product.
Instance Attribute Summary collapse
- 
  
    
      #daily_value  ⇒ Float 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    DVs are the recommended amounts of nutrients to consume or not to exceed each day. 
- 
  
    
      #name  ⇒ String 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The name of nutrients of the product. 
- 
  
    
      #per_100g  ⇒ Float 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The amount of nutrients per 100g of the product. 
- 
  
    
      #per_serving  ⇒ Float 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The amount of nutrients per serving of the product. 
- 
  
    
      #unit  ⇒ String 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The unit of measurement for the amount of nutrients. 
Attributes inherited from Mindee::Parsing::Standard::AbstractField
#bounding_box, #confidence, #page_id, #polygon
Instance Method Summary collapse
- 
  
    
      #initialize(prediction, page_id)  ⇒ NutritionFactsLabelV1Nutrient 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of NutritionFactsLabelV1Nutrient. 
- #printable_values ⇒ Hash
- #table_printable_values ⇒ Hash
- #to_s ⇒ String
- #to_table_line ⇒ String
Methods inherited from Mindee::Parsing::Standard::FeatureField
Methods inherited from Mindee::Parsing::Standard::AbstractField
array_confidence, array_sum, float_to_string
Constructor Details
#initialize(prediction, page_id) ⇒ NutritionFactsLabelV1Nutrient
Returns a new instance of NutritionFactsLabelV1Nutrient.
| 29 30 31 32 33 34 35 36 37 | # File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb', line 29 def initialize(prediction, page_id) super @daily_value = prediction['daily_value'] @name = prediction['name'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @unit = prediction['unit'] @page_id = page_id end | 
Instance Attribute Details
#daily_value ⇒ Float (readonly)
DVs are the recommended amounts of nutrients to consume or not to exceed each day.
| 13 14 15 | # File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb', line 13 def daily_value @daily_value end | 
#name ⇒ String (readonly)
The name of nutrients of the product.
| 16 17 18 | # File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb', line 16 def name @name end | 
#per_100g ⇒ Float (readonly)
The amount of nutrients per 100g of the product.
| 19 20 21 | # File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb', line 19 def per_100g @per_100g end | 
#per_serving ⇒ Float (readonly)
The amount of nutrients per serving of the product.
| 22 23 24 | # File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb', line 22 def per_serving @per_serving end | 
#unit ⇒ String (readonly)
The unit of measurement for the amount of nutrients.
| 25 26 27 | # File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb', line 25 def unit @unit end | 
Instance Method Details
#printable_values ⇒ Hash
| 40 41 42 43 44 45 46 47 48 49 50 51 | # File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb', line 40 def printable_values printable = {} printable[:daily_value] = @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) printable[:name] = format_for_display(@name) printable[:per_100g] = @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) printable[:per_serving] = @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable[:unit] = format_for_display(@unit) printable end | 
#table_printable_values ⇒ Hash
| 54 55 56 57 58 59 60 61 62 63 64 65 | # File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb', line 54 def table_printable_values printable = {} printable[:daily_value] = @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) printable[:name] = format_for_display(@name, 20) printable[:per_100g] = @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) printable[:per_serving] = @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable[:unit] = format_for_display(@unit, nil) printable end | 
#to_s ⇒ String
| 80 81 82 83 84 85 86 87 88 89 | # File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb', line 80 def to_s printable = printable_values out_str = String.new out_str << "\n :Daily Value: #{printable[:daily_value]}" out_str << "\n :Name: #{printable[:name]}" out_str << "\n :Per 100g: #{printable[:per_100g]}" out_str << "\n :Per Serving: #{printable[:per_serving]}" out_str << "\n :Unit: #{printable[:unit]}" out_str end | 
#to_table_line ⇒ String
| 68 69 70 71 72 73 74 75 76 77 | # File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb', line 68 def to_table_line printable = table_printable_values out_str = String.new out_str << format('| %- 12s', printable[:daily_value]) out_str << format('| %- 21s', printable[:name]) out_str << format('| %- 9s', printable[:per_100g]) out_str << format('| %- 12s', printable[:per_serving]) out_str << format('| %- 5s', printable[:unit]) out_str << '|' end |