mindee 3.12.0 → 3.14.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.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +26 -0
  4. data/README.md +23 -23
  5. data/Rakefile +5 -0
  6. data/docs/bank_account_details_v2.md +5 -1
  7. data/docs/bank_check_v1.md +6 -2
  8. data/docs/bank_statement_fr_v1.md +3 -0
  9. data/docs/barcode_reader_v1.md +5 -1
  10. data/docs/bill_of_lading_v1.md +251 -0
  11. data/docs/carte_grise_v1.md +5 -1
  12. data/docs/carte_vitale_v1.md +5 -1
  13. data/docs/code_samples/bill_of_lading_v1_async.txt +19 -0
  14. data/docs/code_samples/energy_bill_fra_v1_async.txt +19 -0
  15. data/docs/code_samples/invoices_v4_async.txt +19 -0
  16. data/docs/code_samples/nutrition_facts_v1_async.txt +19 -0
  17. data/docs/code_samples/payslip_fra_v2_async.txt +19 -0
  18. data/docs/cropper_v1.md +6 -2
  19. data/docs/custom_v1.md +5 -3
  20. data/docs/energy_bill_fra_v1.md +309 -0
  21. data/docs/eu_driver_license_v1.md +6 -2
  22. data/docs/expense_receipts_v5.md +30 -5
  23. data/docs/financial_document_v1.md +43 -1
  24. data/docs/generated_v1.md +3 -0
  25. data/docs/getting_started.md +3 -0
  26. data/docs/idcard_fr_v2.md +15 -2
  27. data/docs/international_id_v2.md +13 -1
  28. data/docs/invoice_splitter_v1.md +16 -13
  29. data/docs/invoices_v4.md +70 -23
  30. data/docs/license_plates_v1.md +5 -1
  31. data/docs/multi_receipts_detector_v1.md +5 -1
  32. data/docs/nutrition_facts_v1.md +374 -0
  33. data/docs/passport_v1.md +5 -1
  34. data/docs/payslip_fra_v2.md +294 -0
  35. data/docs/proof_of_address_v1.md +5 -1
  36. data/docs/resume_v1.md +24 -1
  37. data/docs/us_driver_license_v1.md +6 -2
  38. data/docs/us_healthcare_cards_v1.md +5 -1
  39. data/docs/us_mail_v2.md +6 -2
  40. data/docs/us_w9_v1.md +6 -2
  41. data/examples/auto_invoice_splitter_extraction.rb +48 -0
  42. data/examples/auto_multi_receipts_detector_extraction.rb +31 -0
  43. data/lib/mindee/client.rb +20 -8
  44. data/lib/mindee/{image_extraction → extraction}/common/extracted_image.rb +1 -1
  45. data/lib/mindee/extraction/common/image_extractor.rb +192 -0
  46. data/lib/mindee/{image_extraction → extraction}/common.rb +1 -0
  47. data/lib/mindee/extraction/multi_receipts_extractor/multi_receipts_extractor.rb +32 -0
  48. data/lib/mindee/extraction/pdf_extractor/extracted_pdf.rb +55 -0
  49. data/lib/mindee/extraction/pdf_extractor/pdf_extractor.rb +111 -0
  50. data/lib/mindee/extraction/pdf_extractor.rb +4 -0
  51. data/lib/mindee/extraction/tax_extractor/tax_extractor.rb +322 -0
  52. data/lib/mindee/extraction/tax_extractor.rb +1 -320
  53. data/lib/mindee/extraction.rb +3 -0
  54. data/lib/mindee/http/endpoint.rb +18 -6
  55. data/lib/mindee/parsing/common/api_response.rb +1 -1
  56. data/lib/mindee/parsing/common/document.rb +31 -1
  57. data/lib/mindee/parsing/common/extras/cropper_extra.rb +29 -0
  58. data/lib/mindee/parsing/common/extras/extras.rb +50 -0
  59. data/lib/mindee/parsing/common/extras/full_text_ocr_extra.rb +32 -0
  60. data/lib/mindee/parsing/common/extras.rb +5 -0
  61. data/lib/mindee/parsing/common/page.rb +5 -0
  62. data/lib/mindee/parsing/standard/base_field.rb +1 -0
  63. data/lib/mindee/parsing/standard/date_field.rb +4 -0
  64. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1.rb +39 -0
  65. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rb +52 -0
  66. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rb +95 -0
  67. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rb +58 -0
  68. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_document.rb +136 -0
  69. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rb +58 -0
  70. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_page.rb +32 -0
  71. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rb +58 -0
  72. data/lib/mindee/product/financial_document/financial_document_v1_document.rb +11 -1
  73. data/lib/mindee/product/financial_document/financial_document_v1_line_item.rb +15 -1
  74. data/lib/mindee/product/financial_document/financial_document_v1_page.rb +1 -1
  75. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb +4 -15
  76. data/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb +41 -0
  77. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_document.rb +235 -0
  78. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rb +48 -0
  79. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rb +48 -0
  80. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb +97 -0
  81. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rb +54 -0
  82. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_page.rb +34 -0
  83. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rb +97 -0
  84. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rb +97 -0
  85. data/lib/mindee/product/fr/payslip/payslip_v2.rb +41 -0
  86. data/lib/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rb +54 -0
  87. data/lib/mindee/product/fr/payslip/payslip_v2_document.rb +128 -0
  88. data/lib/mindee/product/fr/payslip/payslip_v2_employee.rb +78 -0
  89. data/lib/mindee/product/fr/payslip/payslip_v2_employer.rb +78 -0
  90. data/lib/mindee/product/fr/payslip/payslip_v2_employment.rb +72 -0
  91. data/lib/mindee/product/fr/payslip/payslip_v2_page.rb +34 -0
  92. data/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb +100 -0
  93. data/lib/mindee/product/fr/payslip/payslip_v2_pay_period.rb +66 -0
  94. data/lib/mindee/product/fr/payslip/payslip_v2_pto.rb +56 -0
  95. data/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb +81 -0
  96. data/lib/mindee/product/invoice/invoice_v4_document.rb +11 -1
  97. data/lib/mindee/product/invoice/invoice_v4_line_item.rb +15 -1
  98. data/lib/mindee/product/invoice/invoice_v4_page.rb +1 -1
  99. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +1 -1
  100. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rb +39 -0
  101. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rb +52 -0
  102. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rb +52 -0
  103. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rb +52 -0
  104. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rb +52 -0
  105. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb +173 -0
  106. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb +87 -0
  107. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rb +32 -0
  108. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rb +52 -0
  109. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rb +52 -0
  110. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb +46 -0
  111. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rb +58 -0
  112. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rb +52 -0
  113. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rb +52 -0
  114. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rb +52 -0
  115. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rb +52 -0
  116. data/lib/mindee/product/receipt/receipt_v5_line_item.rb +11 -1
  117. data/lib/mindee/product/resume/resume_v1_certificate.rb +11 -1
  118. data/lib/mindee/product/resume/resume_v1_education.rb +14 -1
  119. data/lib/mindee/product/resume/resume_v1_language.rb +9 -1
  120. data/lib/mindee/product/resume/resume_v1_professional_experience.rb +15 -1
  121. data/lib/mindee/product/resume/resume_v1_social_networks_url.rb +9 -1
  122. data/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rb +9 -1
  123. data/lib/mindee/product/us/us_mail/us_mail_v2_recipient_address.rb +14 -1
  124. data/lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb +5 -17
  125. data/lib/mindee/product.rb +5 -1
  126. data/lib/mindee/version.rb +1 -1
  127. metadata +71 -9
  128. data/lib/mindee/image_extraction/common/image_extractor.rb +0 -191
  129. data/lib/mindee/image_extraction/multi_receipts_extractor/multi_receipts_extractor.rb +0 -26
  130. data/lib/mindee/image_extraction.rb +0 -4
  131. /data/lib/mindee/{image_extraction → extraction}/multi_receipts_extractor.rb +0 -0
  132. /data/lib/mindee/extraction/{ocr_extractor.rb → tax_extractor/ocr_extractor.rb} +0 -0
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'bill_of_lading_v1_shipper'
5
+ require_relative 'bill_of_lading_v1_consignee'
6
+ require_relative 'bill_of_lading_v1_notify_party'
7
+ require_relative 'bill_of_lading_v1_carrier'
8
+ require_relative 'bill_of_lading_v1_carrier_item'
9
+
10
+ module Mindee
11
+ module Product
12
+ module BillOfLading
13
+ # Bill of Lading API version 1.1 document data.
14
+ class BillOfLadingV1Document < Mindee::Parsing::Common::Prediction
15
+ include Mindee::Parsing::Standard
16
+ # A unique identifier assigned to a Bill of Lading document.
17
+ # @return [Mindee::Parsing::Standard::StringField]
18
+ attr_reader :bill_of_lading_number
19
+ # The shipping company responsible for transporting the goods.
20
+ # @return [Mindee::Product::BillOfLading::BillOfLadingV1Carrier]
21
+ attr_reader :carrier
22
+ # The goods being shipped.
23
+ # @return [Array<Mindee::Product::BillOfLading::BillOfLadingV1CarrierItem>]
24
+ attr_reader :carrier_items
25
+ # The party to whom the goods are being shipped.
26
+ # @return [Mindee::Product::BillOfLading::BillOfLadingV1Consignee]
27
+ attr_reader :consignee
28
+ # The date when the bill of lading is issued.
29
+ # @return [Mindee::Parsing::Standard::DateField]
30
+ attr_reader :date_of_issue
31
+ # The date when the vessel departs from the port of loading.
32
+ # @return [Mindee::Parsing::Standard::DateField]
33
+ attr_reader :departure_date
34
+ # The party to be notified of the arrival of the goods.
35
+ # @return [Mindee::Product::BillOfLading::BillOfLadingV1NotifyParty]
36
+ attr_reader :notify_party
37
+ # The place where the goods are to be delivered.
38
+ # @return [Mindee::Parsing::Standard::StringField]
39
+ attr_reader :place_of_delivery
40
+ # The port where the goods are unloaded from the vessel.
41
+ # @return [Mindee::Parsing::Standard::StringField]
42
+ attr_reader :port_of_discharge
43
+ # The port where the goods are loaded onto the vessel.
44
+ # @return [Mindee::Parsing::Standard::StringField]
45
+ attr_reader :port_of_loading
46
+ # The party responsible for shipping the goods.
47
+ # @return [Mindee::Product::BillOfLading::BillOfLadingV1Shipper]
48
+ attr_reader :shipper
49
+
50
+ # @param prediction [Hash]
51
+ # @param page_id [Integer, nil]
52
+ def initialize(prediction, page_id)
53
+ super()
54
+ @bill_of_lading_number = StringField.new(prediction['bill_of_lading_number'], page_id)
55
+ @carrier = BillOfLadingV1Carrier.new(prediction['carrier'], page_id)
56
+ @carrier_items = []
57
+ prediction['carrier_items'].each do |item|
58
+ @carrier_items.push(BillOfLadingV1CarrierItem.new(item, page_id))
59
+ end
60
+ @consignee = BillOfLadingV1Consignee.new(prediction['consignee'], page_id)
61
+ @date_of_issue = DateField.new(prediction['date_of_issue'], page_id)
62
+ @departure_date = DateField.new(prediction['departure_date'], page_id)
63
+ @notify_party = BillOfLadingV1NotifyParty.new(prediction['notify_party'], page_id)
64
+ @place_of_delivery = StringField.new(prediction['place_of_delivery'], page_id)
65
+ @port_of_discharge = StringField.new(prediction['port_of_discharge'], page_id)
66
+ @port_of_loading = StringField.new(prediction['port_of_loading'], page_id)
67
+ @shipper = BillOfLadingV1Shipper.new(prediction['shipper'], page_id)
68
+ end
69
+
70
+ # @return [String]
71
+ def to_s
72
+ shipper = @shipper.to_s
73
+ consignee = @consignee.to_s
74
+ notify_party = @notify_party.to_s
75
+ carrier = @carrier.to_s
76
+ carrier_items = carrier_items_to_s
77
+ out_str = String.new
78
+ out_str << "\n:Bill of Lading Number: #{@bill_of_lading_number}".rstrip
79
+ out_str << "\n:Shipper:"
80
+ out_str << shipper
81
+ out_str << "\n:Consignee:"
82
+ out_str << consignee
83
+ out_str << "\n:Notify Party:"
84
+ out_str << notify_party
85
+ out_str << "\n:Carrier:"
86
+ out_str << carrier
87
+ out_str << "\n:Items:"
88
+ out_str << carrier_items
89
+ out_str << "\n:Port of Loading: #{@port_of_loading}".rstrip
90
+ out_str << "\n:Port of Discharge: #{@port_of_discharge}".rstrip
91
+ out_str << "\n:Place of Delivery: #{@place_of_delivery}".rstrip
92
+ out_str << "\n:Date of issue: #{@date_of_issue}".rstrip
93
+ out_str << "\n:Departure Date: #{@departure_date}".rstrip
94
+ out_str[1..].to_s
95
+ end
96
+
97
+ private
98
+
99
+ # @param char [String]
100
+ # @return [String]
101
+ def carrier_items_separator(char)
102
+ out_str = String.new
103
+ out_str << ' '
104
+ out_str << "+#{char * 38}"
105
+ out_str << "+#{char * 14}"
106
+ out_str << "+#{char * 13}"
107
+ out_str << "+#{char * 18}"
108
+ out_str << "+#{char * 10}"
109
+ out_str << "+#{char * 13}"
110
+ out_str << '+'
111
+ out_str
112
+ end
113
+
114
+ # @return [String]
115
+ def carrier_items_to_s
116
+ return '' if @carrier_items.empty?
117
+
118
+ line_items = @carrier_items.map(&:to_table_line).join("\n#{carrier_items_separator('-')}\n ")
119
+ out_str = String.new
120
+ out_str << "\n#{carrier_items_separator('-')}"
121
+ out_str << "\n |"
122
+ out_str << ' Description |'
123
+ out_str << ' Gross Weight |'
124
+ out_str << ' Measurement |'
125
+ out_str << ' Measurement Unit |'
126
+ out_str << ' Quantity |'
127
+ out_str << ' Weight Unit |'
128
+ out_str << "\n#{carrier_items_separator('=')}"
129
+ out_str << "\n #{line_items}"
130
+ out_str << "\n#{carrier_items_separator('-')}"
131
+ out_str
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module BillOfLading
8
+ # The party to be notified of the arrival of the goods.
9
+ class BillOfLadingV1NotifyParty < Mindee::Parsing::Standard::FeatureField
10
+ include Mindee::Parsing::Standard
11
+ # The address of the notify party.
12
+ # @return [String]
13
+ attr_reader :address
14
+ # The email of the shipper.
15
+ # @return [String]
16
+ attr_reader :email
17
+ # The name of the notify party.
18
+ # @return [String]
19
+ attr_reader :name
20
+ # The phone number of the notify party.
21
+ # @return [String]
22
+ attr_reader :phone
23
+
24
+ # @param prediction [Hash]
25
+ # @param page_id [Integer, nil]
26
+ def initialize(prediction, page_id)
27
+ super(prediction, page_id)
28
+ @address = prediction['address']
29
+ @email = prediction['email']
30
+ @name = prediction['name']
31
+ @phone = prediction['phone']
32
+ @page_id = page_id
33
+ end
34
+
35
+ # @return [Hash]
36
+ def printable_values
37
+ printable = {}
38
+ printable[:address] = format_for_display(@address)
39
+ printable[:email] = format_for_display(@email)
40
+ printable[:name] = format_for_display(@name)
41
+ printable[:phone] = format_for_display(@phone)
42
+ printable
43
+ end
44
+
45
+ # @return [String]
46
+ def to_s
47
+ printable = printable_values
48
+ out_str = String.new
49
+ out_str << "\n :Address: #{printable[:address]}"
50
+ out_str << "\n :Email: #{printable[:email]}"
51
+ out_str << "\n :Name: #{printable[:name]}"
52
+ out_str << "\n :Phone: #{printable[:phone]}"
53
+ out_str
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'bill_of_lading_v1_document'
5
+
6
+ module Mindee
7
+ module Product
8
+ module BillOfLading
9
+ # Bill of Lading API version 1.1 page data.
10
+ class BillOfLadingV1Page < Mindee::Parsing::Common::Page
11
+ # @param prediction [Hash]
12
+ def initialize(prediction)
13
+ super(prediction)
14
+ @prediction = BillOfLadingV1PagePrediction.new(
15
+ prediction['prediction'],
16
+ prediction['id']
17
+ )
18
+ end
19
+ end
20
+
21
+ # Bill of Lading V1 page prediction.
22
+ class BillOfLadingV1PagePrediction < BillOfLadingV1Document
23
+ # @return [String]
24
+ def to_s
25
+ out_str = String.new
26
+ out_str << "\n#{super}"
27
+ out_str
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module BillOfLading
8
+ # The party responsible for shipping the goods.
9
+ class BillOfLadingV1Shipper < Mindee::Parsing::Standard::FeatureField
10
+ include Mindee::Parsing::Standard
11
+ # The address of the shipper.
12
+ # @return [String]
13
+ attr_reader :address
14
+ # The email of the shipper.
15
+ # @return [String]
16
+ attr_reader :email
17
+ # The name of the shipper.
18
+ # @return [String]
19
+ attr_reader :name
20
+ # The phone number of the shipper.
21
+ # @return [String]
22
+ attr_reader :phone
23
+
24
+ # @param prediction [Hash]
25
+ # @param page_id [Integer, nil]
26
+ def initialize(prediction, page_id)
27
+ super(prediction, page_id)
28
+ @address = prediction['address']
29
+ @email = prediction['email']
30
+ @name = prediction['name']
31
+ @phone = prediction['phone']
32
+ @page_id = page_id
33
+ end
34
+
35
+ # @return [Hash]
36
+ def printable_values
37
+ printable = {}
38
+ printable[:address] = format_for_display(@address)
39
+ printable[:email] = format_for_display(@email)
40
+ printable[:name] = format_for_display(@name)
41
+ printable[:phone] = format_for_display(@phone)
42
+ printable
43
+ end
44
+
45
+ # @return [String]
46
+ def to_s
47
+ printable = printable_values
48
+ out_str = String.new
49
+ out_str << "\n :Address: #{printable[:address]}"
50
+ out_str << "\n :Email: #{printable[:email]}"
51
+ out_str << "\n :Name: #{printable[:name]}"
52
+ out_str << "\n :Phone: #{printable[:phone]}"
53
+ out_str
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -6,7 +6,7 @@ require_relative 'financial_document_v1_line_item'
6
6
  module Mindee
7
7
  module Product
8
8
  module FinancialDocument
9
- # Financial Document API version 1.9 document data.
9
+ # Financial Document API version 1.10 document data.
10
10
  class FinancialDocumentV1Document < Mindee::Parsing::Common::Prediction
11
11
  include Mindee::Parsing::Standard
12
12
  # The customer's address used for billing.
@@ -48,6 +48,12 @@ module Mindee
48
48
  # The locale detected on the document.
49
49
  # @return [Mindee::Parsing::Standard::LocaleField]
50
50
  attr_reader :locale
51
+ # The date on which the payment is due / fullfilled.
52
+ # @return [Mindee::Parsing::Standard::DateField]
53
+ attr_reader :payment_date
54
+ # The purchase order number.
55
+ # @return [Mindee::Parsing::Standard::StringField]
56
+ attr_reader :po_number
51
57
  # The receipt number or identifier only if document is a receipt.
52
58
  # @return [Mindee::Parsing::Standard::StringField]
53
59
  attr_reader :receipt_number
@@ -123,6 +129,8 @@ module Mindee
123
129
  @line_items.push(FinancialDocumentV1LineItem.new(item, page_id))
124
130
  end
125
131
  @locale = LocaleField.new(prediction['locale'], page_id)
132
+ @payment_date = DateField.new(prediction['payment_date'], page_id)
133
+ @po_number = StringField.new(prediction['po_number'], page_id)
126
134
  @receipt_number = StringField.new(prediction['receipt_number'], page_id)
127
135
  @reference_numbers = []
128
136
  prediction['reference_numbers'].each do |item|
@@ -161,11 +169,13 @@ module Mindee
161
169
  out_str = String.new
162
170
  out_str << "\n:Locale: #{@locale}".rstrip
163
171
  out_str << "\n:Invoice Number: #{@invoice_number}".rstrip
172
+ out_str << "\n:Purchase Order Number: #{@po_number}".rstrip
164
173
  out_str << "\n:Receipt Number: #{@receipt_number}".rstrip
165
174
  out_str << "\n:Document Number: #{@document_number}".rstrip
166
175
  out_str << "\n:Reference Numbers: #{reference_numbers}".rstrip
167
176
  out_str << "\n:Purchase Date: #{@date}".rstrip
168
177
  out_str << "\n:Due Date: #{@due_date}".rstrip
178
+ out_str << "\n:Payment Date: #{@payment_date}".rstrip
169
179
  out_str << "\n:Total Net: #{@total_net}".rstrip
170
180
  out_str << "\n:Total Amount: #{@total_amount}".rstrip
171
181
  out_str << "\n:Taxes:#{@taxes}".rstrip
@@ -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 = printable_values
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])
@@ -6,7 +6,7 @@ require_relative 'financial_document_v1_document'
6
6
  module Mindee
7
7
  module Product
8
8
  module FinancialDocument
9
- # Financial Document API version 1.9 page data.
9
+ # Financial Document API version 1.10 page data.
10
10
  class FinancialDocumentV1Page < Mindee::Parsing::Common::Page
11
11
  # @param prediction [Hash]
12
12
  def initialize(prediction)
@@ -36,24 +36,13 @@ module Mindee
36
36
  # @return [Hash]
37
37
  def printable_values
38
38
  printable = {}
39
- printable[:bban_bank_code] = format_for_display(@bban_bank_code, nil)
40
- printable[:bban_branch_code] = format_for_display(@bban_branch_code, nil)
41
- printable[:bban_key] = format_for_display(@bban_key, nil)
42
- printable[:bban_number] = format_for_display(@bban_number, nil)
39
+ printable[:bban_bank_code] = format_for_display(@bban_bank_code)
40
+ printable[:bban_branch_code] = format_for_display(@bban_branch_code)
41
+ printable[:bban_key] = format_for_display(@bban_key)
42
+ printable[:bban_number] = format_for_display(@bban_number)
43
43
  printable
44
44
  end
45
45
 
46
- # @return [String]
47
- def to_table_line
48
- printable = printable_values
49
- out_str = String.new
50
- out_str << format('| %- 10s', printable[:bban_bank_code])
51
- out_str << format('| %- 12s', printable[:bban_branch_code])
52
- out_str << format('| %- 4s', printable[:bban_key])
53
- out_str << format('| %- 15s', printable[:bban_number])
54
- out_str << '|'
55
- end
56
-
57
46
  # @return [String]
58
47
  def to_s
59
48
  printable = printable_values
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../parsing'
4
+ require_relative 'energy_bill_v1_document'
5
+ require_relative 'energy_bill_v1_page'
6
+
7
+ module Mindee
8
+ module Product
9
+ module FR
10
+ # Energy Bill module.
11
+ module EnergyBill
12
+ # Energy Bill API version 1 inference prediction.
13
+ class EnergyBillV1 < Mindee::Parsing::Common::Inference
14
+ @endpoint_name = 'energy_bill_fra'
15
+ @endpoint_version = '1'
16
+
17
+ # @param prediction [Hash]
18
+ def initialize(prediction)
19
+ super
20
+ @prediction = EnergyBillV1Document.new(prediction['prediction'], nil)
21
+ @pages = []
22
+ prediction['pages'].each do |page|
23
+ if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
24
+ @pages.push(EnergyBillV1Page.new(page))
25
+ end
26
+ end
27
+ end
28
+
29
+ class << self
30
+ # Name of the endpoint for this product.
31
+ # @return [String]
32
+ attr_reader :endpoint_name
33
+ # Version for this product.
34
+ # @return [String]
35
+ attr_reader :endpoint_version
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,235 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../parsing'
4
+ require_relative 'energy_bill_v1_energy_supplier'
5
+ require_relative 'energy_bill_v1_energy_consumer'
6
+ require_relative 'energy_bill_v1_subscription'
7
+ require_relative 'energy_bill_v1_energy_usage'
8
+ require_relative 'energy_bill_v1_taxes_and_contribution'
9
+ require_relative 'energy_bill_v1_meter_detail'
10
+
11
+ module Mindee
12
+ module Product
13
+ module FR
14
+ module EnergyBill
15
+ # Energy Bill API version 1.0 document data.
16
+ class EnergyBillV1Document < Mindee::Parsing::Common::Prediction
17
+ include Mindee::Parsing::Standard
18
+ # The unique identifier associated with a specific contract.
19
+ # @return [Mindee::Parsing::Standard::StringField]
20
+ attr_reader :contract_id
21
+ # The unique identifier assigned to each electricity or gas consumption point. It specifies the exact
22
+ # location where the energy is delivered.
23
+ # @return [Mindee::Parsing::Standard::StringField]
24
+ attr_reader :delivery_point
25
+ # The date by which the payment for the energy invoice is due.
26
+ # @return [Mindee::Parsing::Standard::DateField]
27
+ attr_reader :due_date
28
+ # The entity that consumes the energy.
29
+ # @return [Mindee::Product::FR::EnergyBill::EnergyBillV1EnergyConsumer]
30
+ attr_reader :energy_consumer
31
+ # The company that supplies the energy.
32
+ # @return [Mindee::Product::FR::EnergyBill::EnergyBillV1EnergySupplier]
33
+ attr_reader :energy_supplier
34
+ # Details of energy consumption.
35
+ # @return [Array<Mindee::Product::FR::EnergyBill::EnergyBillV1EnergyUsage>]
36
+ attr_reader :energy_usage
37
+ # The date when the energy invoice was issued.
38
+ # @return [Mindee::Parsing::Standard::DateField]
39
+ attr_reader :invoice_date
40
+ # The unique identifier of the energy invoice.
41
+ # @return [Mindee::Parsing::Standard::StringField]
42
+ attr_reader :invoice_number
43
+ # Information about the energy meter.
44
+ # @return [Mindee::Product::FR::EnergyBill::EnergyBillV1MeterDetail]
45
+ attr_reader :meter_details
46
+ # The subscription details fee for the energy service.
47
+ # @return [Array<Mindee::Product::FR::EnergyBill::EnergyBillV1Subscription>]
48
+ attr_reader :subscription
49
+ # Details of Taxes and Contributions.
50
+ # @return [Array<Mindee::Product::FR::EnergyBill::EnergyBillV1TaxesAndContribution>]
51
+ attr_reader :taxes_and_contributions
52
+ # The total amount to be paid for the energy invoice.
53
+ # @return [Mindee::Parsing::Standard::AmountField]
54
+ attr_reader :total_amount
55
+ # The total amount to be paid for the energy invoice before taxes.
56
+ # @return [Mindee::Parsing::Standard::AmountField]
57
+ attr_reader :total_before_taxes
58
+ # Total of taxes applied to the invoice.
59
+ # @return [Mindee::Parsing::Standard::AmountField]
60
+ attr_reader :total_taxes
61
+
62
+ # @param prediction [Hash]
63
+ # @param page_id [Integer, nil]
64
+ def initialize(prediction, page_id)
65
+ super()
66
+ @contract_id = StringField.new(prediction['contract_id'], page_id)
67
+ @delivery_point = StringField.new(prediction['delivery_point'], page_id)
68
+ @due_date = DateField.new(prediction['due_date'], page_id)
69
+ @energy_consumer = EnergyBillV1EnergyConsumer.new(prediction['energy_consumer'], page_id)
70
+ @energy_supplier = EnergyBillV1EnergySupplier.new(prediction['energy_supplier'], page_id)
71
+ @energy_usage = []
72
+ prediction['energy_usage'].each do |item|
73
+ @energy_usage.push(EnergyBillV1EnergyUsage.new(item, page_id))
74
+ end
75
+ @invoice_date = DateField.new(prediction['invoice_date'], page_id)
76
+ @invoice_number = StringField.new(prediction['invoice_number'], page_id)
77
+ @meter_details = EnergyBillV1MeterDetail.new(prediction['meter_details'], page_id)
78
+ @subscription = []
79
+ prediction['subscription'].each do |item|
80
+ @subscription.push(EnergyBillV1Subscription.new(item, page_id))
81
+ end
82
+ @taxes_and_contributions = []
83
+ prediction['taxes_and_contributions'].each do |item|
84
+ @taxes_and_contributions.push(EnergyBillV1TaxesAndContribution.new(item, page_id))
85
+ end
86
+ @total_amount = AmountField.new(prediction['total_amount'], page_id)
87
+ @total_before_taxes = AmountField.new(prediction['total_before_taxes'], page_id)
88
+ @total_taxes = AmountField.new(prediction['total_taxes'], page_id)
89
+ end
90
+
91
+ # @return [String]
92
+ def to_s
93
+ energy_supplier = @energy_supplier.to_s
94
+ energy_consumer = @energy_consumer.to_s
95
+ subscription = subscription_to_s
96
+ energy_usage = energy_usage_to_s
97
+ taxes_and_contributions = taxes_and_contributions_to_s
98
+ meter_details = @meter_details.to_s
99
+ out_str = String.new
100
+ out_str << "\n:Invoice Number: #{@invoice_number}".rstrip
101
+ out_str << "\n:Contract ID: #{@contract_id}".rstrip
102
+ out_str << "\n:Delivery Point: #{@delivery_point}".rstrip
103
+ out_str << "\n:Invoice Date: #{@invoice_date}".rstrip
104
+ out_str << "\n:Due Date: #{@due_date}".rstrip
105
+ out_str << "\n:Total Before Taxes: #{@total_before_taxes}".rstrip
106
+ out_str << "\n:Total Taxes: #{@total_taxes}".rstrip
107
+ out_str << "\n:Total Amount: #{@total_amount}".rstrip
108
+ out_str << "\n:Energy Supplier:"
109
+ out_str << energy_supplier
110
+ out_str << "\n:Energy Consumer:"
111
+ out_str << energy_consumer
112
+ out_str << "\n:Subscription:"
113
+ out_str << subscription
114
+ out_str << "\n:Energy Usage:"
115
+ out_str << energy_usage
116
+ out_str << "\n:Taxes and Contributions:"
117
+ out_str << taxes_and_contributions
118
+ out_str << "\n:Meter Details:"
119
+ out_str << meter_details
120
+ out_str[1..].to_s
121
+ end
122
+
123
+ private
124
+
125
+ # @param char [String]
126
+ # @return [String]
127
+ def subscription_separator(char)
128
+ out_str = String.new
129
+ out_str << ' '
130
+ out_str << "+#{char * 38}"
131
+ out_str << "+#{char * 12}"
132
+ out_str << "+#{char * 12}"
133
+ out_str << "+#{char * 10}"
134
+ out_str << "+#{char * 11}"
135
+ out_str << "+#{char * 12}"
136
+ out_str << '+'
137
+ out_str
138
+ end
139
+
140
+ # @return [String]
141
+ def subscription_to_s
142
+ return '' if @subscription.empty?
143
+
144
+ line_items = @subscription.map(&:to_table_line).join("\n#{subscription_separator('-')}\n ")
145
+ out_str = String.new
146
+ out_str << "\n#{subscription_separator('-')}"
147
+ out_str << "\n |"
148
+ out_str << ' Description |'
149
+ out_str << ' End Date |'
150
+ out_str << ' Start Date |'
151
+ out_str << ' Tax Rate |'
152
+ out_str << ' Total |'
153
+ out_str << ' Unit Price |'
154
+ out_str << "\n#{subscription_separator('=')}"
155
+ out_str << "\n #{line_items}"
156
+ out_str << "\n#{subscription_separator('-')}"
157
+ out_str
158
+ end
159
+
160
+ # @param char [String]
161
+ # @return [String]
162
+ def energy_usage_separator(char)
163
+ out_str = String.new
164
+ out_str << ' '
165
+ out_str << "+#{char * 38}"
166
+ out_str << "+#{char * 12}"
167
+ out_str << "+#{char * 12}"
168
+ out_str << "+#{char * 10}"
169
+ out_str << "+#{char * 11}"
170
+ out_str << "+#{char * 12}"
171
+ out_str << '+'
172
+ out_str
173
+ end
174
+
175
+ # @return [String]
176
+ def energy_usage_to_s
177
+ return '' if @energy_usage.empty?
178
+
179
+ line_items = @energy_usage.map(&:to_table_line).join("\n#{energy_usage_separator('-')}\n ")
180
+ out_str = String.new
181
+ out_str << "\n#{energy_usage_separator('-')}"
182
+ out_str << "\n |"
183
+ out_str << ' Description |'
184
+ out_str << ' End Date |'
185
+ out_str << ' Start Date |'
186
+ out_str << ' Tax Rate |'
187
+ out_str << ' Total |'
188
+ out_str << ' Unit Price |'
189
+ out_str << "\n#{energy_usage_separator('=')}"
190
+ out_str << "\n #{line_items}"
191
+ out_str << "\n#{energy_usage_separator('-')}"
192
+ out_str
193
+ end
194
+
195
+ # @param char [String]
196
+ # @return [String]
197
+ def taxes_and_contributions_separator(char)
198
+ out_str = String.new
199
+ out_str << ' '
200
+ out_str << "+#{char * 38}"
201
+ out_str << "+#{char * 12}"
202
+ out_str << "+#{char * 12}"
203
+ out_str << "+#{char * 10}"
204
+ out_str << "+#{char * 11}"
205
+ out_str << "+#{char * 12}"
206
+ out_str << '+'
207
+ out_str
208
+ end
209
+
210
+ # @return [String]
211
+ def taxes_and_contributions_to_s
212
+ return '' if @taxes_and_contributions.empty?
213
+
214
+ line_items = @taxes_and_contributions.map(&:to_table_line).join(
215
+ "\n#{taxes_and_contributions_separator('-')}\n "
216
+ )
217
+ out_str = String.new
218
+ out_str << "\n#{taxes_and_contributions_separator('-')}"
219
+ out_str << "\n |"
220
+ out_str << ' Description |'
221
+ out_str << ' End Date |'
222
+ out_str << ' Start Date |'
223
+ out_str << ' Tax Rate |'
224
+ out_str << ' Total |'
225
+ out_str << ' Unit Price |'
226
+ out_str << "\n#{taxes_and_contributions_separator('=')}"
227
+ out_str << "\n #{line_items}"
228
+ out_str << "\n#{taxes_and_contributions_separator('-')}"
229
+ out_str
230
+ end
231
+ end
232
+ end
233
+ end
234
+ end
235
+ end