Class: Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1ServingSize

Inherits:
Mindee::Parsing::Standard::FeatureField show all
Includes:
Mindee::Parsing::Standard
Defined in:
lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb

Overview

The size of a single serving of the product.

Instance Attribute Summary collapse

Attributes inherited from Mindee::Parsing::Standard::AbstractField

#bounding_box, #confidence, #page_id, #polygon

Instance Method Summary collapse

Methods inherited from Mindee::Parsing::Standard::FeatureField

#format_for_display

Methods inherited from Mindee::Parsing::Standard::AbstractField

array_confidence, array_sum, float_to_string

Constructor Details

#initialize(prediction, page_id) ⇒ NutritionFactsLabelV1ServingSize

Returns a new instance of NutritionFactsLabelV1ServingSize.

Parameters:

  • prediction (Hash)
  • page_id (Integer, nil)


20
21
22
23
24
25
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb', line 20

def initialize(prediction, page_id)
  super(prediction, page_id)
  @amount = prediction['amount']
  @unit = prediction['unit']
  @page_id = page_id
end

Instance Attribute Details

#amountFloat (readonly)

The amount of a single serving.

Returns:

  • (Float)


13
14
15
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb', line 13

def amount
  @amount
end

#unitString (readonly)

The unit for the amount of a single serving.

Returns:

  • (String)


16
17
18
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb', line 16

def unit
  @unit
end

Instance Method Details

#printable_valuesHash

Returns:

  • (Hash)


28
29
30
31
32
33
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb', line 28

def printable_values
  printable = {}
  printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount)
  printable[:unit] = format_for_display(@unit)
  printable
end

#to_sString

Returns:

  • (String)


36
37
38
39
40
41
42
# File 'lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb', line 36

def to_s
  printable = printable_values
  out_str = String.new
  out_str << "\n  :Amount: #{printable[:amount]}"
  out_str << "\n  :Unit: #{printable[:unit]}"
  out_str
end