mindee 3.2.0 → 3.3.1

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +1 -0
  4. data/CHANGELOG.md +17 -0
  5. data/bin/mindee.rb +1 -1
  6. data/docs/bank_account_details_v2.md +1 -1
  7. data/docs/bank_check_v1.md +5 -2
  8. data/docs/barcode_reader_v1.md +3 -3
  9. data/docs/carte_grise_v1.md +454 -0
  10. data/docs/carte_vitale_v1.md +1 -1
  11. data/docs/code_samples/carte_grise_v1.txt +19 -0
  12. data/docs/cropper_v1.md +6 -3
  13. data/docs/custom_v1.md +9 -1
  14. data/docs/expense_receipts_v5.md +3 -3
  15. data/docs/financial_document_v1.md +11 -8
  16. data/docs/idcard_fr_v2.md +1 -1
  17. data/docs/invoices_v4.md +73 -101
  18. data/docs/license_plates_v1.md +1 -1
  19. data/docs/multi_receipts_detector_v1.md +6 -3
  20. data/docs/passport_v1.md +1 -1
  21. data/docs/proof_of_address_v1.md +1 -1
  22. data/docs/us_driver_license_v1.md +1 -1
  23. data/docs/us_w9_v1.md +4 -4
  24. data/lib/mindee/client.rb +15 -10
  25. data/lib/mindee/http/endpoint.rb +5 -1
  26. data/lib/mindee/http/error.rb +1 -1
  27. data/lib/mindee/parsing/common/api_response.rb +3 -2
  28. data/lib/mindee/parsing/common/document.rb +4 -1
  29. data/lib/mindee/parsing/custom/list_field.rb +7 -5
  30. data/lib/mindee/parsing/standard/base_field.rb +1 -1
  31. data/lib/mindee/product/financial_document/financial_document_v1_document.rb +2 -2
  32. data/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb +39 -0
  33. data/lib/mindee/product/fr/carte_grise/carte_grise_v1_document.rb +235 -0
  34. data/lib/mindee/product/fr/carte_grise/carte_grise_v1_page.rb +34 -0
  35. data/lib/mindee/product/invoice/invoice_v4.rb +1 -2
  36. data/lib/mindee/product/invoice/invoice_v4_document.rb +105 -145
  37. data/lib/mindee/product/invoice/invoice_v4_line_item.rb +54 -30
  38. data/lib/mindee/product/us/w9/w9_v1.rb +2 -2
  39. data/lib/mindee/product/us/w9/w9_v1_document.rb +1 -1
  40. data/lib/mindee/product/us/w9/w9_v1_page.rb +2 -2
  41. data/lib/mindee/product.rb +1 -0
  42. data/lib/mindee/version.rb +1 -1
  43. data/lib/mindee.rb +0 -3
  44. metadata +7 -2
@@ -58,11 +58,11 @@ Prediction
58
58
  | | TAX | | 3.34 |
59
59
  +---------------+--------+----------+---------------+
60
60
  :Supplier Payment Details:
61
- :Supplier name: LOGANS
61
+ :Supplier Name: LOGANS
62
62
  :Supplier Company Registrations:
63
63
  :Supplier Address: 2513 s stemmons freeway lewisville tx 75067
64
64
  :Supplier Phone Number: 9724596042
65
- :Customer name:
65
+ :Customer Name:
66
66
  :Customer Company Registrations:
67
67
  :Customer Address:
68
68
  :Document Type: EXPENSE RECEIPT
@@ -97,11 +97,11 @@ Page 0
97
97
  | | TAX | | 3.34 |
98
98
  +---------------+--------+----------+---------------+
99
99
  :Supplier Payment Details:
100
- :Supplier name: LOGANS
100
+ :Supplier Name: LOGANS
101
101
  :Supplier Company Registrations:
102
102
  :Supplier Address: 2513 s stemmons freeway lewisville tx 75067
103
103
  :Supplier Phone Number: 9724596042
104
- :Customer name:
104
+ :Customer Name:
105
105
  :Customer Company Registrations:
106
106
  :Customer Address:
107
107
  :Document Type: EXPENSE RECEIPT
@@ -131,7 +131,7 @@ A typical `Field` object will have the following attributes:
131
131
  * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
132
132
  * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
133
133
  * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
134
- * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
134
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
135
135
 
136
136
 
137
137
  Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
@@ -179,7 +179,7 @@ The text field `StringField` only has one constraint: it's **value** is a `Strin
179
179
  #### Tax
180
180
  Aside from the basic `Field` attributes, the tax field `TaxField` also implements the following:
181
181
 
182
- * **rate** (`Float`): the tax rate applied to an item can be undefined. Expressed as a percentage. Can be `nil`.
182
+ * **rate** (`Float`): the tax rate applied to an item can be expressed as a percentage. Can be `nil`.
183
183
  * **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`.
184
184
  * **base** (`Float`): base amount used for the tax. Can be `nil`.
185
185
 
@@ -313,7 +313,7 @@ for supplier_company_registrations_elem in result.document.inference.prediction.
313
313
  end
314
314
  ```
315
315
 
316
- ## Supplier name
316
+ ## Supplier Name
317
317
  **supplier_name** ([StringField](#string-field)): The name of the supplier or merchant.
318
318
 
319
319
  ```rb
@@ -326,6 +326,9 @@ puts result.document.inference.prediction.supplier_name.value
326
326
  ```rb
327
327
  for supplier_payment_details_elem in result.document.inference.prediction.supplier_payment_details do
328
328
  puts supplier_payment_details_elem.value
329
+ puts supplier_payment_details_elem.rate
330
+ puts supplier_payment_details_elem.code
331
+ puts supplier_payment_details_elem.basis
329
332
  end
330
333
  ```
331
334
 
@@ -341,7 +344,7 @@ puts result.document.inference.prediction.supplier_phone_number.value
341
344
 
342
345
  ```rb
343
346
  for taxes_elem in result.document.inference.prediction.taxes do
344
- puts taxes_elem.to_s
347
+ puts taxes_elem.value
345
348
  end
346
349
  ```
347
350
 
data/docs/idcard_fr_v2.md CHANGED
@@ -99,7 +99,7 @@ A typical `Field` object will have the following attributes:
99
99
  * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
100
100
  * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
101
101
  * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
102
- * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
102
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
103
103
 
104
104
 
105
105
  Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
data/docs/invoices_v4.md CHANGED
@@ -34,123 +34,84 @@ puts result.document
34
34
  ########
35
35
  Document
36
36
  ########
37
- :Mindee ID: 656c2ec1-0920-4556-9bc2-772162bc698a
38
- :Filename: invoice.pdf
37
+ :Mindee ID: 16bd8752-8c4d-450f-8213-f33b2097504c
38
+ :Filename: default_sample.jpg
39
39
 
40
40
  Inference
41
41
  #########
42
- :Product: mindee/invoices v4.1
42
+ :Product: mindee/invoices v4.2
43
43
  :Rotation applied: Yes
44
44
 
45
45
  Prediction
46
46
  ==========
47
- :Locale: fr; fr; EUR;
48
- :Document type: INVOICE
49
- :Invoice number: 0042004801351
50
- :Reference numbers: AD29094
51
- :Invoice date: 2020-02-17
52
- :Invoice due date: 2020-02-17
53
- :Supplier name: TURNPIKE DESIGNS CO.
54
- :Supplier address: 156 University Ave, Toronto ON, Canada M5H 2H7
55
- :Supplier company registrations: 501124705; FR33501124705
56
- :Supplier payment details: FR7640254025476501124705368;
57
- :Customer name: JIRO DOI
58
- :Customer address: 1954 Bloon Street West Toronto, ON, M6P 3K9 Canada
59
- :Customer company registrations: FR00000000000; 111222333
47
+ :Locale: en; en; CAD;
48
+ :Invoice Number: 14
49
+ :Reference Numbers: AD29094
50
+ :Purchase Date: 2018-09-25
51
+ :Due Date: 2018-09-25
52
+ :Total Net:
53
+ :Total Amount: 2608.20
60
54
  :Taxes:
61
55
  +---------------+--------+----------+---------------+
62
56
  | Base | Code | Rate (%) | Amount |
63
57
  +===============+========+==========+===============+
64
- | | | 20.00 | 97.98 |
58
+ | | | 8.00 | 193.20 |
65
59
  +---------------+--------+----------+---------------+
66
- :Total net: 489.97
67
- :Total tax: 97.98
68
- :Total amount: 587.95
60
+ :Supplier Payment Details:
61
+ :Supplier Name: TURNPIKE DESIGNS CO.
62
+ :Supplier Company Registrations:
63
+ :Supplier Address: 156 University Ave, Toronto ON, Canada M5H 2H7
64
+ :Customer Name: JIRO DOI
65
+ :Customer Company Registrations:
66
+ :Customer Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada
67
+ :Document Type: INVOICE
69
68
  :Line Items:
70
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
71
- | Code | QTY | Price | Amount | Tax (Rate) | Description |
72
- +======================+=========+=========+==========+==================+======================================+
73
- | | | | 4.31 | (2.10%) | PQ20 ETIQ ULTRA RESIS METAXXDC |
74
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
75
- | | 1.00 | 65.00 | 75.00 | 10.00 | Platinum web hosting package Down... |
76
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
77
- | XXX81125600010 | 1.00 | 250.01 | 275.51 | 25.50 (10.20%) | a long string describing the item |
78
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
79
- | ABC456 | 200.30 | 8.101 | 1622.63 | 121.70 (7.50%) | Liquid perfection |
80
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
81
- | | | | | | CARTOUCHE L NR BROTHER TN247BK |
82
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
69
+ +--------------------------------------+--------------+----------+------------+--------------+--------------+------------+
70
+ | Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit Price |
71
+ +======================================+==============+==========+============+==============+==============+============+
72
+ | Platinum web hosting package Down... | | 1.00 | | | 65.00 | 65.00 |
73
+ +--------------------------------------+--------------+----------+------------+--------------+--------------+------------+
74
+ | 2 page website design Includes ba... | | 3.00 | | | 2100.00 | 2100.00 |
75
+ +--------------------------------------+--------------+----------+------------+--------------+--------------+------------+
76
+ | Mobile designs Includes responsiv... | | 1.00 | | | 250.00 | 250.00 |
77
+ +--------------------------------------+--------------+----------+------------+--------------+--------------+------------+
83
78
 
84
79
  Page Predictions
85
80
  ================
86
81
 
87
82
  Page 0
88
83
  ------
89
- :Locale: fr; fr; EUR;
90
- :Document type: INVOICE
91
- :Invoice number: 0042004801351
92
- :Reference numbers:
93
- :Invoice date: 2020-02-17
94
- :Invoice due date: 2020-02-17
95
- :Supplier name:
96
- :Supplier address:
97
- :Supplier company registrations: 501124705; FR33501124705
98
- :Supplier payment details: FR7640254025476501124705368;
99
- :Customer name:
100
- :Customer address:
101
- :Customer company registrations:
102
- :Taxes:
103
- +---------------+--------+----------+---------------+
104
- | Base | Code | Rate (%) | Amount |
105
- +===============+========+==========+===============+
106
- | | | 20.00 | 97.98 |
107
- +---------------+--------+----------+---------------+
108
- :Total net: 489.97
109
- :Total tax: 97.98
110
- :Total amount: 587.95
111
- :Line Items:
112
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
113
- | Code | QTY | Price | Amount | Tax (Rate) | Description |
114
- +======================+=========+=========+==========+==================+======================================+
115
- | | | | 4.31 | (2.10%) | PQ20 ETIQ ULTRA RESIS METAXXDC |
116
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
117
- | | 1.00 | 65.00 | 75.00 | 10.00 | Platinum web hosting package Down... |
118
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
119
-
120
- Page 1
121
- ------
122
- :Locale: fr; fr; EUR;
123
- :Document type: INVOICE
124
- :Invoice number:
125
- :Reference numbers: AD29094
126
- :Invoice date:
127
- :Invoice due date: 2020-02-17
128
- :Supplier name: TURNPIKE DESIGNS CO.
129
- :Supplier address: 156 University Ave, Toronto ON, Canada M5H 2H7
130
- :Supplier company registrations:
131
- :Supplier payment details:
132
- :Customer name: JIRO DOI
133
- :Customer address: 1954 Bloon Street West Toronto, ON, M6P 3K9 Canada
134
- :Customer company registrations:
84
+ :Locale: en; en; CAD;
85
+ :Invoice Number: 14
86
+ :Reference Numbers: AD29094
87
+ :Purchase Date: 2018-09-25
88
+ :Due Date: 2018-09-25
89
+ :Total Net:
90
+ :Total Amount: 2608.20
135
91
  :Taxes:
136
92
  +---------------+--------+----------+---------------+
137
93
  | Base | Code | Rate (%) | Amount |
138
94
  +===============+========+==========+===============+
139
95
  | | | 8.00 | 193.20 |
140
96
  +---------------+--------+----------+---------------+
141
- :Total net:
142
- :Total tax: 193.20
143
- :Total amount: 2608.20
97
+ :Supplier Payment Details:
98
+ :Supplier Name: TURNPIKE DESIGNS CO.
99
+ :Supplier Company Registrations:
100
+ :Supplier Address: 156 University Ave, Toronto ON, Canada M5H 2H7
101
+ :Customer Name: JIRO DOI
102
+ :Customer Company Registrations:
103
+ :Customer Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada
104
+ :Document Type: INVOICE
144
105
  :Line Items:
145
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
146
- | Code | QTY | Price | Amount | Tax (Rate) | Description |
147
- +======================+=========+=========+==========+==================+======================================+
148
- | XXX81125600010 | 1.00 | 250.00 | 250.00 | (10.00%) | a long string describing the item |
149
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
150
- | ABC456 | 200.30 | 8.101 | 1622.63 | 121.70 (7.50%) | Liquid perfection |
151
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
152
- | | | | | | CARTOUCHE L NR BROTHER TN247BK |
153
- +----------------------+---------+---------+----------+------------------+--------------------------------------+
106
+ +--------------------------------------+--------------+----------+------------+--------------+--------------+------------+
107
+ | Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit Price |
108
+ +======================================+==============+==========+============+==============+==============+============+
109
+ | Platinum web hosting package Down... | | 1.00 | | | 65.00 | 65.00 |
110
+ +--------------------------------------+--------------+----------+------------+--------------+--------------+------------+
111
+ | 2 page website design Includes ba... | | 3.00 | | | 2100.00 | 2100.00 |
112
+ +--------------------------------------+--------------+----------+------------+--------------+--------------+------------+
113
+ | Mobile designs Includes responsiv... | | 1.00 | | | 250.00 | 250.00 |
114
+ +--------------------------------------+--------------+----------+------------+--------------+--------------+------------+
154
115
  ```
155
116
 
156
117
  # Field Types
@@ -166,7 +127,7 @@ A typical `Field` object will have the following attributes:
166
127
  * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
167
128
  * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
168
129
  * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
169
- * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
130
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
170
131
 
171
132
 
172
133
  Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
@@ -199,6 +160,14 @@ The locale field `LocaleField` only implements the **value**, **confidence** and
199
160
  * **country** (`String`): ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 code for countries (e.g.: `GRB` or `GB` for "Great Britain"). Can be `nil`.
200
161
  * **currency** (`String`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `nil`.
201
162
 
163
+ ### Payment Details Field
164
+ Aside from the basic `Field` attributes, the payment details field `PaymentDetailsField` also implements the following:
165
+
166
+ * **account_number** (`String`): number of an account, expressed as a string. Can be `nil`.
167
+ * **iban** (`String`): International Bank Account Number. Can be `nil`.
168
+ * **routing_number** (`String`): routing number of an account. Can be `nil`.
169
+ * **swift** (`String`): the account holder's bank's SWIFT Business Identifier Code (BIC). Can be `nil`.
170
+
202
171
  ### String Field
203
172
  The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`).
204
173
 
@@ -206,7 +175,7 @@ The text field `StringField` only has one constraint: it's **value** is a `Strin
206
175
  #### Tax
207
176
  Aside from the basic `Field` attributes, the tax field `TaxField` also implements the following:
208
177
 
209
- * **rate** (`Float`): the tax rate applied to an item can be undefined. Expressed as a percentage. Can be `nil`.
178
+ * **rate** (`Float`): the tax rate applied to an item can be expressed as a percentage. Can be `nil`.
210
179
  * **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`.
211
180
  * **base** (`Float`): base amount used for the tax. Can be `nil`.
212
181
 
@@ -225,7 +194,7 @@ A `InvoiceV4LineItem` implements the following attributes:
225
194
 
226
195
  * `description` (String): The item description.
227
196
  * `product_code` (String): The product code referring to the item.
228
- * `quantity` (Integer): The item quantity
197
+ * `quantity` (Float): The item quantity
229
198
  * `tax_amount` (Float): The item tax amount.
230
199
  * `tax_rate` (Float): The item tax rate in percentage.
231
200
  * `total_amount` (Float): The item total amount.
@@ -235,7 +204,7 @@ A `InvoiceV4LineItem` implements the following attributes:
235
204
  The following fields are extracted for Invoice V4:
236
205
 
237
206
  ## Customer Address
238
- **customerAddress** ([StringField](#string-field)): The address of the customer.
207
+ **customer_address** ([StringField](#string-field)): The address of the customer.
239
208
 
240
209
  ```rb
241
210
  puts result.document.inference.prediction.customer_address.value
@@ -245,13 +214,13 @@ puts result.document.inference.prediction.customer_address.value
245
214
  **customer_company_registrations** (Array<[CompanyRegistrationField](#company-registration-field)>): List of company registrations associated to the customer.
246
215
 
247
216
  ```rb
248
- for customer_company_registration_elem in result.document.inference.prediction.customer_company_registration do
249
- puts customer_company_registration_elem.value
217
+ for customer_company_registrations_elem in result.document.inference.prediction.customer_company_registrations do
218
+ puts customer_company_registrations_elem.value
250
219
  end
251
220
  ```
252
221
 
253
222
  ## Customer Name
254
- **customer_name** ([StringField](#string-field)): The name of the customer.
223
+ **customer_name** ([StringField](#string-field)): The name of the customer or client.
255
224
 
256
225
  ```rb
257
226
  puts result.document.inference.prediction.customer_name.value
@@ -314,7 +283,7 @@ end
314
283
  **supplier_address** ([StringField](#string-field)): The address of the supplier or merchant.
315
284
 
316
285
  ```rb
317
- result.document.inference.prediction.supplier_address.value
286
+ puts result.document.inference.prediction.supplier_address.value
318
287
  ```
319
288
 
320
289
  ## Supplier Company Registrations
@@ -339,15 +308,18 @@ puts result.document.inference.prediction.supplier_name.value
339
308
  ```rb
340
309
  for supplier_payment_details_elem in result.document.inference.prediction.supplier_payment_details do
341
310
  puts supplier_payment_details_elem.value
311
+ puts supplier_payment_details_elem.rate
312
+ puts supplier_payment_details_elem.code
313
+ puts supplier_payment_details_elem.basis
342
314
  end
343
315
  ```
344
316
 
345
317
  ## Taxes
346
- **taxes** (Array<[TaxField](#taxes-field)>): List of tax lines information.
318
+ **taxes** (Array<[TaxField](#taxes-field)>): List of tax line details.
347
319
 
348
320
  ```rb
349
321
  for taxes_elem in result.document.inference.prediction.taxes do
350
- puts taxes_elem.to_s
322
+ puts taxes_elem.value
351
323
  end
352
324
  ```
353
325
 
@@ -67,7 +67,7 @@ A typical `Field` object will have the following attributes:
67
67
  * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
68
68
  * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
69
69
  * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
70
- * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
70
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
71
71
 
72
72
 
73
73
  Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
@@ -1,5 +1,5 @@
1
1
  ---
2
- title: Multi Receipts Detector API Ruby
2
+ title: Multi Receipts Detector OCR Ruby
3
3
  ---
4
4
  The Ruby OCR SDK supports the [Multi Receipts Detector API](https://platform.mindee.com/mindee/multi_receipts_detector).
5
5
 
@@ -77,7 +77,7 @@ A typical `Field` object will have the following attributes:
77
77
  * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
78
78
  * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
79
79
  * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
80
- * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
80
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
81
81
 
82
82
 
83
83
  Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
@@ -97,7 +97,10 @@ The following fields are extracted for Multi Receipts Detector V1:
97
97
 
98
98
  ```rb
99
99
  for receipts_elem in result.document.inference.prediction.receipts do
100
- puts receipts_elem.polygon
100
+ puts receipts_elem.polygon.to_s
101
+ puts receipts_elem.quadrangle.to_s
102
+ puts receipts_elem.rectangle.to_s
103
+ puts receipts_elem.boundingBox.to_s
101
104
  end
102
105
  ```
103
106
 
data/docs/passport_v1.md CHANGED
@@ -87,7 +87,7 @@ A typical `Field` object will have the following attributes:
87
87
  * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
88
88
  * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
89
89
  * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
90
- * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
90
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
91
91
 
92
92
 
93
93
  Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
@@ -105,7 +105,7 @@ A typical `Field` object will have the following attributes:
105
105
  * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
106
106
  * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
107
107
  * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
108
- * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
108
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
109
109
 
110
110
 
111
111
  Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
@@ -101,7 +101,7 @@ A typical `Field` object will have the following attributes:
101
101
  * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
102
102
  * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
103
103
  * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
104
- * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
104
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
105
105
 
106
106
 
107
107
  Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
data/docs/us_w9_v1.md CHANGED
@@ -1,10 +1,10 @@
1
1
  ---
2
2
  title: US W9 OCR Ruby
3
3
  ---
4
- The Ruby OCR SDK supports the [US W9 API](https://platform.mindee.com/mindee/us_w9).
4
+ The Ruby OCR SDK supports the [W9 API](https://platform.mindee.com/mindee/us_w9).
5
5
 
6
6
  Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/us_w9/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
7
- ![US W9 sample](https://github.com/mindee/client-lib-test-data/blob/main/products/us_w9/default_sample.jpg?raw=true)
7
+ ![W9 sample](https://github.com/mindee/client-lib-test-data/blob/main/products/us_w9/default_sample.jpg?raw=true)
8
8
 
9
9
  # Quick-Start
10
10
  ```rb
@@ -74,7 +74,7 @@ A typical `Field` object will have the following attributes:
74
74
  * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
75
75
  * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
76
76
  * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
77
- * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
77
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
78
78
 
79
79
 
80
80
  Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
@@ -93,7 +93,7 @@ The text field `StringField` only has one constraint: it's **value** is a `Strin
93
93
  Some fields are constrained to the page level, and so will not be retrievable to through the document.
94
94
 
95
95
  # Attributes
96
- The following fields are extracted for US W9 V1:
96
+ The following fields are extracted for W9 V1:
97
97
 
98
98
  ## Address
99
99
  [📄](#page-level-fields "This field is only present on individual pages.")**address** ([StringField](#string-field)): The street address (number, street, and apt. or suite no.) of the applicant.
data/lib/mindee/client.rb CHANGED
@@ -137,9 +137,9 @@ module Mindee
137
137
  # * `:on_min_pages` Apply the operation only if document has at least this many pages.
138
138
  # @param cropper [Boolean, nil] Whether to include cropper results for each page.
139
139
  # This performs a cropping operation on the server and will increase response time.
140
- # @param initial_delay_sec [Integer, Float, nil] initial delay before polling. Defaults to 6.
141
- # @param delay_sec [Integer, Float, nil] delay between polling attempts. Defaults to 3.
142
- # @param max_retries [Integer, nil] maximum amount of retries. Defaults to 10.
140
+ # @param initial_delay_sec [Integer, Float, nil] initial delay before polling. Defaults to 4.
141
+ # @param delay_sec [Integer, Float, nil] delay between polling attempts. Defaults to 2.
142
+ # @param max_retries [Integer, nil] maximum amount of retries. Defaults to 30.
143
143
  # @return [Mindee::Parsing::Common::ApiResponse]
144
144
  def enqueue_and_parse(
145
145
  input_source,
@@ -149,9 +149,9 @@ module Mindee
149
149
  close_file: true,
150
150
  page_options: nil,
151
151
  cropper: false,
152
- initial_delay_sec: 6,
153
- delay_sec: 3,
154
- max_retries: 10
152
+ initial_delay_sec: 4,
153
+ delay_sec: 2,
154
+ max_retries: 30
155
155
  )
156
156
  enqueue_res = enqueue(
157
157
  input_source,
@@ -243,11 +243,16 @@ module Mindee
243
243
  # Validates the parameters for async auto-polling
244
244
  # @param initial_delay_sec [Integer, Float] initial delay before polling
245
245
  # @param delay_sec [Integer, Float] delay between polling attempts
246
- # @param max_retries [Integer, nil] maximum amount of retries. Defaults to 10.
246
+ # @param max_retries [Integer, nil] maximum amount of retries.
247
247
  def validate_async_params(initial_delay_sec, delay_sec, max_retries)
248
- raise 'Cannot set auto-poll delay to less than 2 seconds' if delay_sec < 2
249
- raise 'Cannot set initial parsing delay to less than 4 seconds' if initial_delay_sec < 4
250
- raise 'Cannot set auto-poll delay to less than 2 seconds' unless max_retries.is_a? Integer
248
+ min_delay_sec = 1
249
+ min_initial_delay_sec = 2
250
+ min_retries = 2
251
+ raise "Cannot set auto-poll delay to less than #{min_delay_sec} seconds" if delay_sec < min_delay_sec
252
+ if initial_delay_sec < min_initial_delay_sec
253
+ raise "Cannot set initial parsing delay to less than #{min_initial_delay_sec} seconds"
254
+ end
255
+ raise "Cannot set auto-poll delay to less than #{min_retries} seconds" if max_retries < min_retries
251
256
  end
252
257
 
253
258
  # Creates an endpoint with the given values. Raises an error if the endpoint is invalid.
@@ -31,6 +31,8 @@ module Mindee
31
31
  attr_reader :api_key
32
32
  # @return [Integer]
33
33
  attr_reader :request_timeout
34
+ # @return [String]
35
+ attr_reader :url_root
34
36
 
35
37
  def initialize(owner, url_name, version, api_key: '')
36
38
  @owner = owner
@@ -38,7 +40,8 @@ module Mindee
38
40
  @version = version
39
41
  @request_timeout = ENV.fetch(REQUEST_TIMEOUT_ENV_NAME, TIMEOUT_DEFAULT).to_i
40
42
  @api_key = api_key.nil? || api_key.empty? ? ENV.fetch(API_KEY_ENV_NAME, API_KEY_DEFAULT) : api_key
41
- @url_root = "#{BASE_URL_DEFAULT}/products/#{@owner}/#{@url_name}/v#{@version}"
43
+ base_url = ENV.fetch(BASE_URL_ENV_NAME, BASE_URL_DEFAULT)
44
+ @url_root = "#{base_url.chomp('/')}/products/#{@owner}/#{@url_name}/v#{@version}"
42
45
  end
43
46
 
44
47
  # Call the prediction API.
@@ -174,6 +177,7 @@ module Mindee
174
177
  response
175
178
  end
176
179
 
180
+ # Checks API key
177
181
  def check_api_key
178
182
  return unless @api_key.nil? || @api_key.empty?
179
183
 
@@ -73,7 +73,7 @@ module Mindee
73
73
  class MindeeHttpError < StandardError
74
74
  # @return [String]
75
75
  attr_reader :status_code
76
- # @return [String]
76
+ # @return [Integer]
77
77
  attr_reader :api_code
78
78
  # @return [String]
79
79
  attr_reader :api_details
@@ -95,13 +95,14 @@ module Mindee
95
95
  attr_reader :job
96
96
  # @return [Mindee::Parsing::Common::ApiRequest]
97
97
  attr_reader :api_request
98
- # @return [String]
98
+ # @return [Hash]
99
99
  attr_reader :raw_http
100
100
 
101
101
  # @param product_class [Class<Mindee::Product>]
102
102
  # @param http_response [Hash]
103
+ # @param raw_http [String]
103
104
  def initialize(product_class, http_response, raw_http)
104
- @raw_http = raw_http
105
+ @raw_http = raw_http.to_s
105
106
  if http_response.key?('api_request')
106
107
  @api_request = Mindee::Parsing::Common::ApiRequest.new(http_response['api_request'])
107
108
  end
@@ -13,8 +13,10 @@ module Mindee
13
13
  attr_reader :name
14
14
  # @return [String] Mindee ID of the document
15
15
  attr_reader :id
16
- # @return [Mindee::Parsing::Common::Ocr::Ocr, nil]
16
+ # @return [Mindee::Parsing::Common::Ocr::Ocr, nil] OCR text results (limited availability)
17
17
  attr_reader :ocr
18
+ # @return [Integer] Amount of pages of the document
19
+ attr_reader :n_pages
18
20
 
19
21
  # @param http_response [Hash]
20
22
  # @return [Mindee::Parsing::Common::Ocr::Ocr]
@@ -32,6 +34,7 @@ module Mindee
32
34
  @name = http_response['name']
33
35
  @inference = product_class.new(http_response['inference'])
34
36
  @ocr = self.class.load_ocr(http_response)
37
+ @n_pages = http_response['n_pages']
35
38
  end
36
39
 
37
40
  # @return [String]
@@ -14,13 +14,16 @@ module Mindee
14
14
  attr_reader :polygon
15
15
  # @return [Array, Hash, String, nil]
16
16
  attr_reader :content
17
+ # @return [Integer, nil]
18
+ attr_reader :page_id
17
19
 
18
20
  # @param prediction [Hash]
19
- def initialize(prediction)
21
+ def initialize(prediction, page_id: nil)
20
22
  @content = prediction['content']
21
23
  @confidence = prediction['confidence']
22
24
  @polygon = Geometry.polygon_from_prediction(prediction['polygon'])
23
25
  @bounding_box = Geometry.get_bounding_box(@polygon) unless @polygon.nil? || @polygon.empty?
26
+ @page_id = page_id
24
27
  end
25
28
 
26
29
  # @return [String]
@@ -33,8 +36,6 @@ module Mindee
33
36
  class ListField
34
37
  # @return [Array<Mindee::Parsing::Custom::ListFieldItem>]
35
38
  attr_reader :values
36
- # @return [Integer, nil]
37
- attr_reader :page_id
38
39
  # true if the field was reconstructed or computed using other fields.
39
40
  # @return [Boolean]
40
41
  attr_reader :reconstructed
@@ -48,11 +49,12 @@ module Mindee
48
49
  def initialize(prediction, page_id, reconstructed: false)
49
50
  @values = []
50
51
  @confidence = prediction['confidence']
51
- @page_id = page_id || prediction['page_id']
52
+ page_id = prediction['page_id'] if page_id.nil? && prediction.include?('page_id')
52
53
  @reconstructed = reconstructed
53
54
 
54
55
  prediction['values'].each do |field|
55
- @values.push(ListFieldItem.new(field))
56
+ page_id = field['page_id'] if field.include?('page_id')
57
+ @values.push(ListFieldItem.new(field, page_id: page_id))
56
58
  end
57
59
  end
58
60
 
@@ -96,7 +96,7 @@ module Mindee
96
96
  return '' if in_str.nil?
97
97
  return in_str if max_col_size.nil?
98
98
 
99
- in_str.length < max_col_size ? in_str : "#{in_str[0..max_col_size - 3]}..."
99
+ in_str.length < max_col_size ? in_str : "#{in_str[0..max_col_size - 4]}..."
100
100
  end
101
101
  end
102
102
  end