mindee 2.2.1 → 3.1.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 (156) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +2 -0
  4. data/.yardopts +1 -0
  5. data/CHANGELOG.md +40 -0
  6. data/README.md +29 -16
  7. data/bin/mindee.rb +23 -26
  8. data/docs/code_samples/bank_account_details_v1.txt +10 -5
  9. data/docs/code_samples/bank_account_details_v2.txt +19 -0
  10. data/docs/code_samples/bank_check_v1.txt +10 -5
  11. data/docs/code_samples/carte_vitale_v1.txt +10 -5
  12. data/docs/code_samples/custom_v1.txt +19 -10
  13. data/docs/code_samples/default.txt +10 -2
  14. data/docs/code_samples/expense_receipts_v4.txt +10 -5
  15. data/docs/code_samples/expense_receipts_v5.txt +11 -6
  16. data/docs/code_samples/financial_document_v1.txt +10 -5
  17. data/docs/code_samples/idcard_fr_v1.txt +10 -5
  18. data/docs/code_samples/invoice_splitter_v1_async.txt +66 -0
  19. data/docs/code_samples/invoices_v4.txt +10 -5
  20. data/docs/code_samples/license_plates_v1.txt +10 -5
  21. data/docs/code_samples/passport_v1.txt +10 -5
  22. data/docs/code_samples/proof_of_address_v1.txt +10 -5
  23. data/docs/code_samples/us_driver_license_v1.txt +19 -0
  24. data/docs/ruby-api-builder.md +30 -31
  25. data/docs/ruby-getting-started.md +64 -23
  26. data/docs/ruby-invoice-ocr.md +70 -59
  27. data/docs/ruby-passport-ocr.md +49 -40
  28. data/docs/ruby-receipt-ocr.md +45 -32
  29. data/lib/mindee/client.rb +150 -148
  30. data/lib/mindee/geometry/min_max.rb +23 -0
  31. data/lib/mindee/geometry/point.rb +35 -0
  32. data/lib/mindee/geometry/polygon.rb +23 -0
  33. data/lib/mindee/geometry/quadrilateral.rb +45 -0
  34. data/lib/mindee/geometry/utils.rb +81 -0
  35. data/lib/mindee/geometry.rb +5 -116
  36. data/lib/mindee/http/endpoint.rb +115 -16
  37. data/lib/mindee/http.rb +3 -0
  38. data/lib/mindee/input/sources.rb +90 -73
  39. data/lib/mindee/parsing/common/api_response.rb +109 -0
  40. data/lib/mindee/parsing/common/document.rb +48 -0
  41. data/lib/mindee/parsing/common/error.rb +24 -0
  42. data/lib/mindee/parsing/common/inference.rb +43 -0
  43. data/lib/mindee/parsing/common/ocr/mvision_v1.rb +34 -0
  44. data/lib/mindee/parsing/common/ocr/ocr.rb +169 -0
  45. data/lib/mindee/parsing/common/ocr.rb +3 -0
  46. data/lib/mindee/parsing/common/orientation.rb +26 -0
  47. data/lib/mindee/parsing/common/page.rb +40 -0
  48. data/lib/mindee/parsing/common/prediction.rb +15 -0
  49. data/lib/mindee/parsing/common/product.rb +19 -0
  50. data/lib/mindee/parsing/common.rb +10 -0
  51. data/lib/mindee/parsing/custom/classification_field.rb +28 -0
  52. data/lib/mindee/parsing/custom/list_field.rb +76 -0
  53. data/lib/mindee/parsing/custom.rb +4 -0
  54. data/lib/mindee/parsing/standard/amount_field.rb +26 -0
  55. data/lib/mindee/parsing/standard/base_field.rb +104 -0
  56. data/lib/mindee/parsing/standard/classification_field.rb +16 -0
  57. data/lib/mindee/parsing/standard/company_registration_field.rb +21 -0
  58. data/lib/mindee/parsing/standard/date_field.rb +34 -0
  59. data/lib/mindee/parsing/standard/locale_field.rb +50 -0
  60. data/lib/mindee/parsing/standard/payment_details_field.rb +42 -0
  61. data/lib/mindee/parsing/standard/position_field.rb +47 -0
  62. data/lib/mindee/parsing/standard/tax_field.rb +108 -0
  63. data/lib/mindee/parsing/standard/text_field.rb +16 -0
  64. data/lib/mindee/parsing/standard.rb +12 -0
  65. data/lib/mindee/parsing.rb +3 -2
  66. data/lib/mindee/{input → pdf}/pdf_processing.rb +4 -32
  67. data/lib/mindee/pdf/pdf_tools.rb +34 -0
  68. data/lib/mindee/pdf.rb +3 -0
  69. data/lib/mindee/product/.rubocop.yml +5 -0
  70. data/lib/mindee/product/custom/custom_v1.rb +35 -0
  71. data/lib/mindee/product/custom/custom_v1_document.rb +60 -0
  72. data/lib/mindee/product/custom/custom_v1_page.rb +32 -0
  73. data/lib/mindee/product/eu/license_plate/license_plate_v1.rb +38 -0
  74. data/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb +37 -0
  75. data/lib/mindee/product/eu/license_plate/license_plate_v1_page.rb +34 -0
  76. data/lib/mindee/product/financial_document/financial_document_v1.rb +36 -0
  77. data/lib/mindee/product/financial_document/financial_document_v1_document.rb +202 -0
  78. data/lib/mindee/product/financial_document/financial_document_v1_line_item.rb +90 -0
  79. data/lib/mindee/product/financial_document/financial_document_v1_page.rb +32 -0
  80. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb +38 -0
  81. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb +43 -0
  82. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rb +34 -0
  83. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb +38 -0
  84. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb +71 -0
  85. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb +51 -0
  86. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb +34 -0
  87. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1.rb +38 -0
  88. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_document.rb +52 -0
  89. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_page.rb +34 -0
  90. data/lib/mindee/product/fr/id_card/id_card_v1.rb +38 -0
  91. data/lib/mindee/product/fr/id_card/id_card_v1_document.rb +82 -0
  92. data/lib/mindee/product/fr/id_card/id_card_v1_page.rb +48 -0
  93. data/lib/mindee/product/invoice/invoice_v4.rb +37 -0
  94. data/lib/mindee/product/invoice/invoice_v4_document.rb +212 -0
  95. data/lib/mindee/product/invoice/invoice_v4_line_item.rb +66 -0
  96. data/lib/mindee/product/invoice/invoice_v4_page.rb +32 -0
  97. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb +36 -0
  98. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +65 -0
  99. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb +32 -0
  100. data/lib/mindee/product/passport/passport_v1.rb +36 -0
  101. data/lib/mindee/{parsing/prediction/fr/id_card/id_card_v1.rb → product/passport/passport_v1_document.rb} +45 -45
  102. data/lib/mindee/product/passport/passport_v1_page.rb +32 -0
  103. data/lib/mindee/product/proof_of_address/proof_of_address_v1.rb +36 -0
  104. data/lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb +83 -0
  105. data/lib/mindee/product/proof_of_address/proof_of_address_v1_page.rb +32 -0
  106. data/lib/mindee/product/receipt/receipt_v4.rb +36 -0
  107. data/lib/mindee/product/receipt/receipt_v4_document.rb +86 -0
  108. data/lib/mindee/product/receipt/receipt_v4_page.rb +32 -0
  109. data/lib/mindee/product/receipt/receipt_v5.rb +36 -0
  110. data/lib/mindee/product/receipt/receipt_v5_document.rb +149 -0
  111. data/lib/mindee/product/receipt/receipt_v5_line_item.rb +69 -0
  112. data/lib/mindee/product/receipt/receipt_v5_page.rb +32 -0
  113. data/lib/mindee/product/us/bank_check/bank_check_v1.rb +38 -0
  114. data/lib/mindee/product/us/bank_check/bank_check_v1_document.rb +62 -0
  115. data/lib/mindee/product/us/bank_check/bank_check_v1_page.rb +57 -0
  116. data/lib/mindee/product/us/driver_license/driver_license_v1.rb +38 -0
  117. data/lib/mindee/product/us/driver_license/driver_license_v1_document.rb +113 -0
  118. data/lib/mindee/product/us/driver_license/driver_license_v1_page.rb +53 -0
  119. data/lib/mindee/product.rb +17 -0
  120. data/lib/mindee/version.rb +2 -1
  121. data/lib/mindee.rb +3 -1
  122. metadata +91 -38
  123. data/docs/code_samples/shipping_containers_v1.txt +0 -14
  124. data/lib/mindee/document_config.rb +0 -60
  125. data/lib/mindee/parsing/document.rb +0 -31
  126. data/lib/mindee/parsing/error.rb +0 -22
  127. data/lib/mindee/parsing/inference.rb +0 -53
  128. data/lib/mindee/parsing/page.rb +0 -46
  129. data/lib/mindee/parsing/prediction/base.rb +0 -30
  130. data/lib/mindee/parsing/prediction/common_fields/amount.rb +0 -21
  131. data/lib/mindee/parsing/prediction/common_fields/base.rb +0 -72
  132. data/lib/mindee/parsing/prediction/common_fields/company_registration.rb +0 -17
  133. data/lib/mindee/parsing/prediction/common_fields/date.rb +0 -30
  134. data/lib/mindee/parsing/prediction/common_fields/locale.rb +0 -45
  135. data/lib/mindee/parsing/prediction/common_fields/payment_details.rb +0 -33
  136. data/lib/mindee/parsing/prediction/common_fields/position.rb +0 -39
  137. data/lib/mindee/parsing/prediction/common_fields/tax.rb +0 -44
  138. data/lib/mindee/parsing/prediction/common_fields/text.rb +0 -12
  139. data/lib/mindee/parsing/prediction/common_fields.rb +0 -11
  140. data/lib/mindee/parsing/prediction/custom/custom_v1.rb +0 -58
  141. data/lib/mindee/parsing/prediction/custom/fields.rb +0 -91
  142. data/lib/mindee/parsing/prediction/eu/license_plate/license_plate_v1.rb +0 -34
  143. data/lib/mindee/parsing/prediction/financial_document/financial_document_v1.rb +0 -237
  144. data/lib/mindee/parsing/prediction/financial_document/financial_document_v1_line_item.rb +0 -58
  145. data/lib/mindee/parsing/prediction/fr/bank_account_details/bank_account_details_v1.rb +0 -40
  146. data/lib/mindee/parsing/prediction/fr/carte_vitale/carte_vitale_v1.rb +0 -49
  147. data/lib/mindee/parsing/prediction/invoice/invoice_v4.rb +0 -212
  148. data/lib/mindee/parsing/prediction/invoice/invoice_v4_line_item.rb +0 -58
  149. data/lib/mindee/parsing/prediction/passport/passport_v1.rb +0 -121
  150. data/lib/mindee/parsing/prediction/proof_of_address/proof_of_address_v1.rb +0 -80
  151. data/lib/mindee/parsing/prediction/receipt/receipt_v4.rb +0 -87
  152. data/lib/mindee/parsing/prediction/receipt/receipt_v5.rb +0 -136
  153. data/lib/mindee/parsing/prediction/receipt/receipt_v5_line_item.rb +0 -37
  154. data/lib/mindee/parsing/prediction/shipping_container/shipping_container_v1.rb +0 -38
  155. data/lib/mindee/parsing/prediction/us/bank_check/bank_check_v1.rb +0 -70
  156. data/lib/mindee/parsing/prediction.rb +0 -15
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'receipt_v5_line_item'
5
+
6
+ module Mindee
7
+ module Product
8
+ module Receipt
9
+ # Receipt V5 document prediction.
10
+ class ReceiptV5Document < Mindee::Parsing::Common::Prediction
11
+ include Mindee::Parsing::Standard
12
+ # The purchase category among predefined classes.
13
+ # @return [Mindee::Parsing::Standard::ClassificationField]
14
+ attr_reader :category
15
+ # The date the purchase was made.
16
+ # @return [Mindee::Parsing::Standard::DateField]
17
+ attr_reader :date
18
+ # One of: 'CREDIT CARD RECEIPT', 'EXPENSE RECEIPT'.
19
+ # @return [Mindee::Parsing::Standard::ClassificationField]
20
+ attr_reader :document_type
21
+ # List of line item details.
22
+ # @return [Array<Mindee::Product::Receipt::ReceiptV5LineItem>]
23
+ attr_reader :line_items
24
+ # The locale detected on the document.
25
+ # @return [Mindee::Parsing::Standard::Locale]
26
+ attr_reader :locale
27
+ # The purchase subcategory among predefined classes for transport and food.
28
+ # @return [Mindee::Parsing::Standard::ClassificationField]
29
+ attr_reader :subcategory
30
+ # The address of the supplier or merchant.
31
+ # @return [Mindee::Parsing::Standard::TextField]
32
+ attr_reader :supplier_address
33
+ # List of company registrations associated to the supplier.
34
+ # @return [Array<Mindee::Parsing::Standard::CompanyRegistration>]
35
+ attr_reader :supplier_company_registrations
36
+ # The name of the supplier or merchant.
37
+ # @return [Mindee::Parsing::Standard::TextField]
38
+ attr_reader :supplier_name
39
+ # The phone number of the supplier or merchant.
40
+ # @return [Mindee::Parsing::Standard::TextField]
41
+ attr_reader :supplier_phone_number
42
+ # List of tax lines information.
43
+ # @return [Mindee::Parsing::Standard::Taxes]
44
+ attr_reader :taxes
45
+ # The time the purchase was made.
46
+ # @return [Mindee::Parsing::Standard::TextField]
47
+ attr_reader :time
48
+ # The total amount of tip and gratuity.
49
+ # @return [Mindee::Parsing::Standard::AmountField]
50
+ attr_reader :tip
51
+ # The total amount paid: includes taxes, discounts, fees, tips, and gratuity.
52
+ # @return [Mindee::Parsing::Standard::AmountField]
53
+ attr_reader :total_amount
54
+ # The net amount paid: does not include taxes, fees, and discounts.
55
+ # @return [Mindee::Parsing::Standard::AmountField]
56
+ attr_reader :total_net
57
+ # The total amount of taxes.
58
+ # @return [Mindee::Parsing::Standard::AmountField]
59
+ attr_reader :total_tax
60
+
61
+ # @param prediction [Hash]
62
+ # @param page_id [Integer, nil]
63
+ def initialize(prediction, page_id)
64
+ super()
65
+ @category = ClassificationField.new(prediction['category'], page_id)
66
+ @date = DateField.new(prediction['date'], page_id)
67
+ @document_type = ClassificationField.new(prediction['document_type'], page_id)
68
+ @line_items = []
69
+ prediction['line_items'].each do |item|
70
+ @line_items.push(ReceiptV5LineItem.new(item, page_id))
71
+ end
72
+ @locale = Locale.new(prediction['locale'], page_id)
73
+ @subcategory = ClassificationField.new(prediction['subcategory'], page_id)
74
+ @supplier_address = TextField.new(prediction['supplier_address'], page_id)
75
+ @supplier_company_registrations = []
76
+ prediction['supplier_company_registrations'].each do |item|
77
+ @supplier_company_registrations.push(CompanyRegistration.new(item, page_id))
78
+ end
79
+ @supplier_name = TextField.new(prediction['supplier_name'], page_id)
80
+ @supplier_phone_number = TextField.new(prediction['supplier_phone_number'], page_id)
81
+ @taxes = Taxes.new(prediction['taxes'], page_id)
82
+ @time = TextField.new(prediction['time'], page_id)
83
+ @tip = AmountField.new(prediction['tip'], page_id)
84
+ @total_amount = AmountField.new(prediction['total_amount'], page_id)
85
+ @total_net = AmountField.new(prediction['total_net'], page_id)
86
+ @total_tax = AmountField.new(prediction['total_tax'], page_id)
87
+ end
88
+
89
+ # @return [String]
90
+ def to_s
91
+ supplier_company_registrations = @supplier_company_registrations.join("\n #{' ' * 32}")
92
+ line_items = line_items_to_s
93
+ out_str = String.new
94
+ out_str << "\n:Expense Locale: #{@locale}".rstrip
95
+ out_str << "\n:Purchase Category: #{@category}".rstrip
96
+ out_str << "\n:Purchase Subcategory: #{@subcategory}".rstrip
97
+ out_str << "\n:Document Type: #{@document_type}".rstrip
98
+ out_str << "\n:Purchase Date: #{@date}".rstrip
99
+ out_str << "\n:Purchase Time: #{@time}".rstrip
100
+ out_str << "\n:Total Amount: #{@total_amount}".rstrip
101
+ out_str << "\n:Total Net: #{@total_net}".rstrip
102
+ out_str << "\n:Total Tax: #{@total_tax}".rstrip
103
+ out_str << "\n:Tip and Gratuity: #{@tip}".rstrip
104
+ out_str << "\n:Taxes:#{@taxes}".rstrip
105
+ out_str << "\n:Supplier Name: #{@supplier_name}".rstrip
106
+ out_str << "\n:Supplier Company Registrations: #{supplier_company_registrations}".rstrip
107
+ out_str << "\n:Supplier Address: #{@supplier_address}".rstrip
108
+ out_str << "\n:Supplier Phone Number: #{@supplier_phone_number}".rstrip
109
+ out_str << "\n:Line Items:"
110
+ out_str << line_items
111
+ out_str[1..].to_s
112
+ end
113
+
114
+ private
115
+
116
+ # @param char [String]
117
+ # @return [String]
118
+ def line_items_separator(char)
119
+ out_str = String.new
120
+ out_str << ' '
121
+ out_str << "+#{char * 38}"
122
+ out_str << "+#{char * 10}"
123
+ out_str << "+#{char * 14}"
124
+ out_str << "+#{char * 12}"
125
+ out_str << '+'
126
+ out_str
127
+ end
128
+
129
+ # @return [String]
130
+ def line_items_to_s
131
+ return '' if @line_items.empty?
132
+
133
+ line_items = @line_items.map(&:to_table_line).join("\n#{line_items_separator('-')}\n ")
134
+ out_str = String.new
135
+ out_str << "\n#{line_items_separator('-')}"
136
+ out_str << "\n |"
137
+ out_str << ' Description |'
138
+ out_str << ' Quantity |'
139
+ out_str << ' Total Amount |'
140
+ out_str << ' Unit Price |'
141
+ out_str << "\n#{line_items_separator('=')}"
142
+ out_str << "\n #{line_items}"
143
+ out_str << "\n#{line_items_separator('-')}"
144
+ out_str
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module Receipt
8
+ # List of line item details.
9
+ class ReceiptV5LineItem < Mindee::Parsing::Standard::FeatureField
10
+ include Mindee::Parsing::Standard
11
+ # The item description.
12
+ # @return [String]
13
+ attr_reader :description
14
+ # The item quantity.
15
+ # @return [Float]
16
+ attr_reader :quantity
17
+ # The item total amount.
18
+ # @return [Float]
19
+ attr_reader :total_amount
20
+ # The item unit price.
21
+ # @return [Float]
22
+ attr_reader :unit_price
23
+
24
+ # @param prediction [Hash]
25
+ # @param page_id [Integer, nil]
26
+ def initialize(prediction, page_id)
27
+ super(prediction, page_id)
28
+ @description = prediction['description']
29
+ @quantity = prediction['quantity']
30
+ @total_amount = prediction['total_amount']
31
+ @unit_price = prediction['unit_price']
32
+ @page_id = page_id
33
+ end
34
+
35
+ # @return [Hash]
36
+ def printable_values
37
+ printable = {}
38
+ printable[:description] = format_for_display(@description, 36)
39
+ printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity)
40
+ printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount)
41
+ printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price)
42
+ printable
43
+ end
44
+
45
+ # @return [String]
46
+ def to_table_line
47
+ printable = printable_values
48
+ out_str = String.new
49
+ out_str << format('| %- 37s', printable[:description])
50
+ out_str << format('| %- 9s', printable[:quantity])
51
+ out_str << format('| %- 13s', printable[:total_amount])
52
+ out_str << format('| %- 11s', printable[:unit_price])
53
+ out_str << '|'
54
+ end
55
+
56
+ # @return [String]
57
+ def to_s
58
+ printable = printable_values
59
+ out_str = String.new
60
+ out_str << "\n :Description: #{printable[:description]}"
61
+ out_str << "\n :Quantity: #{printable[:quantity]}"
62
+ out_str << "\n :Total Amount: #{printable[:total_amount]}"
63
+ out_str << "\n :Unit Price: #{printable[:unit_price]}"
64
+ out_str
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'receipt_v5_document'
5
+
6
+ module Mindee
7
+ module Product
8
+ module Receipt
9
+ # Receipt V5 page.
10
+ class ReceiptV5Page < Mindee::Parsing::Common::Page
11
+ # @param prediction [Hash]
12
+ def initialize(prediction)
13
+ super(prediction)
14
+ @prediction = ReceiptV5PagePrediction.new(
15
+ prediction['prediction'],
16
+ prediction['id']
17
+ )
18
+ end
19
+ end
20
+
21
+ # Receipt V5 page prediction.
22
+ class ReceiptV5PagePrediction < ReceiptV5Document
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,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../parsing'
4
+ require_relative 'bank_check_v1_document'
5
+ require_relative 'bank_check_v1_page'
6
+
7
+ module Mindee
8
+ module Product
9
+ module US
10
+ module BankCheck
11
+ # Bank Check V1 prediction inference.
12
+ class BankCheckV1 < Mindee::Parsing::Common::Inference
13
+ @endpoint_name = 'bank_check'
14
+ @endpoint_version = '1'
15
+
16
+ # @param prediction [Hash]
17
+ def initialize(prediction)
18
+ super
19
+ @prediction = BankCheckV1Document.new(prediction['prediction'], nil)
20
+ @pages = []
21
+ prediction['pages'].each do |page|
22
+ @pages.push(BankCheckV1Page.new(page))
23
+ end
24
+ end
25
+
26
+ class << self
27
+ # Name of the endpoint for this product.
28
+ # @return [String]
29
+ attr_reader :endpoint_name
30
+ # Version for this product.
31
+ # @return [String]
32
+ attr_reader :endpoint_version
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module US
8
+ module BankCheck
9
+ # Bank Check V1 document prediction.
10
+ class BankCheckV1Document < Mindee::Parsing::Common::Prediction
11
+ include Mindee::Parsing::Standard
12
+ # The check payer's account number.
13
+ # @return [Mindee::Parsing::Standard::TextField]
14
+ attr_reader :account_number
15
+ # The amount of the check.
16
+ # @return [Mindee::Parsing::Standard::AmountField]
17
+ attr_reader :amount
18
+ # The issuer's check number.
19
+ # @return [Mindee::Parsing::Standard::TextField]
20
+ attr_reader :check_number
21
+ # The date the check was issued.
22
+ # @return [Mindee::Parsing::Standard::DateField]
23
+ attr_reader :date
24
+ # List of the check's payees (recipients).
25
+ # @return [Array<Mindee::Parsing::Standard::TextField>]
26
+ attr_reader :payees
27
+ # The check issuer's routing number.
28
+ # @return [Mindee::Parsing::Standard::TextField]
29
+ attr_reader :routing_number
30
+
31
+ # @param prediction [Hash]
32
+ # @param page_id [Integer, nil]
33
+ def initialize(prediction, page_id)
34
+ super()
35
+ @account_number = TextField.new(prediction['account_number'], page_id)
36
+ @amount = AmountField.new(prediction['amount'], page_id)
37
+ @check_number = TextField.new(prediction['check_number'], page_id)
38
+ @date = DateField.new(prediction['date'], page_id)
39
+ @payees = []
40
+ prediction['payees'].each do |item|
41
+ @payees.push(TextField.new(item, page_id))
42
+ end
43
+ @routing_number = TextField.new(prediction['routing_number'], page_id)
44
+ end
45
+
46
+ # @return [String]
47
+ def to_s
48
+ payees = @payees.join("\n #{' ' * 8}")
49
+ out_str = String.new
50
+ out_str << "\n:Check Issue Date: #{@date}".rstrip
51
+ out_str << "\n:Amount: #{@amount}".rstrip
52
+ out_str << "\n:Payees: #{payees}".rstrip
53
+ out_str << "\n:Routing Number: #{@routing_number}".rstrip
54
+ out_str << "\n:Account Number: #{@account_number}".rstrip
55
+ out_str << "\n:Check Number: #{@check_number}".rstrip
56
+ out_str[1..].to_s
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../parsing'
4
+ require_relative 'bank_check_v1_document'
5
+
6
+ module Mindee
7
+ module Product
8
+ module US
9
+ module BankCheck
10
+ # Bank Check V1 page.
11
+ class BankCheckV1Page < Mindee::Parsing::Common::Page
12
+ # @param prediction [Hash]
13
+ def initialize(prediction)
14
+ super(prediction)
15
+ @prediction = BankCheckV1PagePrediction.new(
16
+ prediction['prediction'],
17
+ prediction['id']
18
+ )
19
+ end
20
+ end
21
+
22
+ # Bank Check V1 page prediction.
23
+ class BankCheckV1PagePrediction < BankCheckV1Document
24
+ include Mindee::Parsing::Standard
25
+
26
+ # The position of the check on the document.
27
+ # @return [Mindee::Parsing::Standard::PositionField]
28
+ attr_reader :check_position
29
+ # List of signature positions
30
+ # @return [Array<Mindee::Parsing::Standard::PositionField>]
31
+ attr_reader :signatures_positions
32
+
33
+ # @param prediction [Hash]
34
+ # @param page_id [Integer, nil]
35
+ def initialize(prediction, page_id)
36
+ @check_position = PositionField.new(prediction['check_position'], page_id)
37
+ @signatures_positions = []
38
+ prediction['signatures_positions'].each do |item|
39
+ @signatures_positions.push(PositionField.new(item, page_id))
40
+ end
41
+ super(prediction, page_id)
42
+ end
43
+
44
+ # @return [String]
45
+ def to_s
46
+ signatures_positions = @signatures_positions.join("\n #{' ' * 21}")
47
+ out_str = String.new
48
+ out_str << "\n:Check Position: #{@check_position}".rstrip
49
+ out_str << "\n:Signature Positions: #{signatures_positions}".rstrip
50
+ out_str << "\n#{super}"
51
+ out_str
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../parsing'
4
+ require_relative 'driver_license_v1_document'
5
+ require_relative 'driver_license_v1_page'
6
+
7
+ module Mindee
8
+ module Product
9
+ module US
10
+ module DriverLicense
11
+ # Driver License V1 prediction inference.
12
+ class DriverLicenseV1 < Mindee::Parsing::Common::Inference
13
+ @endpoint_name = 'us_driver_license'
14
+ @endpoint_version = '1'
15
+
16
+ # @param prediction [Hash]
17
+ def initialize(prediction)
18
+ super
19
+ @prediction = DriverLicenseV1Document.new(prediction['prediction'], nil)
20
+ @pages = []
21
+ prediction['pages'].each do |page|
22
+ @pages.push(DriverLicenseV1Page.new(page))
23
+ end
24
+ end
25
+
26
+ class << self
27
+ # Name of the endpoint for this product.
28
+ # @return [String]
29
+ attr_reader :endpoint_name
30
+ # Version for this product.
31
+ # @return [String]
32
+ attr_reader :endpoint_version
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module US
8
+ module DriverLicense
9
+ # Driver License V1 document prediction.
10
+ class DriverLicenseV1Document < Mindee::Parsing::Common::Prediction
11
+ include Mindee::Parsing::Standard
12
+ # US driver license holders address
13
+ # @return [Mindee::Parsing::Standard::TextField]
14
+ attr_reader :address
15
+ # US driver license holders date of birth
16
+ # @return [Mindee::Parsing::Standard::DateField]
17
+ attr_reader :date_of_birth
18
+ # Document Discriminator Number of the US Driver License
19
+ # @return [Mindee::Parsing::Standard::TextField]
20
+ attr_reader :dd_number
21
+ # US driver license holders class
22
+ # @return [Mindee::Parsing::Standard::TextField]
23
+ attr_reader :dl_class
24
+ # ID number of the US Driver License.
25
+ # @return [Mindee::Parsing::Standard::TextField]
26
+ attr_reader :driver_license_id
27
+ # US driver license holders endorsements
28
+ # @return [Mindee::Parsing::Standard::TextField]
29
+ attr_reader :endorsements
30
+ # Date on which the documents expires.
31
+ # @return [Mindee::Parsing::Standard::DateField]
32
+ attr_reader :expiry_date
33
+ # US driver license holders eye colour
34
+ # @return [Mindee::Parsing::Standard::TextField]
35
+ attr_reader :eye_color
36
+ # US driver license holders first name(s)
37
+ # @return [Mindee::Parsing::Standard::TextField]
38
+ attr_reader :first_name
39
+ # US driver license holders hair colour
40
+ # @return [Mindee::Parsing::Standard::TextField]
41
+ attr_reader :hair_color
42
+ # US driver license holders hight
43
+ # @return [Mindee::Parsing::Standard::TextField]
44
+ attr_reader :height
45
+ # Date on which the documents was issued.
46
+ # @return [Mindee::Parsing::Standard::DateField]
47
+ attr_reader :issued_date
48
+ # US driver license holders last name
49
+ # @return [Mindee::Parsing::Standard::TextField]
50
+ attr_reader :last_name
51
+ # US driver license holders restrictions
52
+ # @return [Mindee::Parsing::Standard::TextField]
53
+ attr_reader :restrictions
54
+ # US driver license holders gender
55
+ # @return [Mindee::Parsing::Standard::TextField]
56
+ attr_reader :sex
57
+ # US State
58
+ # @return [Mindee::Parsing::Standard::TextField]
59
+ attr_reader :state
60
+ # US driver license holders weight
61
+ # @return [Mindee::Parsing::Standard::TextField]
62
+ attr_reader :weight
63
+
64
+ # @param prediction [Hash]
65
+ # @param page_id [Integer, nil]
66
+ def initialize(prediction, page_id)
67
+ super()
68
+ @address = TextField.new(prediction['address'], page_id)
69
+ @date_of_birth = DateField.new(prediction['date_of_birth'], page_id)
70
+ @dd_number = TextField.new(prediction['dd_number'], page_id)
71
+ @dl_class = TextField.new(prediction['dl_class'], page_id)
72
+ @driver_license_id = TextField.new(prediction['driver_license_id'], page_id)
73
+ @endorsements = TextField.new(prediction['endorsements'], page_id)
74
+ @expiry_date = DateField.new(prediction['expiry_date'], page_id)
75
+ @eye_color = TextField.new(prediction['eye_color'], page_id)
76
+ @first_name = TextField.new(prediction['first_name'], page_id)
77
+ @hair_color = TextField.new(prediction['hair_color'], page_id)
78
+ @height = TextField.new(prediction['height'], page_id)
79
+ @issued_date = DateField.new(prediction['issued_date'], page_id)
80
+ @last_name = TextField.new(prediction['last_name'], page_id)
81
+ @restrictions = TextField.new(prediction['restrictions'], page_id)
82
+ @sex = TextField.new(prediction['sex'], page_id)
83
+ @state = TextField.new(prediction['state'], page_id)
84
+ @weight = TextField.new(prediction['weight'], page_id)
85
+ end
86
+
87
+ # @return [String]
88
+ def to_s
89
+ out_str = String.new
90
+ out_str << "\n:State: #{@state}".rstrip
91
+ out_str << "\n:Driver License ID: #{@driver_license_id}".rstrip
92
+ out_str << "\n:Expiry Date: #{@expiry_date}".rstrip
93
+ out_str << "\n:Date Of Issue: #{@issued_date}".rstrip
94
+ out_str << "\n:Last Name: #{@last_name}".rstrip
95
+ out_str << "\n:First Name: #{@first_name}".rstrip
96
+ out_str << "\n:Address: #{@address}".rstrip
97
+ out_str << "\n:Date Of Birth: #{@date_of_birth}".rstrip
98
+ out_str << "\n:Restrictions: #{@restrictions}".rstrip
99
+ out_str << "\n:Endorsements: #{@endorsements}".rstrip
100
+ out_str << "\n:Driver License Class: #{@dl_class}".rstrip
101
+ out_str << "\n:Sex: #{@sex}".rstrip
102
+ out_str << "\n:Height: #{@height}".rstrip
103
+ out_str << "\n:Weight: #{@weight}".rstrip
104
+ out_str << "\n:Hair Color: #{@hair_color}".rstrip
105
+ out_str << "\n:Eye Color: #{@eye_color}".rstrip
106
+ out_str << "\n:Document Discriminator: #{@dd_number}".rstrip
107
+ out_str[1..].to_s
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../parsing'
4
+ require_relative 'driver_license_v1_document'
5
+
6
+ module Mindee
7
+ module Product
8
+ module US
9
+ module DriverLicense
10
+ # Driver License V1 page.
11
+ class DriverLicenseV1Page < Mindee::Parsing::Common::Page
12
+ # @param prediction [Hash]
13
+ def initialize(prediction)
14
+ super(prediction)
15
+ @prediction = DriverLicenseV1PagePrediction.new(
16
+ prediction['prediction'],
17
+ prediction['id']
18
+ )
19
+ end
20
+ end
21
+
22
+ # Driver License V1 page prediction.
23
+ class DriverLicenseV1PagePrediction < DriverLicenseV1Document
24
+ include Mindee::Parsing::Standard
25
+
26
+ # Has a photo of the US driver license holder
27
+ # @return [Mindee::Parsing::Standard::PositionField]
28
+ attr_reader :photo
29
+ # Has a signature of the US driver license holder
30
+ # @return [Mindee::Parsing::Standard::PositionField]
31
+ attr_reader :signature
32
+
33
+ # @param prediction [Hash]
34
+ # @param page_id [Integer, nil]
35
+ def initialize(prediction, page_id)
36
+ @photo = PositionField.new(prediction['photo'], page_id)
37
+ @signature = PositionField.new(prediction['signature'], page_id)
38
+ super(prediction, page_id)
39
+ end
40
+
41
+ # @return [String]
42
+ def to_s
43
+ out_str = String.new
44
+ out_str << "\n:Photo: #{@photo}".rstrip
45
+ out_str << "\n:Signature: #{@signature}".rstrip
46
+ out_str << "\n#{super}"
47
+ out_str
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'product/custom/custom_v1'
4
+ require_relative 'product/proof_of_address/proof_of_address_v1'
5
+ require_relative 'product/financial_document/financial_document_v1'
6
+ require_relative 'product/invoice/invoice_v4'
7
+ require_relative 'product/passport/passport_v1'
8
+ require_relative 'product/receipt/receipt_v4'
9
+ require_relative 'product/receipt/receipt_v5'
10
+ require_relative 'product/eu/license_plate/license_plate_v1'
11
+ require_relative 'product/fr/bank_account_details/bank_account_details_v1'
12
+ require_relative 'product/fr/bank_account_details/bank_account_details_v2'
13
+ require_relative 'product/fr/carte_vitale/carte_vitale_v1'
14
+ require_relative 'product/fr/id_card/id_card_v1'
15
+ require_relative 'product/invoice_splitter/invoice_splitter_v1'
16
+ require_relative 'product/us/bank_check/bank_check_v1'
17
+ require_relative 'product/us/driver_license/driver_license_v1'
@@ -2,8 +2,9 @@
2
2
 
3
3
  # Mindee
4
4
  module Mindee
5
- VERSION = '2.2.1'
5
+ VERSION = '3.1.0'
6
6
 
7
+ # @return [String]
7
8
  def self.find_platform
8
9
  host = RbConfig::CONFIG['host_os']
9
10
  platforms = {
data/lib/mindee.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  require 'mindee/client'
4
4
 
5
5
  module Mindee
6
- class Error < StandardError
6
+ module HTTP
7
+ class HttpError < StandardError
8
+ end
7
9
  end
8
10
  end