mindee 3.16.0 → 3.17.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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/bin/mindee.rb +20 -2
  4. data/docs/code_samples/{international_id_v1_async.txt → driver_license_v1_async.txt} +1 -1
  5. data/docs/code_samples/french_healthcard_v1_async.txt +19 -0
  6. data/docs/code_samples/payslip_fra_v3_async.txt +19 -0
  7. data/docs/code_samples/workflow_execution.txt +29 -0
  8. data/docs/driver_license_v1.md +156 -0
  9. data/docs/{carte_vitale_v1.md → french_healthcard_v1.md} +14 -24
  10. data/docs/payslip_fra_v3.md +319 -0
  11. data/lib/mindee/client.rb +40 -0
  12. data/lib/mindee/http/workflow_endpoint.rb +90 -0
  13. data/lib/mindee/http.rb +1 -0
  14. data/lib/mindee/parsing/common/api_response.rb +22 -1
  15. data/lib/mindee/parsing/common/execution.rb +73 -0
  16. data/lib/mindee/parsing/common/execution_file.rb +24 -0
  17. data/lib/mindee/parsing/common/execution_priority.rb +30 -0
  18. data/lib/mindee/parsing/common.rb +3 -0
  19. data/lib/mindee/product/{international_id/international_id_v1.rb → driver_license/driver_license_v1.rb} +9 -9
  20. data/lib/mindee/product/driver_license/driver_license_v1_document.rb +91 -0
  21. data/lib/mindee/product/{international_id/international_id_v1_page.rb → driver_license/driver_license_v1_page.rb} +7 -7
  22. data/lib/mindee/product/fr/health_card/health_card_v1.rb +41 -0
  23. data/lib/mindee/product/fr/health_card/health_card_v1_document.rb +52 -0
  24. data/lib/mindee/product/fr/health_card/health_card_v1_page.rb +34 -0
  25. data/lib/mindee/product/fr/payslip/payslip_v3.rb +41 -0
  26. data/lib/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rb +54 -0
  27. data/lib/mindee/product/fr/payslip/payslip_v3_document.rb +166 -0
  28. data/lib/mindee/product/fr/payslip/payslip_v3_employee.rb +78 -0
  29. data/lib/mindee/product/fr/payslip/payslip_v3_employer.rb +78 -0
  30. data/lib/mindee/product/fr/payslip/payslip_v3_employment.rb +78 -0
  31. data/lib/mindee/product/fr/payslip/payslip_v3_page.rb +34 -0
  32. data/lib/mindee/product/fr/payslip/payslip_v3_paid_time_off.rb +89 -0
  33. data/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb +100 -0
  34. data/lib/mindee/product/fr/payslip/payslip_v3_pay_period.rb +66 -0
  35. data/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb +89 -0
  36. data/lib/mindee/product/resume/resume_v1_document.rb +1 -1
  37. data/lib/mindee/product/resume/resume_v1_page.rb +1 -1
  38. data/lib/mindee/product.rb +3 -1
  39. data/lib/mindee/version.rb +1 -1
  40. metadata +30 -10
  41. data/docs/eu_driver_license_v1.md +0 -227
  42. data/docs/proof_of_address_v1.md +0 -211
  43. data/docs/us_driver_license_v1.md +0 -272
  44. data/lib/mindee/product/international_id/international_id_v1_document.rb +0 -109
@@ -0,0 +1,319 @@
1
+ ---
2
+ title: FR Payslip OCR Ruby
3
+ category: 622b805aaec68102ea7fcbc2
4
+ slug: ruby-fr-payslip-ocr
5
+ parentDoc: 6294d97ee723f1008d2ab28e
6
+ ---
7
+ The Ruby OCR SDK supports the [Payslip API](https://platform.mindee.com/mindee/payslip_fra).
8
+
9
+ Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
10
+ ![Payslip sample](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg?raw=true)
11
+
12
+ # Quick-Start
13
+ ```rb
14
+ require 'mindee'
15
+
16
+ # Init a new client
17
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
18
+
19
+ # Load a file from disk
20
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
21
+
22
+ # Parse the file
23
+ result = mindee_client.enqueue_and_parse(
24
+ input_source,
25
+ Mindee::Product::FR::Payslip::PayslipV3
26
+ )
27
+
28
+ # Print a full summary of the parsed data in RST format
29
+ puts result.document
30
+
31
+ # Print the document-level parsed data
32
+ # puts result.document.inference.prediction
33
+
34
+ ```
35
+
36
+ **Output (RST):**
37
+ ```rst
38
+ ########
39
+ Document
40
+ ########
41
+ :Mindee ID: a479e3e7-6838-4e82-9a7d-99289f34ec7f
42
+ :Filename: default_sample.jpg
43
+
44
+ Inference
45
+ #########
46
+ :Product: mindee/payslip_fra v3.0
47
+ :Rotation applied: Yes
48
+
49
+ Prediction
50
+ ==========
51
+ :Pay Period:
52
+ :End Date: 2023-03-31
53
+ :Month: 03
54
+ :Payment Date: 2023-03-29
55
+ :Start Date: 2023-03-01
56
+ :Year: 2023
57
+ :Employee:
58
+ :Address: 52 RUE DES FLEURS 33500 LIBOURNE FRANCE
59
+ :Date of Birth:
60
+ :First Name: Jean Luc
61
+ :Last Name: Picard
62
+ :Phone Number:
63
+ :Registration Number:
64
+ :Social Security Number: 123456789012345
65
+ :Employer:
66
+ :Address: 1 RUE DU TONNOT 25210 DOUBS
67
+ :Company ID: 12345678901234
68
+ :Company Site:
69
+ :NAF Code: 1234A
70
+ :Name: DEMO COMPANY
71
+ :Phone Number:
72
+ :URSSAF Number:
73
+ :Bank Account Details:
74
+ :Bank Name:
75
+ :IBAN:
76
+ :SWIFT:
77
+ :Employment:
78
+ :Category: Cadre
79
+ :Coefficient: 600,000
80
+ :Collective Agreement: Construction -- Promotion
81
+ :Job Title: Directeur Régional du Développement
82
+ :Position Level: Niveau 5 Echelon 3
83
+ :Seniority Date:
84
+ :Start Date: 2022-05-01
85
+ :Salary Details:
86
+ +--------------+-----------+--------------------------------------+--------+-----------+
87
+ | Amount | Base | Description | Number | Rate |
88
+ +==============+===========+======================================+========+===========+
89
+ | 6666.67 | | Salaire de base | | |
90
+ +--------------+-----------+--------------------------------------+--------+-----------+
91
+ | 9.30 | | Part patronale Mutuelle NR | | |
92
+ +--------------+-----------+--------------------------------------+--------+-----------+
93
+ | 508.30 | | Avantages en nature voiture | | |
94
+ +--------------+-----------+--------------------------------------+--------+-----------+
95
+ :Pay Detail:
96
+ :Gross Salary: 7184.27
97
+ :Gross Salary YTD: 18074.81
98
+ :Income Tax Rate: 17.60
99
+ :Income Tax Withheld: 1030.99
100
+ :Net Paid: 3868.32
101
+ :Net Paid Before Tax: 4899.31
102
+ :Net Taxable: 5857.90
103
+ :Net Taxable YTD: 14752.73
104
+ :Total Cost Employer: 10486.94
105
+ :Total Taxes and Deductions: 1650.36
106
+ :Paid Time Off:
107
+ +-----------+--------+-------------+-----------+-----------+
108
+ | Accrued | Period | Type | Remaining | Used |
109
+ +===========+========+=============+===========+===========+
110
+ | | N-1 | VACATION | | |
111
+ +-----------+--------+-------------+-----------+-----------+
112
+ | 6.17 | N | VACATION | 6.17 | |
113
+ +-----------+--------+-------------+-----------+-----------+
114
+ | 2.01 | N | RTT | 2.01 | |
115
+ +-----------+--------+-------------+-----------+-----------+
116
+ ```
117
+
118
+ # Field Types
119
+ ## Standard Fields
120
+ These fields are generic and used in several products.
121
+
122
+ ### Basic Field
123
+ Each prediction object contains a set of fields that inherit from the generic `Field` class.
124
+ A typical `Field` object will have the following attributes:
125
+
126
+ * **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted.
127
+ * **confidence** (Float, nil): the confidence score of the field prediction.
128
+ * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
129
+ * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
130
+ * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level.
131
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
132
+
133
+
134
+ 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.
135
+
136
+ ## Specific Fields
137
+ Fields which are specific to this product; they are not used in any other product.
138
+
139
+ ### Bank Account Details Field
140
+ Information about the employee's bank account.
141
+
142
+ A `PayslipV3BankAccountDetail` implements the following attributes:
143
+
144
+ * `bank_name` (String): The name of the bank.
145
+ * `iban` (String): The IBAN of the bank account.
146
+ * `swift` (String): The SWIFT code of the bank.
147
+ Fields which are specific to this product; they are not used in any other product.
148
+
149
+ ### Employee Field
150
+ Information about the employee.
151
+
152
+ A `PayslipV3Employee` implements the following attributes:
153
+
154
+ * `address` (String): The address of the employee.
155
+ * `date_of_birth` (String): The date of birth of the employee.
156
+ * `first_name` (String): The first name of the employee.
157
+ * `last_name` (String): The last name of the employee.
158
+ * `phone_number` (String): The phone number of the employee.
159
+ * `registration_number` (String): The registration number of the employee.
160
+ * `social_security_number` (String): The social security number of the employee.
161
+ Fields which are specific to this product; they are not used in any other product.
162
+
163
+ ### Employer Field
164
+ Information about the employer.
165
+
166
+ A `PayslipV3Employer` implements the following attributes:
167
+
168
+ * `address` (String): The address of the employer.
169
+ * `company_id` (String): The company ID of the employer.
170
+ * `company_site` (String): The site of the company.
171
+ * `naf_code` (String): The NAF code of the employer.
172
+ * `name` (String): The name of the employer.
173
+ * `phone_number` (String): The phone number of the employer.
174
+ * `urssaf_number` (String): The URSSAF number of the employer.
175
+ Fields which are specific to this product; they are not used in any other product.
176
+
177
+ ### Employment Field
178
+ Information about the employment.
179
+
180
+ A `PayslipV3Employment` implements the following attributes:
181
+
182
+ * `category` (String): The category of the employment.
183
+ * `coefficient` (String): The coefficient of the employment.
184
+ * `collective_agreement` (String): The collective agreement of the employment.
185
+ * `job_title` (String): The job title of the employee.
186
+ * `position_level` (String): The position level of the employment.
187
+ * `seniority_date` (String): The seniority date of the employment.
188
+ * `start_date` (String): The start date of the employment.
189
+ Fields which are specific to this product; they are not used in any other product.
190
+
191
+ ### Paid Time Off Field
192
+ Information about paid time off.
193
+
194
+ A `PayslipV3PaidTimeOff` implements the following attributes:
195
+
196
+ * `accrued` (Float): The amount of paid time off accrued in the period.
197
+ * `period` (String): The paid time off period.
198
+
199
+ #### Possible values include:
200
+ - N
201
+ - N-1
202
+ - N-2
203
+
204
+ * `pto_type` (String): The type of paid time off.
205
+
206
+ #### Possible values include:
207
+ - VACATION
208
+ - RTT
209
+ - COMPENSATORY
210
+
211
+ * `remaining` (Float): The remaining amount of paid time off at the end of the period.
212
+ * `used` (Float): The amount of paid time off used in the period.
213
+ Fields which are specific to this product; they are not used in any other product.
214
+
215
+ ### Pay Detail Field
216
+ Detailed information about the pay.
217
+
218
+ A `PayslipV3PayDetail` implements the following attributes:
219
+
220
+ * `gross_salary` (Float): The gross salary of the employee.
221
+ * `gross_salary_ytd` (Float): The year-to-date gross salary of the employee.
222
+ * `income_tax_rate` (Float): The income tax rate of the employee.
223
+ * `income_tax_withheld` (Float): The income tax withheld from the employee's pay.
224
+ * `net_paid` (Float): The net paid amount of the employee.
225
+ * `net_paid_before_tax` (Float): The net paid amount before tax of the employee.
226
+ * `net_taxable` (Float): The net taxable amount of the employee.
227
+ * `net_taxable_ytd` (Float): The year-to-date net taxable amount of the employee.
228
+ * `total_cost_employer` (Float): The total cost to the employer.
229
+ * `total_taxes_and_deductions` (Float): The total taxes and deductions of the employee.
230
+ Fields which are specific to this product; they are not used in any other product.
231
+
232
+ ### Pay Period Field
233
+ Information about the pay period.
234
+
235
+ A `PayslipV3PayPeriod` implements the following attributes:
236
+
237
+ * `end_date` (String): The end date of the pay period.
238
+ * `month` (String): The month of the pay period.
239
+ * `payment_date` (String): The date of payment for the pay period.
240
+ * `start_date` (String): The start date of the pay period.
241
+ * `year` (String): The year of the pay period.
242
+ Fields which are specific to this product; they are not used in any other product.
243
+
244
+ ### Salary Details Field
245
+ Detailed information about the earnings.
246
+
247
+ A `PayslipV3SalaryDetail` implements the following attributes:
248
+
249
+ * `amount` (Float): The amount of the earning.
250
+ * `base` (Float): The base rate value of the earning.
251
+ * `description` (String): The description of the earnings.
252
+ * `number` (Float): The number of units in the earning.
253
+ * `rate` (Float): The rate of the earning.
254
+
255
+ # Attributes
256
+ The following fields are extracted for Payslip V3:
257
+
258
+ ## Bank Account Details
259
+ **bank_account_details** ([PayslipV3BankAccountDetail](#bank-account-details-field)): Information about the employee's bank account.
260
+
261
+ ```rb
262
+ puts result.document.inference.prediction.bank_account_details.value
263
+ ```
264
+
265
+ ## Employee
266
+ **employee** ([PayslipV3Employee](#employee-field)): Information about the employee.
267
+
268
+ ```rb
269
+ puts result.document.inference.prediction.employee.value
270
+ ```
271
+
272
+ ## Employer
273
+ **employer** ([PayslipV3Employer](#employer-field)): Information about the employer.
274
+
275
+ ```rb
276
+ puts result.document.inference.prediction.employer.value
277
+ ```
278
+
279
+ ## Employment
280
+ **employment** ([PayslipV3Employment](#employment-field)): Information about the employment.
281
+
282
+ ```rb
283
+ puts result.document.inference.prediction.employment.value
284
+ ```
285
+
286
+ ## Paid Time Off
287
+ **paid_time_off** (Array<[PayslipV3PaidTimeOff](#paid-time-off-field)>): Information about paid time off.
288
+
289
+ ```rb
290
+ for paid_time_off_elem in result.document.inference.prediction.paid_time_off do
291
+ puts paid_time_off_elem.value
292
+ end
293
+ ```
294
+
295
+ ## Pay Detail
296
+ **pay_detail** ([PayslipV3PayDetail](#pay-detail-field)): Detailed information about the pay.
297
+
298
+ ```rb
299
+ puts result.document.inference.prediction.pay_detail.value
300
+ ```
301
+
302
+ ## Pay Period
303
+ **pay_period** ([PayslipV3PayPeriod](#pay-period-field)): Information about the pay period.
304
+
305
+ ```rb
306
+ puts result.document.inference.prediction.pay_period.value
307
+ ```
308
+
309
+ ## Salary Details
310
+ **salary_details** (Array<[PayslipV3SalaryDetail](#salary-details-field)>): Detailed information about the earnings.
311
+
312
+ ```rb
313
+ for salary_details_elem in result.document.inference.prediction.salary_details do
314
+ puts salary_details_elem.value
315
+ end
316
+ ```
317
+
318
+ # Questions?
319
+ [Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g)
data/lib/mindee/client.rb CHANGED
@@ -195,6 +195,46 @@ module Mindee
195
195
 
196
196
  # rubocop:enable Metrics/ParameterLists
197
197
 
198
+ # Sends a document to a workflow.
199
+ #
200
+ # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource]
201
+ # @param document_alias [String, nil] Alias to give to the document.
202
+ # @param priority [Symbol, nil] Priority to give to the document.
203
+ # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs.
204
+ # This performs a full OCR operation on the server and may increase response time.
205
+ #
206
+ # @param public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without
207
+ # requiring authentication.
208
+ # @param page_options [Hash, nil] Page cutting/merge options:
209
+ #
210
+ # * `:page_indexes` Zero-based list of page indexes.
211
+ # * `:operation` Operation to apply on the document, given the `page_indexes specified:
212
+ # * `:KEEP_ONLY` - keep only the specified pages, and remove all others.
213
+ # * `:REMOVE` - remove the specified pages, and keep all others.
214
+ # * `:on_min_pages` Apply the operation only if document has at least this many pages.
215
+ #
216
+ #
217
+ # @return [Mindee::Parsing::Common::WorkflowResponse]
218
+ def execute_workflow(
219
+ input_source,
220
+ workflow_id,
221
+ document_alias: nil,
222
+ priority: nil,
223
+ full_text: false,
224
+ public_url: nil,
225
+ page_options: nil
226
+ )
227
+ if input_source.is_a?(Mindee::Input::Source::LocalInputSource) && !page_options.nil? && input_source.pdf?
228
+ input_source.process_pdf(page_options)
229
+ end
230
+
231
+ workflow_endpoint = Mindee::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key)
232
+ prediction, raw_http = workflow_endpoint.execute_workflow(input_source, full_text, document_alias, priority,
233
+ public_url)
234
+ Mindee::Parsing::Common::WorkflowResponse.new(Product::Generated::GeneratedV1,
235
+ prediction, raw_http)
236
+ end
237
+
198
238
  # Load a prediction.
199
239
  #
200
240
  # @param product_class [Mindee::Inference] class of the product
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+ require_relative 'error'
6
+
7
+ module Mindee
8
+ module HTTP
9
+ # Handles the routing for workflow calls.
10
+ class WorkflowEndpoint
11
+ # @return [String]
12
+ attr_reader :api_key
13
+ # @return [Integer]
14
+ attr_reader :request_timeout
15
+ # @return [String]
16
+ attr_reader :url
17
+
18
+ def initialize(workflow_id, api_key: '')
19
+ @request_timeout = ENV.fetch(REQUEST_TIMEOUT_ENV_NAME, TIMEOUT_DEFAULT).to_i
20
+ @api_key = api_key.nil? || api_key.empty? ? ENV.fetch(API_KEY_ENV_NAME, API_KEY_DEFAULT) : api_key
21
+ base_url = ENV.fetch(BASE_URL_ENV_NAME, BASE_URL_DEFAULT)
22
+ @url = "#{base_url.chomp('/')}/workflows/#{workflow_id}/executions"
23
+ end
24
+
25
+ # Sends a document to the workflow.
26
+ # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource]
27
+ # @param document_alias [String, nil] Alias to give to the document.
28
+ # @param priority [Symbol, nil] Priority to give to the document.
29
+ # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs.
30
+ # @param public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without
31
+ # requiring authentication.
32
+ # @return [Array]
33
+ def execute_workflow(input_source, full_text, document_alias, priority, public_url)
34
+ check_api_key
35
+ response = workflow_execution_req_post(input_source, document_alias, priority, full_text, public_url)
36
+ hashed_response = JSON.parse(response.body, object_class: Hash)
37
+ return [hashed_response, response.body] if ResponseValidation.valid_async_response?(response)
38
+
39
+ ResponseValidation.clean_request!(response)
40
+ error = Error.handle_error(@url_name, response)
41
+ raise error
42
+ end
43
+
44
+ # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource]
45
+ # @param document_alias [String, nil] Alias to give to the document.
46
+ # @param priority [Symbol, nil] Priority to give to the document.
47
+ # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs.
48
+ # @param public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without
49
+ # requiring authentication.
50
+ # @return [Net::HTTPResponse, nil]
51
+ def workflow_execution_req_post(input_source, document_alias, priority, full_text, public_url)
52
+ uri = URI(@url)
53
+ params = {}
54
+ params[:full_text_ocr] = 'true' if full_text
55
+ uri.query = URI.encode_www_form(params)
56
+
57
+ headers = {
58
+ 'Authorization' => "Token #{@api_key}",
59
+ 'User-Agent' => USER_AGENT,
60
+ }
61
+ req = Net::HTTP::Post.new(uri, headers)
62
+ form_data = if input_source.is_a?(Mindee::Input::Source::UrlInputSource)
63
+ [['document', input_source.url]]
64
+ else
65
+ [input_source.read_document]
66
+ end
67
+ form_data.push ['alias', document_alias] if document_alias
68
+ form_data.push ['public_url', public_url] if public_url
69
+ form_data.push ['priority', priority.to_s] if priority
70
+
71
+ req.set_form(form_data, 'multipart/form-data')
72
+
73
+ response = nil
74
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @request_timeout) do |http|
75
+ response = http.request(req)
76
+ end
77
+ response
78
+ end
79
+
80
+ # Checks API key
81
+ def check_api_key
82
+ return unless @api_key.nil? || @api_key.empty?
83
+
84
+ raise "Missing API key. Check your Client Configuration.\n" \
85
+ 'You can set this using the ' \
86
+ "'#{HTTP::API_KEY_ENV_NAME}' environment variable."
87
+ end
88
+ end
89
+ end
90
+ end
data/lib/mindee/http.rb CHANGED
@@ -2,3 +2,4 @@
2
2
 
3
3
  require_relative 'http/endpoint'
4
4
  require_relative 'http/error'
5
+ require_relative 'http/workflow_endpoint'
@@ -32,7 +32,7 @@ module Mindee
32
32
  attr_reader :id
33
33
  # @return [Mindee::Parsing::Standard::DateField]
34
34
  attr_reader :issued_at
35
- # @return [Mindee::Parsing::Standard::DateField, nil]
35
+ # @return [Time, nil]
36
36
  attr_reader :available_at
37
37
  # @return [JobStatus, Symbol]
38
38
  attr_reader :status
@@ -121,6 +121,27 @@ module Mindee
121
121
  @job = Mindee::Parsing::Common::Job.new(http_response['job']) if http_response.key?('job')
122
122
  end
123
123
  end
124
+
125
+ # Represents the server response after a document is sent to a workflow.
126
+ class WorkflowResponse
127
+ # Set the prediction model used to parse the document.
128
+ # The response object will be instantiated based on this parameter.
129
+ # @return [Mindee::Parsing::Common::Execution]
130
+ attr_reader :execution
131
+ # @return [Mindee::Parsing::Common::ApiRequest]
132
+ attr_reader :api_request
133
+ # @return [String]
134
+ attr_reader :raw_http
135
+
136
+ # @param http_response [Hash]
137
+ # @param product_class [Mindee::Inference]
138
+ def initialize(product_class, http_response, raw_http)
139
+ @raw_http = raw_http.to_s
140
+ @api_request = Mindee::Parsing::Common::ApiRequest.new(http_response['api_request'])
141
+ product_class = (product_class || Product::Generated::GeneratedV1)
142
+ @execution = Mindee::Parsing::Common::Execution.new(product_class, http_response['execution'])
143
+ end
144
+ end
124
145
  end
125
146
  end
126
147
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mindee
4
+ module Parsing
5
+ module Common
6
+ # Identifier for the batch to which the execution belongs.
7
+ class Execution
8
+ # Identifier for the batch to which the execution belongs.
9
+ # @return [String]
10
+ attr_reader :batch_name
11
+ # The time at which the execution started.
12
+ # @return [Time, nil]
13
+ attr_reader :created_at
14
+ # File representation within a workflow execution.
15
+ # @return [ExecutionFile]
16
+ attr_reader :file
17
+ # Identifier for the execution.
18
+ # @return [String]
19
+ attr_reader :id
20
+ # Deserialized inference object.
21
+ # @return [Mindee::Inference]
22
+ attr_reader :inference
23
+ # Priority of the execution.
24
+ # @return [ExecutionPriority]
25
+ attr_reader :priority
26
+ # The time at which the file was tagged as reviewed.
27
+ # @return [Time, nil]
28
+ attr_reader :reviewed_at
29
+ # The time at which the file was uploaded to a workflow.
30
+ # @return [Time, nil]
31
+ attr_reader :available_at
32
+ # Reviewed fields and values.
33
+ # @return [Mindee::Product::Generated::GeneratedV1Document]
34
+ attr_reader :reviewed_prediction
35
+ # Execution Status.
36
+ # @return [String]
37
+ attr_reader :status
38
+ # Execution type.
39
+ # @return [String]
40
+ attr_reader :type
41
+ # The time at which the file was uploaded to a workflow.
42
+ # @return [Time, nil]
43
+ attr_reader :uploaded_at
44
+ # Identifier for the workflow.
45
+ # @return [String]
46
+ attr_reader :workflow_id
47
+
48
+ # rubocop:disable Metrics/CyclomaticComplexity
49
+
50
+ # @param product_class [Mindee::Inference]
51
+ # @param http_response [Hash]
52
+ def initialize(product_class, http_response)
53
+ @batch_name = http_response['batch_name']
54
+ @created_at = Time.iso8601(http_response['created_at']) if http_response['created_at']
55
+ @file = ExecutionFile.new(http_response['file']) if http_response['file']
56
+ @id = http_response['id']
57
+ @inference = product_class.new(http_response['inference']) if http_response['inference']
58
+ @priority = Mindee::Parsing::Common::ExecutionPriority.to_priority(http_response['priority'])
59
+ @reviewed_at = Time.iso8601(http_response['reviewed_at']) if http_response['reviewed_at']
60
+ @available_at = Time.iso8601(http_response['available_at']) if http_response['available_at']
61
+ if http_response['reviewed_prediction']
62
+ @reviewed_prediction = GeneratedV1Document.new(http_response['reviewed_prediction'])
63
+ end
64
+ @status = http_response['status']
65
+ @type = http_response['type']
66
+ @uploaded_at = Time.iso8601(http_response['uploaded_at']) if http_response['uploaded_at']
67
+ @workflow_id = http_response['workflow_id']
68
+ end
69
+ # rubocop:enable Metrics/CyclomaticComplexity
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mindee
4
+ module Parsing
5
+ module Common
6
+ # Representation of a workflow execution's file data.
7
+ class ExecutionFile
8
+ # File name.
9
+ # @return [String]
10
+ attr_reader :name
11
+
12
+ # Optional alias for the file.
13
+ # @return [String]
14
+ attr_reader :alias
15
+
16
+ # @param http_response [Hash]
17
+ def initialize(http_response)
18
+ @name = http_response['name']
19
+ @alias = http_response['alias']
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mindee
4
+ module Parsing
5
+ module Common
6
+ # Execution policy priority values.
7
+ module ExecutionPriority
8
+ LOW = :low
9
+ MEDIUM = :medium
10
+ HIGH = :high
11
+
12
+ # Sets the priority to one of its possibly values, defaults to nil otherwise.
13
+ # @param [String, nil] priority_str
14
+ # @return [Symbol, nil]
15
+ def self.to_priority(priority_str)
16
+ return nil if priority_str.nil?
17
+
18
+ case priority_str.downcase
19
+ when 'low'
20
+ :low
21
+ when 'high'
22
+ :high
23
+ else
24
+ :medium
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,6 +2,9 @@
2
2
 
3
3
  require_relative 'common/api_response'
4
4
  require_relative 'common/document'
5
+ require_relative 'common/execution'
6
+ require_relative 'common/execution_file'
7
+ require_relative 'common/execution_priority'
5
8
  require_relative 'common/inference'
6
9
  require_relative 'common/ocr'
7
10
  require_relative 'common/prediction'
@@ -1,26 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../../parsing'
4
- require_relative 'international_id_v1_document'
5
- require_relative 'international_id_v1_page'
4
+ require_relative 'driver_license_v1_document'
5
+ require_relative 'driver_license_v1_page'
6
6
 
7
7
  module Mindee
8
8
  module Product
9
- # International ID module.
10
- module InternationalId
11
- # International ID V1 prediction inference.
12
- class InternationalIdV1 < Mindee::Parsing::Common::Inference
13
- @endpoint_name = 'international_id'
9
+ # Driver License module.
10
+ module DriverLicense
11
+ # Driver License API version 1 inference prediction.
12
+ class DriverLicenseV1 < Mindee::Parsing::Common::Inference
13
+ @endpoint_name = 'driver_license'
14
14
  @endpoint_version = '1'
15
15
 
16
16
  # @param prediction [Hash]
17
17
  def initialize(prediction)
18
18
  super
19
- @prediction = InternationalIdV1Document.new(prediction['prediction'], nil)
19
+ @prediction = DriverLicenseV1Document.new(prediction['prediction'], nil)
20
20
  @pages = []
21
21
  prediction['pages'].each do |page|
22
22
  if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
23
- @pages.push(InternationalIdV1Page.new(page))
23
+ @pages.push(DriverLicenseV1Page.new(page))
24
24
  end
25
25
  end
26
26
  end