mindee 3.12.0 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +18 -0
- data/README.md +23 -23
- data/Rakefile +5 -0
- data/docs/bank_account_details_v2.md +5 -1
- data/docs/bank_check_v1.md +6 -2
- data/docs/bank_statement_fr_v1.md +3 -0
- data/docs/barcode_reader_v1.md +5 -1
- data/docs/bill_of_lading_v1.md +202 -0
- data/docs/carte_grise_v1.md +5 -1
- data/docs/carte_vitale_v1.md +5 -1
- data/docs/code_samples/bill_of_lading_v1_async.txt +19 -0
- data/docs/code_samples/energy_bill_fra_v1_async.txt +19 -0
- data/docs/code_samples/invoices_v4_async.txt +19 -0
- data/docs/code_samples/nutrition_facts_v1_async.txt +19 -0
- data/docs/code_samples/payslip_fra_v2_async.txt +19 -0
- data/docs/cropper_v1.md +6 -2
- data/docs/custom_v1.md +5 -3
- data/docs/energy_bill_fra_v1.md +249 -0
- data/docs/eu_driver_license_v1.md +6 -2
- data/docs/expense_receipts_v5.md +26 -1
- data/docs/financial_document_v1.md +29 -1
- data/docs/generated_v1.md +3 -0
- data/docs/getting_started.md +3 -0
- data/docs/idcard_fr_v2.md +15 -2
- data/docs/international_id_v2.md +13 -1
- data/docs/invoice_splitter_v1.md +16 -13
- data/docs/invoices_v4.md +54 -21
- data/docs/license_plates_v1.md +5 -1
- data/docs/multi_receipts_detector_v1.md +5 -1
- data/docs/nutrition_facts_v1.md +295 -0
- data/docs/passport_v1.md +5 -1
- data/docs/payslip_fra_v2.md +218 -0
- data/docs/proof_of_address_v1.md +5 -1
- data/docs/resume_v1.md +24 -1
- data/docs/us_driver_license_v1.md +6 -2
- data/docs/us_healthcare_cards_v1.md +5 -1
- data/docs/us_mail_v2.md +5 -1
- data/docs/us_w9_v1.md +6 -2
- data/examples/auto_invoice_splitter_extraction.rb +43 -0
- data/lib/mindee/client.rb +20 -8
- data/lib/mindee/{image_extraction → extraction}/common/image_extractor.rb +2 -4
- data/lib/mindee/{image_extraction → extraction}/common.rb +1 -0
- data/lib/mindee/extraction/pdf_extractor/extracted_pdf.rb +55 -0
- data/lib/mindee/extraction/pdf_extractor/pdf_extractor.rb +111 -0
- data/lib/mindee/extraction/pdf_extractor.rb +4 -0
- data/lib/mindee/extraction/tax_extractor/tax_extractor.rb +322 -0
- data/lib/mindee/extraction/tax_extractor.rb +1 -320
- data/lib/mindee/extraction.rb +3 -0
- data/lib/mindee/http/endpoint.rb +18 -6
- data/lib/mindee/parsing/common/api_response.rb +1 -1
- data/lib/mindee/parsing/common/document.rb +31 -1
- data/lib/mindee/parsing/common/extras/cropper_extra.rb +29 -0
- data/lib/mindee/parsing/common/extras/extras.rb +50 -0
- data/lib/mindee/parsing/common/extras/full_text_ocr_extra.rb +32 -0
- data/lib/mindee/parsing/common/extras.rb +5 -0
- data/lib/mindee/parsing/common/page.rb +5 -0
- data/lib/mindee/parsing/standard/base_field.rb +1 -0
- data/lib/mindee/product/bill_of_lading/bill_of_lading_v1.rb +39 -0
- data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rb +52 -0
- data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rb +95 -0
- data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rb +58 -0
- data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_document.rb +136 -0
- data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rb +58 -0
- data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_page.rb +32 -0
- data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rb +58 -0
- data/lib/mindee/product/financial_document/financial_document_v1_line_item.rb +15 -1
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb +4 -15
- data/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb +41 -0
- data/lib/mindee/product/fr/energy_bill/energy_bill_v1_document.rb +235 -0
- data/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rb +48 -0
- data/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rb +48 -0
- data/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb +97 -0
- data/lib/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rb +54 -0
- data/lib/mindee/product/fr/energy_bill/energy_bill_v1_page.rb +34 -0
- data/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rb +97 -0
- data/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rb +97 -0
- data/lib/mindee/product/fr/payslip/payslip_v2.rb +41 -0
- data/lib/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rb +54 -0
- data/lib/mindee/product/fr/payslip/payslip_v2_document.rb +128 -0
- data/lib/mindee/product/fr/payslip/payslip_v2_employee.rb +78 -0
- data/lib/mindee/product/fr/payslip/payslip_v2_employer.rb +78 -0
- data/lib/mindee/product/fr/payslip/payslip_v2_employment.rb +72 -0
- data/lib/mindee/product/fr/payslip/payslip_v2_page.rb +34 -0
- data/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb +100 -0
- data/lib/mindee/product/fr/payslip/payslip_v2_pay_period.rb +66 -0
- data/lib/mindee/product/fr/payslip/payslip_v2_pto.rb +56 -0
- data/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb +81 -0
- data/lib/mindee/product/invoice/invoice_v4_line_item.rb +15 -1
- data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +1 -1
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rb +39 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rb +52 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rb +52 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rb +52 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rb +52 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb +173 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb +87 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rb +32 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rb +52 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rb +52 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb +46 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rb +58 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rb +52 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rb +52 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rb +52 -0
- data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rb +52 -0
- data/lib/mindee/product/receipt/receipt_v5_line_item.rb +11 -1
- data/lib/mindee/product/resume/resume_v1_certificate.rb +11 -1
- data/lib/mindee/product/resume/resume_v1_education.rb +14 -1
- data/lib/mindee/product/resume/resume_v1_language.rb +9 -1
- data/lib/mindee/product/resume/resume_v1_professional_experience.rb +15 -1
- data/lib/mindee/product/resume/resume_v1_social_networks_url.rb +9 -1
- data/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rb +9 -1
- data/lib/mindee/product/us/us_mail/us_mail_v2_recipient_address.rb +14 -1
- data/lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb +5 -17
- data/lib/mindee/product.rb +5 -1
- data/lib/mindee/version.rb +1 -1
- metadata +70 -9
- data/lib/mindee/image_extraction.rb +0 -4
- /data/lib/mindee/{image_extraction → extraction}/common/extracted_image.rb +0 -0
- /data/lib/mindee/{image_extraction → extraction}/multi_receipts_extractor/multi_receipts_extractor.rb +0 -0
- /data/lib/mindee/{image_extraction → extraction}/multi_receipts_extractor.rb +0 -0
- /data/lib/mindee/extraction/{ocr_extractor.rb → tax_extractor/ocr_extractor.rb} +0 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module FR
|
8
|
+
module Payslip
|
9
|
+
# Information about the pay period.
|
10
|
+
class PayslipV2PayPeriod < Mindee::Parsing::Standard::FeatureField
|
11
|
+
include Mindee::Parsing::Standard
|
12
|
+
# The end date of the pay period.
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :end_date
|
15
|
+
# The month of the pay period.
|
16
|
+
# @return [String]
|
17
|
+
attr_reader :month
|
18
|
+
# The date of payment for the pay period.
|
19
|
+
# @return [String]
|
20
|
+
attr_reader :payment_date
|
21
|
+
# The start date of the pay period.
|
22
|
+
# @return [String]
|
23
|
+
attr_reader :start_date
|
24
|
+
# The year of the pay period.
|
25
|
+
# @return [String]
|
26
|
+
attr_reader :year
|
27
|
+
|
28
|
+
# @param prediction [Hash]
|
29
|
+
# @param page_id [Integer, nil]
|
30
|
+
def initialize(prediction, page_id)
|
31
|
+
super(prediction, page_id)
|
32
|
+
@end_date = prediction['end_date']
|
33
|
+
@month = prediction['month']
|
34
|
+
@payment_date = prediction['payment_date']
|
35
|
+
@start_date = prediction['start_date']
|
36
|
+
@year = prediction['year']
|
37
|
+
@page_id = page_id
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Hash]
|
41
|
+
def printable_values
|
42
|
+
printable = {}
|
43
|
+
printable[:end_date] = format_for_display(@end_date)
|
44
|
+
printable[:month] = format_for_display(@month)
|
45
|
+
printable[:payment_date] = format_for_display(@payment_date)
|
46
|
+
printable[:start_date] = format_for_display(@start_date)
|
47
|
+
printable[:year] = format_for_display(@year)
|
48
|
+
printable
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [String]
|
52
|
+
def to_s
|
53
|
+
printable = printable_values
|
54
|
+
out_str = String.new
|
55
|
+
out_str << "\n :End Date: #{printable[:end_date]}"
|
56
|
+
out_str << "\n :Month: #{printable[:month]}"
|
57
|
+
out_str << "\n :Payment Date: #{printable[:payment_date]}"
|
58
|
+
out_str << "\n :Start Date: #{printable[:start_date]}"
|
59
|
+
out_str << "\n :Year: #{printable[:year]}"
|
60
|
+
out_str
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module FR
|
8
|
+
module Payslip
|
9
|
+
# Information about paid time off.
|
10
|
+
class PayslipV2Pto < Mindee::Parsing::Standard::FeatureField
|
11
|
+
include Mindee::Parsing::Standard
|
12
|
+
# The amount of paid time off accrued in this period.
|
13
|
+
# @return [Float]
|
14
|
+
attr_reader :accrued_this_period
|
15
|
+
# The balance of paid time off at the end of the period.
|
16
|
+
# @return [Float]
|
17
|
+
attr_reader :balance_end_of_period
|
18
|
+
# The amount of paid time off used in this period.
|
19
|
+
# @return [Float]
|
20
|
+
attr_reader :used_this_period
|
21
|
+
|
22
|
+
# @param prediction [Hash]
|
23
|
+
# @param page_id [Integer, nil]
|
24
|
+
def initialize(prediction, page_id)
|
25
|
+
super(prediction, page_id)
|
26
|
+
@accrued_this_period = prediction['accrued_this_period']
|
27
|
+
@balance_end_of_period = prediction['balance_end_of_period']
|
28
|
+
@used_this_period = prediction['used_this_period']
|
29
|
+
@page_id = page_id
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Hash]
|
33
|
+
def printable_values
|
34
|
+
printable = {}
|
35
|
+
printable[:accrued_this_period] =
|
36
|
+
@accrued_this_period.nil? ? '' : Field.float_to_string(@accrued_this_period)
|
37
|
+
printable[:balance_end_of_period] =
|
38
|
+
@balance_end_of_period.nil? ? '' : Field.float_to_string(@balance_end_of_period)
|
39
|
+
printable[:used_this_period] = @used_this_period.nil? ? '' : Field.float_to_string(@used_this_period)
|
40
|
+
printable
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [String]
|
44
|
+
def to_s
|
45
|
+
printable = printable_values
|
46
|
+
out_str = String.new
|
47
|
+
out_str << "\n :Accrued This Period: #{printable[:accrued_this_period]}"
|
48
|
+
out_str << "\n :Balance End of Period: #{printable[:balance_end_of_period]}"
|
49
|
+
out_str << "\n :Used This Period: #{printable[:used_this_period]}"
|
50
|
+
out_str
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module FR
|
8
|
+
module Payslip
|
9
|
+
# Detailed information about the earnings.
|
10
|
+
class PayslipV2SalaryDetail < Mindee::Parsing::Standard::FeatureField
|
11
|
+
include Mindee::Parsing::Standard
|
12
|
+
# The amount of the earnings.
|
13
|
+
# @return [Float]
|
14
|
+
attr_reader :amount
|
15
|
+
# The base value of the earnings.
|
16
|
+
# @return [Float]
|
17
|
+
attr_reader :base
|
18
|
+
# The description of the earnings.
|
19
|
+
# @return [String]
|
20
|
+
attr_reader :description
|
21
|
+
# The rate of the earnings.
|
22
|
+
# @return [Float]
|
23
|
+
attr_reader :rate
|
24
|
+
|
25
|
+
# @param prediction [Hash]
|
26
|
+
# @param page_id [Integer, nil]
|
27
|
+
def initialize(prediction, page_id)
|
28
|
+
super(prediction, page_id)
|
29
|
+
@amount = prediction['amount']
|
30
|
+
@base = prediction['base']
|
31
|
+
@description = prediction['description']
|
32
|
+
@rate = prediction['rate']
|
33
|
+
@page_id = page_id
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Hash]
|
37
|
+
def printable_values
|
38
|
+
printable = {}
|
39
|
+
printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount)
|
40
|
+
printable[:base] = @base.nil? ? '' : Field.float_to_string(@base)
|
41
|
+
printable[:description] = format_for_display(@description)
|
42
|
+
printable[:rate] = @rate.nil? ? '' : Field.float_to_string(@rate)
|
43
|
+
printable
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Hash]
|
47
|
+
def table_printable_values
|
48
|
+
printable = {}
|
49
|
+
printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount)
|
50
|
+
printable[:base] = @base.nil? ? '' : Field.float_to_string(@base)
|
51
|
+
printable[:description] = format_for_display(@description, 36)
|
52
|
+
printable[:rate] = @rate.nil? ? '' : Field.float_to_string(@rate)
|
53
|
+
printable
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [String]
|
57
|
+
def to_table_line
|
58
|
+
printable = table_printable_values
|
59
|
+
out_str = String.new
|
60
|
+
out_str << format('| %- 13s', printable[:amount])
|
61
|
+
out_str << format('| %- 10s', printable[:base])
|
62
|
+
out_str << format('| %- 37s', printable[:description])
|
63
|
+
out_str << format('| %- 10s', printable[:rate])
|
64
|
+
out_str << '|'
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [String]
|
68
|
+
def to_s
|
69
|
+
printable = printable_values
|
70
|
+
out_str = String.new
|
71
|
+
out_str << "\n :Amount: #{printable[:amount]}"
|
72
|
+
out_str << "\n :Base: #{printable[:base]}"
|
73
|
+
out_str << "\n :Description: #{printable[:description]}"
|
74
|
+
out_str << "\n :Rate: #{printable[:rate]}"
|
75
|
+
out_str
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -50,6 +50,20 @@ module Mindee
|
|
50
50
|
|
51
51
|
# @return [Hash]
|
52
52
|
def printable_values
|
53
|
+
printable = {}
|
54
|
+
printable[:description] = format_for_display(@description)
|
55
|
+
printable[:product_code] = format_for_display(@product_code)
|
56
|
+
printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity)
|
57
|
+
printable[:tax_amount] = @tax_amount.nil? ? '' : Field.float_to_string(@tax_amount)
|
58
|
+
printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate)
|
59
|
+
printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount)
|
60
|
+
printable[:unit_measure] = format_for_display(@unit_measure)
|
61
|
+
printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price)
|
62
|
+
printable
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Hash]
|
66
|
+
def table_printable_values
|
53
67
|
printable = {}
|
54
68
|
printable[:description] = format_for_display(@description, 36)
|
55
69
|
printable[:product_code] = format_for_display(@product_code, nil)
|
@@ -64,7 +78,7 @@ module Mindee
|
|
64
78
|
|
65
79
|
# @return [String]
|
66
80
|
def to_table_line
|
67
|
-
printable =
|
81
|
+
printable = table_printable_values
|
68
82
|
out_str = String.new
|
69
83
|
out_str << format('| %- 37s', printable[:description])
|
70
84
|
out_str << format('| %- 13s', printable[:product_code])
|
@@ -29,7 +29,7 @@ module Mindee
|
|
29
29
|
|
30
30
|
# Invoice Splitter V1 document prediction.
|
31
31
|
class InvoiceSplitterV1Document < Mindee::Parsing::Common::Prediction
|
32
|
-
# @return[Array<Mindee::Product::InvoiceSplitterV1PageGroup>]
|
32
|
+
# @return[Array<Mindee::Product::InvoiceSplitter::InvoiceSplitterV1PageGroup>]
|
33
33
|
attr_reader :invoice_page_groups
|
34
34
|
|
35
35
|
# @param prediction [Hash]
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../parsing'
|
4
|
+
require_relative 'nutrition_facts_label_v1_document'
|
5
|
+
require_relative 'nutrition_facts_label_v1_page'
|
6
|
+
|
7
|
+
module Mindee
|
8
|
+
module Product
|
9
|
+
# Nutrition Facts Label module.
|
10
|
+
module NutritionFactsLabel
|
11
|
+
# Nutrition Facts Label API version 1 inference prediction.
|
12
|
+
class NutritionFactsLabelV1 < Mindee::Parsing::Common::Inference
|
13
|
+
@endpoint_name = 'nutrition_facts'
|
14
|
+
@endpoint_version = '1'
|
15
|
+
|
16
|
+
# @param prediction [Hash]
|
17
|
+
def initialize(prediction)
|
18
|
+
super
|
19
|
+
@prediction = NutritionFactsLabelV1Document.new(prediction['prediction'], nil)
|
20
|
+
@pages = []
|
21
|
+
prediction['pages'].each do |page|
|
22
|
+
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
|
23
|
+
@pages.push(NutritionFactsLabelV1Page.new(page))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
# Name of the endpoint for this product.
|
30
|
+
# @return [String]
|
31
|
+
attr_reader :endpoint_name
|
32
|
+
# Version for this product.
|
33
|
+
# @return [String]
|
34
|
+
attr_reader :endpoint_version
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module NutritionFactsLabel
|
8
|
+
# The amount of added sugars in the product.
|
9
|
+
class NutritionFactsLabelV1AddedSugar < Mindee::Parsing::Standard::FeatureField
|
10
|
+
include Mindee::Parsing::Standard
|
11
|
+
# DVs are the recommended amounts of added sugars to consume or not to exceed each day.
|
12
|
+
# @return [Float]
|
13
|
+
attr_reader :daily_value
|
14
|
+
# The amount of added sugars per 100g of the product.
|
15
|
+
# @return [Float]
|
16
|
+
attr_reader :per_100g
|
17
|
+
# The amount of added sugars per serving of the product.
|
18
|
+
# @return [Float]
|
19
|
+
attr_reader :per_serving
|
20
|
+
|
21
|
+
# @param prediction [Hash]
|
22
|
+
# @param page_id [Integer, nil]
|
23
|
+
def initialize(prediction, page_id)
|
24
|
+
super(prediction, page_id)
|
25
|
+
@daily_value = prediction['daily_value']
|
26
|
+
@per_100g = prediction['per_100g']
|
27
|
+
@per_serving = prediction['per_serving']
|
28
|
+
@page_id = page_id
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Hash]
|
32
|
+
def printable_values
|
33
|
+
printable = {}
|
34
|
+
printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value)
|
35
|
+
printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g)
|
36
|
+
printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving)
|
37
|
+
printable
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [String]
|
41
|
+
def to_s
|
42
|
+
printable = printable_values
|
43
|
+
out_str = String.new
|
44
|
+
out_str << "\n :Daily Value: #{printable[:daily_value]}"
|
45
|
+
out_str << "\n :Per 100g: #{printable[:per_100g]}"
|
46
|
+
out_str << "\n :Per Serving: #{printable[:per_serving]}"
|
47
|
+
out_str
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module NutritionFactsLabel
|
8
|
+
# The amount of calories in the product.
|
9
|
+
class NutritionFactsLabelV1Calorie < Mindee::Parsing::Standard::FeatureField
|
10
|
+
include Mindee::Parsing::Standard
|
11
|
+
# DVs are the recommended amounts of calories to consume or not to exceed each day.
|
12
|
+
# @return [Float]
|
13
|
+
attr_reader :daily_value
|
14
|
+
# The amount of calories per 100g of the product.
|
15
|
+
# @return [Float]
|
16
|
+
attr_reader :per_100g
|
17
|
+
# The amount of calories per serving of the product.
|
18
|
+
# @return [Float]
|
19
|
+
attr_reader :per_serving
|
20
|
+
|
21
|
+
# @param prediction [Hash]
|
22
|
+
# @param page_id [Integer, nil]
|
23
|
+
def initialize(prediction, page_id)
|
24
|
+
super(prediction, page_id)
|
25
|
+
@daily_value = prediction['daily_value']
|
26
|
+
@per_100g = prediction['per_100g']
|
27
|
+
@per_serving = prediction['per_serving']
|
28
|
+
@page_id = page_id
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Hash]
|
32
|
+
def printable_values
|
33
|
+
printable = {}
|
34
|
+
printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value)
|
35
|
+
printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g)
|
36
|
+
printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving)
|
37
|
+
printable
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [String]
|
41
|
+
def to_s
|
42
|
+
printable = printable_values
|
43
|
+
out_str = String.new
|
44
|
+
out_str << "\n :Daily Value: #{printable[:daily_value]}"
|
45
|
+
out_str << "\n :Per 100g: #{printable[:per_100g]}"
|
46
|
+
out_str << "\n :Per Serving: #{printable[:per_serving]}"
|
47
|
+
out_str
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module NutritionFactsLabel
|
8
|
+
# The amount of cholesterol in the product.
|
9
|
+
class NutritionFactsLabelV1Cholesterol < Mindee::Parsing::Standard::FeatureField
|
10
|
+
include Mindee::Parsing::Standard
|
11
|
+
# DVs are the recommended amounts of cholesterol to consume or not to exceed each day.
|
12
|
+
# @return [Float]
|
13
|
+
attr_reader :daily_value
|
14
|
+
# The amount of cholesterol per 100g of the product.
|
15
|
+
# @return [Float]
|
16
|
+
attr_reader :per_100g
|
17
|
+
# The amount of cholesterol per serving of the product.
|
18
|
+
# @return [Float]
|
19
|
+
attr_reader :per_serving
|
20
|
+
|
21
|
+
# @param prediction [Hash]
|
22
|
+
# @param page_id [Integer, nil]
|
23
|
+
def initialize(prediction, page_id)
|
24
|
+
super(prediction, page_id)
|
25
|
+
@daily_value = prediction['daily_value']
|
26
|
+
@per_100g = prediction['per_100g']
|
27
|
+
@per_serving = prediction['per_serving']
|
28
|
+
@page_id = page_id
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Hash]
|
32
|
+
def printable_values
|
33
|
+
printable = {}
|
34
|
+
printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value)
|
35
|
+
printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g)
|
36
|
+
printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving)
|
37
|
+
printable
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [String]
|
41
|
+
def to_s
|
42
|
+
printable = printable_values
|
43
|
+
out_str = String.new
|
44
|
+
out_str << "\n :Daily Value: #{printable[:daily_value]}"
|
45
|
+
out_str << "\n :Per 100g: #{printable[:per_100g]}"
|
46
|
+
out_str << "\n :Per Serving: #{printable[:per_serving]}"
|
47
|
+
out_str
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../parsing'
|
4
|
+
|
5
|
+
module Mindee
|
6
|
+
module Product
|
7
|
+
module NutritionFactsLabel
|
8
|
+
# The amount of dietary fiber in the product.
|
9
|
+
class NutritionFactsLabelV1DietaryFiber < Mindee::Parsing::Standard::FeatureField
|
10
|
+
include Mindee::Parsing::Standard
|
11
|
+
# DVs are the recommended amounts of dietary fiber to consume or not to exceed each day.
|
12
|
+
# @return [Float]
|
13
|
+
attr_reader :daily_value
|
14
|
+
# The amount of dietary fiber per 100g of the product.
|
15
|
+
# @return [Float]
|
16
|
+
attr_reader :per_100g
|
17
|
+
# The amount of dietary fiber per serving of the product.
|
18
|
+
# @return [Float]
|
19
|
+
attr_reader :per_serving
|
20
|
+
|
21
|
+
# @param prediction [Hash]
|
22
|
+
# @param page_id [Integer, nil]
|
23
|
+
def initialize(prediction, page_id)
|
24
|
+
super(prediction, page_id)
|
25
|
+
@daily_value = prediction['daily_value']
|
26
|
+
@per_100g = prediction['per_100g']
|
27
|
+
@per_serving = prediction['per_serving']
|
28
|
+
@page_id = page_id
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Hash]
|
32
|
+
def printable_values
|
33
|
+
printable = {}
|
34
|
+
printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value)
|
35
|
+
printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g)
|
36
|
+
printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving)
|
37
|
+
printable
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [String]
|
41
|
+
def to_s
|
42
|
+
printable = printable_values
|
43
|
+
out_str = String.new
|
44
|
+
out_str << "\n :Daily Value: #{printable[:daily_value]}"
|
45
|
+
out_str << "\n :Per 100g: #{printable[:per_100g]}"
|
46
|
+
out_str << "\n :Per Serving: #{printable[:per_serving]}"
|
47
|
+
out_str
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../parsing'
|
4
|
+
require_relative 'nutrition_facts_label_v1_serving_size'
|
5
|
+
require_relative 'nutrition_facts_label_v1_calorie'
|
6
|
+
require_relative 'nutrition_facts_label_v1_total_fat'
|
7
|
+
require_relative 'nutrition_facts_label_v1_saturated_fat'
|
8
|
+
require_relative 'nutrition_facts_label_v1_trans_fat'
|
9
|
+
require_relative 'nutrition_facts_label_v1_cholesterol'
|
10
|
+
require_relative 'nutrition_facts_label_v1_total_carbohydrate'
|
11
|
+
require_relative 'nutrition_facts_label_v1_dietary_fiber'
|
12
|
+
require_relative 'nutrition_facts_label_v1_total_sugar'
|
13
|
+
require_relative 'nutrition_facts_label_v1_added_sugar'
|
14
|
+
require_relative 'nutrition_facts_label_v1_protein'
|
15
|
+
require_relative 'nutrition_facts_label_v1_sodium'
|
16
|
+
require_relative 'nutrition_facts_label_v1_nutrient'
|
17
|
+
|
18
|
+
module Mindee
|
19
|
+
module Product
|
20
|
+
module NutritionFactsLabel
|
21
|
+
# Nutrition Facts Label API version 1.0 document data.
|
22
|
+
class NutritionFactsLabelV1Document < Mindee::Parsing::Common::Prediction
|
23
|
+
include Mindee::Parsing::Standard
|
24
|
+
# The amount of added sugars in the product.
|
25
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1AddedSugar]
|
26
|
+
attr_reader :added_sugars
|
27
|
+
# The amount of calories in the product.
|
28
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Calorie]
|
29
|
+
attr_reader :calories
|
30
|
+
# The amount of cholesterol in the product.
|
31
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Cholesterol]
|
32
|
+
attr_reader :cholesterol
|
33
|
+
# The amount of dietary fiber in the product.
|
34
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1DietaryFiber]
|
35
|
+
attr_reader :dietary_fiber
|
36
|
+
# The amount of nutrients in the product.
|
37
|
+
# @return [Array<Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrient>]
|
38
|
+
attr_reader :nutrients
|
39
|
+
# The amount of protein in the product.
|
40
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Protein]
|
41
|
+
attr_reader :protein
|
42
|
+
# The amount of saturated fat in the product.
|
43
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1SaturatedFat]
|
44
|
+
attr_reader :saturated_fat
|
45
|
+
# The number of servings in each box of the product.
|
46
|
+
# @return [Mindee::Parsing::Standard::AmountField]
|
47
|
+
attr_reader :serving_per_box
|
48
|
+
# The size of a single serving of the product.
|
49
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1ServingSize]
|
50
|
+
attr_reader :serving_size
|
51
|
+
# The amount of sodium in the product.
|
52
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Sodium]
|
53
|
+
attr_reader :sodium
|
54
|
+
# The total amount of carbohydrates in the product.
|
55
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TotalCarbohydrate]
|
56
|
+
attr_reader :total_carbohydrate
|
57
|
+
# The total amount of fat in the product.
|
58
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TotalFat]
|
59
|
+
attr_reader :total_fat
|
60
|
+
# The total amount of sugars in the product.
|
61
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TotalSugar]
|
62
|
+
attr_reader :total_sugars
|
63
|
+
# The amount of trans fat in the product.
|
64
|
+
# @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1TransFat]
|
65
|
+
attr_reader :trans_fat
|
66
|
+
|
67
|
+
# @param prediction [Hash]
|
68
|
+
# @param page_id [Integer, nil]
|
69
|
+
def initialize(prediction, page_id)
|
70
|
+
super()
|
71
|
+
@added_sugars = NutritionFactsLabelV1AddedSugar.new(prediction['added_sugars'], page_id)
|
72
|
+
@calories = NutritionFactsLabelV1Calorie.new(prediction['calories'], page_id)
|
73
|
+
@cholesterol = NutritionFactsLabelV1Cholesterol.new(prediction['cholesterol'], page_id)
|
74
|
+
@dietary_fiber = NutritionFactsLabelV1DietaryFiber.new(prediction['dietary_fiber'], page_id)
|
75
|
+
@nutrients = []
|
76
|
+
prediction['nutrients'].each do |item|
|
77
|
+
@nutrients.push(NutritionFactsLabelV1Nutrient.new(item, page_id))
|
78
|
+
end
|
79
|
+
@protein = NutritionFactsLabelV1Protein.new(prediction['protein'], page_id)
|
80
|
+
@saturated_fat = NutritionFactsLabelV1SaturatedFat.new(prediction['saturated_fat'], page_id)
|
81
|
+
@serving_per_box = AmountField.new(prediction['serving_per_box'], page_id)
|
82
|
+
@serving_size = NutritionFactsLabelV1ServingSize.new(prediction['serving_size'], page_id)
|
83
|
+
@sodium = NutritionFactsLabelV1Sodium.new(prediction['sodium'], page_id)
|
84
|
+
@total_carbohydrate = NutritionFactsLabelV1TotalCarbohydrate.new(prediction['total_carbohydrate'], page_id)
|
85
|
+
@total_fat = NutritionFactsLabelV1TotalFat.new(prediction['total_fat'], page_id)
|
86
|
+
@total_sugars = NutritionFactsLabelV1TotalSugar.new(prediction['total_sugars'], page_id)
|
87
|
+
@trans_fat = NutritionFactsLabelV1TransFat.new(prediction['trans_fat'], page_id)
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return [String]
|
91
|
+
def to_s
|
92
|
+
serving_size = @serving_size.to_s
|
93
|
+
calories = @calories.to_s
|
94
|
+
total_fat = @total_fat.to_s
|
95
|
+
saturated_fat = @saturated_fat.to_s
|
96
|
+
trans_fat = @trans_fat.to_s
|
97
|
+
cholesterol = @cholesterol.to_s
|
98
|
+
total_carbohydrate = @total_carbohydrate.to_s
|
99
|
+
dietary_fiber = @dietary_fiber.to_s
|
100
|
+
total_sugars = @total_sugars.to_s
|
101
|
+
added_sugars = @added_sugars.to_s
|
102
|
+
protein = @protein.to_s
|
103
|
+
sodium = @sodium.to_s
|
104
|
+
nutrients = nutrients_to_s
|
105
|
+
out_str = String.new
|
106
|
+
out_str << "\n:Serving per Box: #{@serving_per_box}".rstrip
|
107
|
+
out_str << "\n:Serving Size:"
|
108
|
+
out_str << serving_size
|
109
|
+
out_str << "\n:Calories:"
|
110
|
+
out_str << calories
|
111
|
+
out_str << "\n:Total Fat:"
|
112
|
+
out_str << total_fat
|
113
|
+
out_str << "\n:Saturated Fat:"
|
114
|
+
out_str << saturated_fat
|
115
|
+
out_str << "\n:Trans Fat:"
|
116
|
+
out_str << trans_fat
|
117
|
+
out_str << "\n:Cholesterol:"
|
118
|
+
out_str << cholesterol
|
119
|
+
out_str << "\n:Total Carbohydrate:"
|
120
|
+
out_str << total_carbohydrate
|
121
|
+
out_str << "\n:Dietary Fiber:"
|
122
|
+
out_str << dietary_fiber
|
123
|
+
out_str << "\n:Total Sugars:"
|
124
|
+
out_str << total_sugars
|
125
|
+
out_str << "\n:Added Sugars:"
|
126
|
+
out_str << added_sugars
|
127
|
+
out_str << "\n:Protein:"
|
128
|
+
out_str << protein
|
129
|
+
out_str << "\n:sodium:"
|
130
|
+
out_str << sodium
|
131
|
+
out_str << "\n:nutrients:"
|
132
|
+
out_str << nutrients
|
133
|
+
out_str[1..].to_s
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
# @param char [String]
|
139
|
+
# @return [String]
|
140
|
+
def nutrients_separator(char)
|
141
|
+
out_str = String.new
|
142
|
+
out_str << ' '
|
143
|
+
out_str << "+#{char * 13}"
|
144
|
+
out_str << "+#{char * 22}"
|
145
|
+
out_str << "+#{char * 10}"
|
146
|
+
out_str << "+#{char * 13}"
|
147
|
+
out_str << "+#{char * 6}"
|
148
|
+
out_str << '+'
|
149
|
+
out_str
|
150
|
+
end
|
151
|
+
|
152
|
+
# @return [String]
|
153
|
+
def nutrients_to_s
|
154
|
+
return '' if @nutrients.empty?
|
155
|
+
|
156
|
+
line_items = @nutrients.map(&:to_table_line).join("\n#{nutrients_separator('-')}\n ")
|
157
|
+
out_str = String.new
|
158
|
+
out_str << "\n#{nutrients_separator('-')}"
|
159
|
+
out_str << "\n |"
|
160
|
+
out_str << ' Daily Value |'
|
161
|
+
out_str << ' Name |'
|
162
|
+
out_str << ' Per 100g |'
|
163
|
+
out_str << ' Per Serving |'
|
164
|
+
out_str << ' Unit |'
|
165
|
+
out_str << "\n#{nutrients_separator('=')}"
|
166
|
+
out_str << "\n #{line_items}"
|
167
|
+
out_str << "\n#{nutrients_separator('-')}"
|
168
|
+
out_str
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|