diff --git a/.rubocop.yml b/.rubocop.yml index c8b7a7fa..1d5a8466 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,8 +8,9 @@ AllCops: - 'bin/*' - _test.rb - local_test/* + - Steepfile - TargetRubyVersion: 2.6 + TargetRubyVersion: 3.0 SuggestExtensions: false Gemspec/DevelopmentDependencies: diff --git a/README.md b/README.md index 14d81068..a28d5a5b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Quickly and easily connect to Mindee's API services using Ruby. ## Requirements -The following Ruby versions are tested and supported: 2.6, 2.7, 3.0, 3.1, 3.2 +The following Ruby versions are tested and supported: 3.0, 3.1, 3.2, 3.3, 3.4 ## Quick Start @@ -39,15 +39,18 @@ specific reason. Accidentally overwriting them can lead to unexpected behavior. Before making any changes, we recommend reviewing the following information to understand the purpose and potential impact of each environment variable: -* `MINDEE_API_KEY`: - * **Description**: Your personal Mindee API Key as shown on the platform. Be careful not to show this publicly! - * **Default Value**: `nil` +* `MINDEE_API_KEY`: + * **Description**: Your personal Mindee API Key as shown on the platform. Be careful not to show this publicly! + * **Default Value**: `nil` * `MINDEE_BASE_URL`: - * **Description**: The default base URL of the API endpoint. Use this variable to specify the root URL for API requests. Modify as needed for proxy configurations or changes in API endpoint location. - * **Default Value**: `https://api.mindee.net/v1` + * **Description**: The default base URL of the API endpoint. Use this variable to specify the root URL for API requests. Modify as needed for proxy configurations or changes in API endpoint location. + * **Default Value**: `https://api.mindee.net/v1` * `MINDEE_REQUEST_TIMEOUT`: - * **Description**: The default timeout for HTTP requests (in seconds). - * **Default Value**: `120` + * **Description**: The default timeout for HTTP requests (in seconds). + * **Default Value**: `120` +* `MINDEE_LOG_LEVEL`: + * **Description**: The default logging level for the mindee logger. + * **Default Value**: `WARN` ### Loading a File and Parsing It @@ -62,8 +65,8 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') # Load a file from disk input_source = mindee_client.source_from_path('/path/to/the/file.ext') result = mindee_client.parse( - input_source, - Mindee::Product::Invoice::InvoiceV4 + input_source, + Mindee::Product::Invoice::InvoiceV4 ) # Print a full summary of the parsed data in RST format @@ -108,15 +111,17 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') result = mindee_client.parse( - input_source, - Mindee::Product::EU::LicensePlate::LicensePlateV1 + input_source, + Mindee::Product::EU::LicensePlate::LicensePlateV1 ) # Print a full summary of the parsed data in RST format puts result.document ``` -### Custom Documents (docTI & Custom APIs) +### Universal - All Other Documents + +The Universal product acts as a catch-all for every and any API if it doesn't have an assigned product name. ```ruby require 'mindee' @@ -131,9 +136,9 @@ endpoint = mindee_client.create_endpoint( # Load a file from disk input_source = mindee_client.source_from_path('/path/to/the/file.ext') -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, - Mindee::Product::Generated::GeneratedV1, + Mindee::Product::Universal::Universal, endpoint: endpoint ) @@ -147,15 +152,10 @@ result.document.inference.prediction.fields.each do |field_name, field_data| puts field_data.to_s end ``` -## Asynchronously Parsing a File - -This allows for easier handling of bursts of documents sent. -Some products are only available asynchronously, check the example code -directly on the Mindee platform. +## Enqueueing and Parse a Webhook Response -### Enqueue and Parse a Webhook Response This is an optional way of handling asynchronous APIs. ```rb @@ -168,7 +168,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') -# Parse the file +# Send the file to the server enqueue_response = mindee_client.enqueue( input_source, Mindee::Product::InternationalId::InternationalIdV2 @@ -225,28 +225,9 @@ There's more to it than that for those that need more features, or want to customize the experience. * [Ruby Overview](https://developers.mindee.com/docs/ruby-getting-started) -* [Custom OCR Ruby (Deprecated)](https://developers.mindee.com/docs/ruby-api-builder-ocr) -* [Generated API Ruby](https://developers.mindee.com/docs/ruby-generated-ocr) -* [Invoice OCR Ruby](https://developers.mindee.com/docs/ruby-invoice-ocr) -* [International Id OCR Ruby](https://developers.mindee.com/docs/ruby-international-id-ocr) -* [Financial Document OCR Ruby](https://developers.mindee.com/docs/ruby-financial-document-ocr) -* [Passport OCR Ruby](https://developers.mindee.com/docs/ruby-passport-ocr) -* [Proof of Address OCR Ruby](https://developers.mindee.com/docs/ruby-proof-of-address-ocr) -* [Receipt OCR Ruby](https://developers.mindee.com/docs/ruby-receipt-ocr) -* [Resume OCR Ruby](https://developers.mindee.com/docs/ruby-resume-ocr) -* [EU License Plate OCR Ruby](https://developers.mindee.com/docs/ruby-eu-license-plate-ocr) -* [EU Driver License OCR Ruby](https://developers.mindee.com/docs/ruby-eu-driver-license-ocr) -* [FR Bank Account Details OCR Ruby](https://developers.mindee.com/docs/ruby-fr-bank-account-details-ocr) -* [FR Bank Statement OCR Ruby](https://developers.mindee.com/docs/ruby-fr-bank-statement-ocr) -* [FR Health Card OCR Ruby](https://developers.mindee.com/docs/ruby-fr-health-card-ocr) -* [FR ID Card OCR Ruby](https://developers.mindee.com/docs/ruby-fr-carte-nationale-didentite-ocr) -* [US Bank Check OCR Ruby](https://developers.mindee.com/docs/ruby-us-bank-check-ocr) -* [US Driver License OCR Ruby](https://developers.mindee.com/docs/ruby-us-driver-license-ocr) -* [US W9 API Ruby](https://developers.mindee.com/docs/ruby-us-w9-ocr) -* [Barcode Reader API Ruby](https://developers.mindee.com/docs/ruby-barcode-reader-ocr) -* [Cropper API Ruby](https://developers.mindee.com/docs/ruby-cropper-ocr) -* [Invoice Splitter API Ruby](https://developers.mindee.com/docs/ruby-invoice-splitter-ocr) -* [Multi Receipts Detector API Ruby](https://developers.mindee.com/docs/ruby-multi-receipts-detector-ocr) +* [Common file operations](https://developers.mindee.com/docs/ruby-common-file-operations) +* [Global products](https://developers.mindee.com/docs/ruby-global-products) +* [Localized products](https://developers.mindee.com/docs/ruby-localized-products) You can also take a look at the [Reference Documentation](https://mindee.github.io/mindee-api-ruby/). diff --git a/Steepfile b/Steepfile new file mode 100644 index 00000000..73b80857 --- /dev/null +++ b/Steepfile @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +D = Steep::Diagnostic + +target :lib do + signature 'sig/custom/*.rbs' + signature 'sig/mindee/**/*.rbs' + + check 'lib/mindee/**/*.rb' + # check 'bin' # CLI files are ignored + + # NOTE: Steep does not support some libraries: + # - net/http. + # - marcel + # - mini_magick + # - origami (my bad) + # Do NOT enable them. + # Use the stubs located at sig/custom/.rbs instead. + library 'date' + library 'fileutils' + library 'logger' + library 'json' + library 'openssl' + library 'pathname' + library 'tempfile' + library 'time' + library 'uri' + + configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default) +end + diff --git a/bin/mindee.rb b/bin/mindee.rb index 0622f4c3..903093e1 100755 --- a/bin/mindee.rb +++ b/bin/mindee.rb @@ -5,26 +5,13 @@ require 'optparse' require 'mindee' -options = {} DOCUMENTS = { - "custom" => { - description: "Custom document type from API builder", - doc_class: Mindee::Product::Custom::CustomV1, - sync: true, - async: false, - }, - "generated" => { - description: "Generated document type from API builder", - doc_class: Mindee::Product::Generated::GeneratedV1, + "universal" => { + description: "Universal document type from API builder", + doc_class: Mindee::Product::Universal::Universal, sync: true, async: true, }, - "proof-of-address" => { - description: 'Proof of Address', - doc_class: Mindee::Product::ProofOfAddress::ProofOfAddressV1, - sync: true, - async: false, - }, "cropper" => { description: 'Cropper', doc_class: Mindee::Product::Cropper::CropperV1, @@ -79,12 +66,6 @@ sync: true, async: false, }, - "eu-driver-license" => { - description: "EU Driver License", - doc_class: Mindee::Product::EU::DriverLicense::DriverLicenseV1, - sync: true, - async: false, - }, "fr-bank-account-details" => { description: "FR Bank Account Details", doc_class: Mindee::Product::FR::BankAccountDetails::BankAccountDetailsV2, @@ -93,7 +74,7 @@ }, "fr-bank-statement" => { description: "FR Bank Statement", - doc_class: Mindee::Product::FR::BankStatement::BankStatementV1, + doc_class: Mindee::Product::FR::BankStatement::BankStatementV2, sync: false, async: true, }, @@ -121,12 +102,6 @@ sync: true, async: false, }, - "us-driver-license" => { - description: "US Driver License", - doc_class: Mindee::Product::US::DriverLicense::DriverLicenseV1, - sync: true, - async: false, - }, "us-heathcare-card" => { description: "US Healthcare Card", doc_class: Mindee::Product::US::HealthcareCard::HealthcareCardV1, @@ -148,13 +123,8 @@ } options = {} -DEFAULT_CUTTING = { - page_indexes: [0, 1, 2, 3, 4], - operation: :KEEP_ONLY, - on_min_pages: 0, -} -# Initializes custom & generated-specific options +# Initializes universal-specific options # @param cli_parser [OptionParser] def custom_subcommand(cli_parser, options) cli_parser.on('-v [VERSION]', '--version [VERSION]', 'Model version for the API') do |v| @@ -171,7 +141,7 @@ def custom_subcommand(cli_parser, options) opts.on('-w', '--all-words', 'Include words in response') do |v| options[:all_words] = v end - opts.on('-c', '--cut-pages', "Don't cut document pages") do |v| + opts.on('-c', '--cut-pages', "Cut document pages") do |v| options[:cut_pages] = v end opts.on('-k [KEY]', '--key [KEY]', 'API key for the endpoint') do |v| @@ -181,12 +151,10 @@ def custom_subcommand(cli_parser, options) options[:print_full] = true end opts.on('-F', '--fix-pdf', "Attempts to fix broken PDF files before sending them to the server.") do |v| - options[:fix_pdf] = true + options[:repair_pdf] = true end - if (doc_key != 'custom' && doc_key != 'generated') - opts.banner = "Product: #{doc_value[:description]}. \nUsage: mindee.rb #{doc_key} [options] file" - else - opts.banner = "#{doc_value[:description]}. \nUsage: \nmindee.rb custom [options] endpoint_name file\nor\nmindee.rb generated [options] endpoint_name file" + if doc_key != 'universal' + opts.banner = "#{doc_value[:description]}. \nUsage: \nmindee.rb universal [options] endpoint_name file\nor\nmindee.rb universal [options] endpoint_name file" custom_subcommand(opts, options) end if doc_value[:async] @@ -206,13 +174,13 @@ def custom_subcommand(cli_parser, options) end command = ARGV.shift -if !DOCUMENTS.include?(command) +unless DOCUMENTS.include?(command) abort(global_parser.help) end doc_class = DOCUMENTS[command][:doc_class] product_parser[command].parse! -if command == 'custom' || command == 'generated' +if command == 'universal' if ARGV.length < 2 $stderr.puts "The '#{command}' command requires both ENDPOINT_NAME and file arguments." abort(product_parser[command].help) @@ -229,13 +197,13 @@ def custom_subcommand(cli_parser, options) end mindee_client = Mindee::Client.new(api_key: options[:api_key]) -if (options[:file_path].start_with?("https://")) +if options[:file_path].start_with?("https://") input_source = mindee_client.source_from_url(options[:file_path]) else - input_source = mindee_client.source_from_path(options[:file_path], fix_pdf: options[:fix_pdf]) + input_source = mindee_client.source_from_path(options[:file_path], repair_pdf: options[:repair_pdf]) end -if command == 'custom' || command == 'generated' +if command == 'universal' custom_endpoint = mindee_client.create_endpoint( endpoint_name: endpoint_name, account_name: options[:account_name], @@ -245,7 +213,16 @@ def custom_subcommand(cli_parser, options) custom_endpoint = nil end -page_options = options[:cut_pages].nil? ? nil : default_cutting +if options[:cut_pages].nil? || !options[:cut_pages].is_a?(Integer) || options[:cut_pages] < 0 + page_options = options[:cut_pages].nil? +else + page_options = Mindee::PageOptions.new(params: { + page_indexes: (0..options[:cut_pages].to_i).to_a, + operation: :KEEP_ONLY, + on_min_pages: 0, + }) +end + if options[:parse_async].nil? if !DOCUMENTS[command][:sync] options[:parse_async] = true @@ -253,21 +230,12 @@ def custom_subcommand(cli_parser, options) options[:parse_async] = false end end -if options[:parse_async] - result = mindee_client.enqueue_and_parse( - input_source, - DOCUMENTS[command][:doc_class], - endpoint: custom_endpoint, - page_options: page_options, - ) -else - result = mindee_client.parse( - input_source, - DOCUMENTS[command][:doc_class], - endpoint: custom_endpoint, - page_options: page_options, - ) -end +result = mindee_client.parse( + input_source, + doc_class, + options: { endpoint: custom_endpoint, + options: Mindee::ParseOptions.new(params: { page_options: page_options }), enqueue: options[:parse_async] } +) if options[:print_full] puts result.document diff --git a/docs/advanced_file_operations.md b/docs/advanced_file_operations.md new file mode 100644 index 00000000..519a4db4 --- /dev/null +++ b/docs/advanced_file_operations.md @@ -0,0 +1,111 @@ +--- +title: Advanced File Operations +category: 622b805aaec68102ea7fcbc2 +slug: ruby-advanced-file-operations +parentDoc: 6294d97ee723f1008d2ab28e +--- + +> ❗️ Disclaimer: the file operations listed below do not directly manipulate the files you will pass to the library, +> they will instead create a copy before applying any operations, which means that the file you send may not be an +> exact copy of the file the server will receive. +> To avoid any unexpected or unwanted result, you can save a copy of the created file locally to inspect it visually +> before sending it. + +## Image compression + +The compression functionality for image files (JPEG, PNG, etc.) via the `compress!` method available on a +LocalInputSource. This method allows you to reduce file size by specifying quality and dimension constraints. + +Example: + +```rb +# Compress an image with custom parameters. +input_source.compress!(quality: 85, max_width: 1024, max_height: 768) +``` +> ⚠️ Warning: Compression alters the original image data. +> We strongly advise you inspect a compressed file before sending it: +> ```rb +> # Compress using a quality of 50%: +> input_source.compress!(quality: 50) +> input_source.write_to_file('path/to/my/compressed/file_50.jpg') +> ``` + +For reference, here's what the following levels of compression on this image will look like: + +Original: +![Invoice sample](https://github.com/mindee/client-lib-test-data/blob/main/products/invoices/default_sample.jpg?raw=true) + + +85% compressed: +![85% sample](https://github.com/mindee/client-lib-test-data/blob/main/file_operations/compression/compressed_ruby_85.jpg?raw=true) + +50% compressed: +![50% sample](https://github.com/mindee/client-lib-test-data/blob/main/file_operations/compression/compressed_ruby_50.jpg?raw=true) + +10% compressed: +![10% sample](https://github.com/mindee/client-lib-test-data/blob/main/file_operations/compression/compressed_ruby_10.jpg?raw=true) + + +## PDF operations + +PDF operations include both compression and fixing features. +These are specifically designed to handle challenges associated with PDF files, such as large file sizes and formatting +issues. + +### PDF compression + +> 🧪 PDF compression is an **experimental** feature that rasterizes each page of the PDF (similar to how images are +> compressed) to reduce its overall size. +> +> Because the process involves re-rendering the PDF’s contents, some source text may be lost or rendered differently. +> Use this feature with caution. + + +```rb +# Load a local input source. +input_file_path = "path/to/your/file.pdf" +output_file_path = "path/to/the/compressed/file.pdf" +pdf_input = Mindee::Input::Source::PathInputSource.new(input_file_path) + +# We advise you test the quality value yourself, as results may vary greatly depending on the input file +pdf_input.compress!(quality: 50) + +# Write the output file locally for visual checking: +File.write(output_file_path, pdf_input.io_stream.read) +``` + +> 🚧 Be warned that the source text (the text embedded in the PDF itself) might not render properly, +> and so source PDFs will be ignored by default. +> You can bypass this using: + +```rb +pdf_input.compress!(quality: 50, force_source_text: true) +``` + +Or alternatively, you can try to approximate the re-rendering of the source-text using: + +```rb +pdf_input.compress!(quality: 50, force_source_text: true, disable_source_text: false) +``` + +### PDF Repair + +The PDF repair feature attempts to rescue PDFs with invalid or broken header information. +This can sometimes help when files get rejected by the server. + +Example: +```rb +# Load a PDF file with the repair_pdf flag enabled. +input_source = mindee_client.source_from_file(file, "document.pdf", repair_pdf: true) +``` + +> ⚠️ Warning: PDF fixing alters the input file by re-writing header information. +> Use this feature only when required, as it might affect the integrity of the document file. + +--- + +Feel free to expand these examples and adjust the parameters as needed for your projects. For further details on +authentication and usage, you can refer to the [Getting Started Guide](getting_started.md). + +# Questions? +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/bank_statement_fr_v1.md b/docs/bank_statement_fr_v1.md deleted file mode 100644 index 7046e8fb..00000000 --- a/docs/bank_statement_fr_v1.md +++ /dev/null @@ -1,178 +0,0 @@ ---- -title: FR Bank Statement (FR) OCR Ruby -category: 622b805aaec68102ea7fcbc2 -slug: ruby-fr-bank-statement-ocr -parentDoc: 6294d97ee723f1008d2ab28e ---- -The Ruby OCR SDK supports the [Bank Statement (FR) API](https://platform.mindee.com/mindee/bank_statement_fr). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_statement_fr/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Bank Statement (FR) sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_statement_fr/default_sample.jpg?raw=true) - -# Quick-Start -```rb -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Parse the file -result = mindee_client.enqueue_and_parse( - input_source, - Mindee::Product::FR::BankStatement::BankStatementV1 -) - -# Print a full summary of the parsed data in RST format -puts result.document - -# Print the document-level parsed data -# puts result.document.inference.prediction -``` - -**Output (RST):** -```rst -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. -* **confidence** (Float, nil): the confidence score of the field prediction. -* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - - -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. - - -### Amount Field -The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`). - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **date_object** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`). - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Transactions Field -The list of values that represent the financial transactions recorded in a bank statement. - -A `BankStatementV1Transaction` implements the following attributes: - -* `amount` (Float): The monetary amount of the transaction. -* `date` (String): The date on which the transaction occurred. -* `description` (String): The additional information about the transaction. - -# Attributes -The following fields are extracted for Bank Statement (FR) V1: - -## Account Number -**account_number** ([StringField](#string-field)): The unique identifier for a customer's account in the bank's system. - -```rb -puts result.document.inference.prediction.account_number.value -``` - -## Bank Address -**bank_address** ([StringField](#string-field)): The physical location of the bank where the statement was issued. - -```rb -puts result.document.inference.prediction.bank_address.value -``` - -## Bank Name -**bank_name** ([StringField](#string-field)): The name of the bank that issued the statement. - -```rb -puts result.document.inference.prediction.bank_name.value -``` - -## Client Address -**client_address** ([StringField](#string-field)): The address of the client associated with the bank statement. - -```rb -puts result.document.inference.prediction.client_address.value -``` - -## Client Name -**client_name** ([StringField](#string-field)): The name of the client who owns the bank statement. - -```rb -puts result.document.inference.prediction.client_name.value -``` - -## Closing Balance -**closing_balance** ([AmountField](#amount-field)): The final amount of money in the account at the end of the statement period. - -```rb -puts result.document.inference.prediction.closing_balance.value -``` - -## Opening Balance -**opening_balance** ([AmountField](#amount-field)): The initial amount of money in an account at the start of the period. - -```rb -puts result.document.inference.prediction.opening_balance.value -``` - -## Statement Date -**statement_date** ([DateField](#date-field)): The date on which the bank statement was generated. - -```rb -puts result.document.inference.prediction.statement_date.value -``` - -## Statement End Date -**statement_end_date** ([DateField](#date-field)): The date when the statement period ends. - -```rb -puts result.document.inference.prediction.statement_end_date.value -``` - -## Statement Start Date -**statement_start_date** ([DateField](#date-field)): The date when the bank statement period begins. - -```rb -puts result.document.inference.prediction.statement_start_date.value -``` - -## Total Credits -**total_credits** ([AmountField](#amount-field)): The total amount of money deposited into the account. - -```rb -puts result.document.inference.prediction.total_credits.value -``` - -## Total Debits -**total_debits** ([AmountField](#amount-field)): The total amount of money debited from the account. - -```rb -puts result.document.inference.prediction.total_debits.value -``` - -## Transactions -**transactions** (Array<[BankStatementV1Transaction](#transactions-field)>): The list of values that represent the financial transactions recorded in a bank statement. - -```rb -for transactions_elem in result.document.inference.prediction.transactions do - puts transactions_elem.value -end -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/code_samples/bank_account_details_v1.txt b/docs/code_samples/bank_account_details_v1.txt index d090bc5b..c237ef83 100644 --- a/docs/code_samples/bank_account_details_v1.txt +++ b/docs/code_samples/bank_account_details_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/bank_account_details_v2.txt b/docs/code_samples/bank_account_details_v2.txt index 162f6ade..3ca5d422 100644 --- a/docs/code_samples/bank_account_details_v2.txt +++ b/docs/code_samples/bank_account_details_v2.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/bank_check_v1.txt b/docs/code_samples/bank_check_v1.txt index 7d2e11d0..142e152e 100644 --- a/docs/code_samples/bank_check_v1.txt +++ b/docs/code_samples/bank_check_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/bank_statement_fr_v1_async.txt b/docs/code_samples/bank_statement_fr_v1_async.txt deleted file mode 100644 index 58f4026d..00000000 --- a/docs/code_samples/bank_statement_fr_v1_async.txt +++ /dev/null @@ -1,19 +0,0 @@ -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Parse the file -result = mindee_client.enqueue_and_parse( - input_source, - Mindee::Product::FR::BankStatement::BankStatementV1 -) - -# Print a full summary of the parsed data in RST format -puts result.document - -# Print the document-level parsed data -# puts result.document.inference.prediction diff --git a/docs/code_samples/bank_statement_fr_v2_async.txt b/docs/code_samples/bank_statement_fr_v2_async.txt index dfd299e7..57069619 100644 --- a/docs/code_samples/bank_statement_fr_v2_async.txt +++ b/docs/code_samples/bank_statement_fr_v2_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FR::BankStatement::BankStatementV2 ) diff --git a/docs/code_samples/barcode_reader_v1.txt b/docs/code_samples/barcode_reader_v1.txt index 1bed10d7..6e19e07f 100644 --- a/docs/code_samples/barcode_reader_v1.txt +++ b/docs/code_samples/barcode_reader_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/bill_of_lading_v1.txt b/docs/code_samples/bill_of_lading_v1.txt new file mode 100644 index 00000000..b9a0c6b3 --- /dev/null +++ b/docs/code_samples/bill_of_lading_v1.txt @@ -0,0 +1,25 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + + +require 'mindee' + +# Init a new client +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Parse the file +result = mindee_client.parse( + input_source, + Mindee::Product::BillOfLading::BillOfLadingV1 +) + +# Print a full summary of the parsed data in RST format +puts result.document + +# Print the document-level parsed data +# puts result.document.inference.prediction diff --git a/docs/code_samples/bill_of_lading_v1_async.txt b/docs/code_samples/bill_of_lading_v1_async.txt index 1bfba1a8..2622f296 100644 --- a/docs/code_samples/bill_of_lading_v1_async.txt +++ b/docs/code_samples/bill_of_lading_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::BillOfLading::BillOfLadingV1 ) diff --git a/docs/code_samples/business_card_v1.txt b/docs/code_samples/business_card_v1.txt new file mode 100644 index 00000000..d7adfea0 --- /dev/null +++ b/docs/code_samples/business_card_v1.txt @@ -0,0 +1,24 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + +require 'mindee' + +# Init a new client +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Parse the file +result = mindee_client.parse( + input_source, + Mindee::Product::BusinessCard::BusinessCardV1 +) + +# Print a full summary of the parsed data in RST format +puts result.document + +# Print the document-level parsed data +# puts result.document.inference.prediction diff --git a/docs/code_samples/business_card_v1_async.txt b/docs/code_samples/business_card_v1_async.txt index cf71e928..d7adfea0 100644 --- a/docs/code_samples/business_card_v1_async.txt +++ b/docs/code_samples/business_card_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::BusinessCard::BusinessCardV1 ) diff --git a/docs/code_samples/carte_grise_v1.txt b/docs/code_samples/carte_grise_v1.txt index 33658234..21e11499 100644 --- a/docs/code_samples/carte_grise_v1.txt +++ b/docs/code_samples/carte_grise_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/cropper_v1.txt b/docs/code_samples/cropper_v1.txt index e65b2da4..cd9693f4 100644 --- a/docs/code_samples/cropper_v1.txt +++ b/docs/code_samples/cropper_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/custom_v1.txt b/docs/code_samples/custom_v1.txt deleted file mode 100644 index ea1d2bd2..00000000 --- a/docs/code_samples/custom_v1.txt +++ /dev/null @@ -1,33 +0,0 @@ -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Initialize a custom endpoint for this product -custom_endpoint = mindee_client.create_endpoint( - account_name: 'my-account', - endpoint_name: 'my-endpoint' -) - -# Parse the file -result = mindee_client.parse( - input_source, - Mindee::Product::Custom::CustomV1, - endpoint: custom_endpoint -) - -# Print a full summary of the parsed data in RST format -puts result.document - -# Print the document-level parsed data -# puts result.document.inference.prediction - -# Looping over all prediction values -result.document.inference.prediction.fields.each do |field_name, field_data| - puts field_name - puts field_data.values - puts field_data.to_s -end diff --git a/docs/code_samples/default.txt b/docs/code_samples/default.txt index 8ad7da4d..c75db9d9 100644 --- a/docs/code_samples/default.txt +++ b/docs/code_samples/default.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -16,8 +21,9 @@ custom_endpoint = mindee_client.create_endpoint( # Parse the file result = mindee_client.parse( input_source, - Mindee::Product::Generated::GeneratedV1, - endpoint: custom_endpoint + Mindee::Product::Universal::Universal, + endpoint: custom_endpoint, + enqueue: false ) # Print a full summary of the parsed data in RST format diff --git a/docs/code_samples/default_async.txt b/docs/code_samples/default_async.txt index 85c645b2..e7ef3f44 100644 --- a/docs/code_samples/default_async.txt +++ b/docs/code_samples/default_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -14,9 +19,9 @@ custom_endpoint = mindee_client.create_endpoint( ) # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, - Mindee::Product::Generated::GeneratedV1, + Mindee::Product::Universal::Universal, endpoint: custom_endpoint ) diff --git a/docs/code_samples/delivery_notes_v1.txt b/docs/code_samples/delivery_notes_v1.txt new file mode 100644 index 00000000..895b3fc0 --- /dev/null +++ b/docs/code_samples/delivery_notes_v1.txt @@ -0,0 +1,24 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + +require 'mindee' + +# Init a new client +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Parse the file +result = mindee_client.parse( + input_source, + Mindee::Product::DeliveryNote::DeliveryNoteV1 +) + +# Print a full summary of the parsed data in RST format +puts result.document + +# Print the document-level parsed data +# puts result.document.inference.prediction diff --git a/docs/code_samples/delivery_notes_v1_async.txt b/docs/code_samples/delivery_notes_v1_async.txt index 3c38b76a..895b3fc0 100644 --- a/docs/code_samples/delivery_notes_v1_async.txt +++ b/docs/code_samples/delivery_notes_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::DeliveryNote::DeliveryNoteV1 ) diff --git a/docs/code_samples/driver_license_v1.txt b/docs/code_samples/driver_license_v1.txt new file mode 100644 index 00000000..700a4fe1 --- /dev/null +++ b/docs/code_samples/driver_license_v1.txt @@ -0,0 +1,24 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + +require 'mindee' + +# Init a new client +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Parse the file +result = mindee_client.parse( + input_source, + Mindee::Product::DriverLicense::DriverLicenseV1 +) + +# Print a full summary of the parsed data in RST format +puts result.document + +# Print the document-level parsed data +# puts result.document.inference.prediction diff --git a/docs/code_samples/driver_license_v1_async.txt b/docs/code_samples/driver_license_v1_async.txt index 4b8b5c0d..700a4fe1 100644 --- a/docs/code_samples/driver_license_v1_async.txt +++ b/docs/code_samples/driver_license_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::DriverLicense::DriverLicenseV1 ) diff --git a/docs/code_samples/energy_bill_fra_v1.txt b/docs/code_samples/energy_bill_fra_v1.txt new file mode 100644 index 00000000..6d20bfa5 --- /dev/null +++ b/docs/code_samples/energy_bill_fra_v1.txt @@ -0,0 +1,24 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + +require 'mindee' + +# Init a new client +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Parse the file +result = mindee_client.parse( + input_source, + Mindee::Product::FR::EnergyBill::EnergyBillV1 +) + +# Print a full summary of the parsed data in RST format +puts result.document + +# Print the document-level parsed data +# puts result.document.inference.prediction diff --git a/docs/code_samples/energy_bill_fra_v1_async.txt b/docs/code_samples/energy_bill_fra_v1_async.txt index b045ac8b..6d20bfa5 100644 --- a/docs/code_samples/energy_bill_fra_v1_async.txt +++ b/docs/code_samples/energy_bill_fra_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FR::EnergyBill::EnergyBillV1 ) diff --git a/docs/code_samples/expense_receipts_v5.txt b/docs/code_samples/expense_receipts_v5.txt index cc3d8bac..59420d7b 100644 --- a/docs/code_samples/expense_receipts_v5.txt +++ b/docs/code_samples/expense_receipts_v5.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/expense_receipts_v5_async.txt b/docs/code_samples/expense_receipts_v5_async.txt index 8cfabd14..59420d7b 100644 --- a/docs/code_samples/expense_receipts_v5_async.txt +++ b/docs/code_samples/expense_receipts_v5_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::Receipt::ReceiptV5 ) diff --git a/docs/code_samples/financial_document_v1.txt b/docs/code_samples/financial_document_v1.txt index bca415af..dc0e8842 100644 --- a/docs/code_samples/financial_document_v1.txt +++ b/docs/code_samples/financial_document_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/financial_document_v1_async.txt b/docs/code_samples/financial_document_v1_async.txt index ee4cbb42..dc0e8842 100644 --- a/docs/code_samples/financial_document_v1_async.txt +++ b/docs/code_samples/financial_document_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FinancialDocument::FinancialDocumentV1 ) diff --git a/docs/code_samples/french_healthcard_v1.txt b/docs/code_samples/french_healthcard_v1.txt new file mode 100644 index 00000000..8f0ebd8d --- /dev/null +++ b/docs/code_samples/french_healthcard_v1.txt @@ -0,0 +1,24 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + +require 'mindee' + +# Init a new client +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Parse the file +result = mindee_client.parse( + input_source, + Mindee::Product::FR::HealthCard::HealthCardV1 +) + +# Print a full summary of the parsed data in RST format +puts result.document + +# Print the document-level parsed data +# puts result.document.inference.prediction diff --git a/docs/code_samples/french_healthcard_v1_async.txt b/docs/code_samples/french_healthcard_v1_async.txt index c7c9f1ee..8f0ebd8d 100644 --- a/docs/code_samples/french_healthcard_v1_async.txt +++ b/docs/code_samples/french_healthcard_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FR::HealthCard::HealthCardV1 ) diff --git a/docs/code_samples/idcard_fr_v1.txt b/docs/code_samples/idcard_fr_v1.txt index 61512ca8..caf4900d 100644 --- a/docs/code_samples/idcard_fr_v1.txt +++ b/docs/code_samples/idcard_fr_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/idcard_fr_v2.txt b/docs/code_samples/idcard_fr_v2.txt index a4a1ea94..9ba3c71a 100644 --- a/docs/code_samples/idcard_fr_v2.txt +++ b/docs/code_samples/idcard_fr_v2.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/ind_passport_v1.txt b/docs/code_samples/ind_passport_v1.txt new file mode 100644 index 00000000..af933cfc --- /dev/null +++ b/docs/code_samples/ind_passport_v1.txt @@ -0,0 +1,24 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + +require 'mindee' + +# Init a new client +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Parse the file +result = mindee_client.parse( + input_source, + Mindee::Product::IND::IndianPassport::IndianPassportV1 +) + +# Print a full summary of the parsed data in RST format +puts result.document + +# Print the document-level parsed data +# puts result.document.inference.prediction diff --git a/docs/code_samples/ind_passport_v1_async.txt b/docs/code_samples/ind_passport_v1_async.txt index f0e7a2e7..af933cfc 100644 --- a/docs/code_samples/ind_passport_v1_async.txt +++ b/docs/code_samples/ind_passport_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::IND::IndianPassport::IndianPassportV1 ) diff --git a/docs/code_samples/international_id_v2.txt b/docs/code_samples/international_id_v2.txt new file mode 100644 index 00000000..e463ab3c --- /dev/null +++ b/docs/code_samples/international_id_v2.txt @@ -0,0 +1,24 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + +require 'mindee' + +# Init a new client +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Parse the file +result = mindee_client.parse( + input_source, + Mindee::Product::InternationalId::InternationalIdV2 +) + +# Print a full summary of the parsed data in RST format +puts result.document + +# Print the document-level parsed data +# puts result.document.inference.prediction diff --git a/docs/code_samples/international_id_v2_async.txt b/docs/code_samples/international_id_v2_async.txt index 2f44c90d..e463ab3c 100644 --- a/docs/code_samples/international_id_v2_async.txt +++ b/docs/code_samples/international_id_v2_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::InternationalId::InternationalIdV2 ) diff --git a/docs/code_samples/invoice_splitter_v1_async.txt b/docs/code_samples/invoice_splitter_v1_async.txt index 8907d19a..e354da00 100644 --- a/docs/code_samples/invoice_splitter_v1_async.txt +++ b/docs/code_samples/invoice_splitter_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -6,7 +11,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') # Load a file from disk input_source = mindee_client.source_from_path('/path/to/the/file.ext') -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::InvoiceSplitter::InvoiceSplitterV1 ) diff --git a/docs/code_samples/invoices_v4.txt b/docs/code_samples/invoices_v4.txt index 1312a7c9..eb0495bf 100644 --- a/docs/code_samples/invoices_v4.txt +++ b/docs/code_samples/invoices_v4.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/invoices_v4_async.txt b/docs/code_samples/invoices_v4_async.txt index 2c681b86..eb0495bf 100644 --- a/docs/code_samples/invoices_v4_async.txt +++ b/docs/code_samples/invoices_v4_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::Invoice::InvoiceV4 ) diff --git a/docs/code_samples/license_plates_v1.txt b/docs/code_samples/license_plates_v1.txt index f765fd4c..0c2abca0 100644 --- a/docs/code_samples/license_plates_v1.txt +++ b/docs/code_samples/license_plates_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/multi_receipts_detector_v1.txt b/docs/code_samples/multi_receipts_detector_v1.txt index a330fc55..7827496c 100644 --- a/docs/code_samples/multi_receipts_detector_v1.txt +++ b/docs/code_samples/multi_receipts_detector_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/nutrition_facts_v1.txt b/docs/code_samples/nutrition_facts_v1.txt new file mode 100644 index 00000000..f3df6045 --- /dev/null +++ b/docs/code_samples/nutrition_facts_v1.txt @@ -0,0 +1,24 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + +require 'mindee' + +# Init a new client +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Parse the file +result = mindee_client.parse( + input_source, + Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1 +) + +# Print a full summary of the parsed data in RST format +puts result.document + +# Print the document-level parsed data +# puts result.document.inference.prediction diff --git a/docs/code_samples/nutrition_facts_v1_async.txt b/docs/code_samples/nutrition_facts_v1_async.txt index aff76e2d..f3df6045 100644 --- a/docs/code_samples/nutrition_facts_v1_async.txt +++ b/docs/code_samples/nutrition_facts_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1 ) diff --git a/docs/code_samples/passport_v1.txt b/docs/code_samples/passport_v1.txt index 4619e84a..b5d94b61 100644 --- a/docs/code_samples/passport_v1.txt +++ b/docs/code_samples/passport_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/eu_driver_license_v1.txt b/docs/code_samples/payslip_fra_v2.txt similarity index 78% rename from docs/code_samples/eu_driver_license_v1.txt rename to docs/code_samples/payslip_fra_v2.txt index 0065552f..552ad0f5 100644 --- a/docs/code_samples/eu_driver_license_v1.txt +++ b/docs/code_samples/payslip_fra_v2.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -9,7 +14,7 @@ input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file result = mindee_client.parse( input_source, - Mindee::Product::EU::DriverLicense::DriverLicenseV1 + Mindee::Product::FR::Payslip::PayslipV2 ) # Print a full summary of the parsed data in RST format diff --git a/docs/code_samples/payslip_fra_v2_async.txt b/docs/code_samples/payslip_fra_v2_async.txt index c82bfd63..552ad0f5 100644 --- a/docs/code_samples/payslip_fra_v2_async.txt +++ b/docs/code_samples/payslip_fra_v2_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FR::Payslip::PayslipV2 ) diff --git a/docs/code_samples/expense_receipts_v4.txt b/docs/code_samples/payslip_fra_v3.txt similarity index 78% rename from docs/code_samples/expense_receipts_v4.txt rename to docs/code_samples/payslip_fra_v3.txt index b65a8c84..52a074b0 100644 --- a/docs/code_samples/expense_receipts_v4.txt +++ b/docs/code_samples/payslip_fra_v3.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -9,7 +14,7 @@ input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file result = mindee_client.parse( input_source, - Mindee::Product::Receipt::ReceiptV4 + Mindee::Product::FR::Payslip::PayslipV3 ) # Print a full summary of the parsed data in RST format diff --git a/docs/code_samples/payslip_fra_v3_async.txt b/docs/code_samples/payslip_fra_v3_async.txt index ab012ee1..52a074b0 100644 --- a/docs/code_samples/payslip_fra_v3_async.txt +++ b/docs/code_samples/payslip_fra_v3_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FR::Payslip::PayslipV3 ) diff --git a/docs/code_samples/us_driver_license_v1.txt b/docs/code_samples/resume_v1.txt similarity index 79% rename from docs/code_samples/us_driver_license_v1.txt rename to docs/code_samples/resume_v1.txt index f5128301..5439a462 100644 --- a/docs/code_samples/us_driver_license_v1.txt +++ b/docs/code_samples/resume_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -9,7 +14,7 @@ input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file result = mindee_client.parse( input_source, - Mindee::Product::US::DriverLicense::DriverLicenseV1 + Mindee::Product::Resume::ResumeV1 ) # Print a full summary of the parsed data in RST format diff --git a/docs/code_samples/resume_v1_async.txt b/docs/code_samples/resume_v1_async.txt index 8c411a9f..5439a462 100644 --- a/docs/code_samples/resume_v1_async.txt +++ b/docs/code_samples/resume_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::Resume::ResumeV1 ) diff --git a/docs/code_samples/us_healthcare_cards_v1.txt b/docs/code_samples/us_healthcare_cards_v1.txt new file mode 100644 index 00000000..4b36ae96 --- /dev/null +++ b/docs/code_samples/us_healthcare_cards_v1.txt @@ -0,0 +1,24 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + +require 'mindee' + +# Init a new client +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Parse the file +result = mindee_client.parse( + input_source, + Mindee::Product::US::HealthcareCard::HealthcareCardV1 +) + +# Print a full summary of the parsed data in RST format +puts result.document + +# Print the document-level parsed data +# puts result.document.inference.prediction diff --git a/docs/code_samples/us_healthcare_cards_v1_async.txt b/docs/code_samples/us_healthcare_cards_v1_async.txt index f2905403..4b36ae96 100644 --- a/docs/code_samples/us_healthcare_cards_v1_async.txt +++ b/docs/code_samples/us_healthcare_cards_v1_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::US::HealthcareCard::HealthcareCardV1 ) diff --git a/docs/code_samples/us_mail_v2_async.txt b/docs/code_samples/us_mail_v2_async.txt deleted file mode 100644 index 94459557..00000000 --- a/docs/code_samples/us_mail_v2_async.txt +++ /dev/null @@ -1,19 +0,0 @@ -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Parse the file -result = mindee_client.enqueue_and_parse( - input_source, - Mindee::Product::US::UsMail::UsMailV2 -) - -# Print a full summary of the parsed data in RST format -puts result.document - -# Print the document-level parsed data -# puts result.document.inference.prediction diff --git a/docs/code_samples/proof_of_address_v1.txt b/docs/code_samples/us_mail_v3.txt similarity index 78% rename from docs/code_samples/proof_of_address_v1.txt rename to docs/code_samples/us_mail_v3.txt index 940291ed..b42c6aff 100644 --- a/docs/code_samples/proof_of_address_v1.txt +++ b/docs/code_samples/us_mail_v3.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -9,7 +14,7 @@ input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file result = mindee_client.parse( input_source, - Mindee::Product::ProofOfAddress::ProofOfAddressV1 + Mindee::Product::US::UsMail::UsMailV3 ) # Print a full summary of the parsed data in RST format diff --git a/docs/code_samples/us_mail_v3_async.txt b/docs/code_samples/us_mail_v3_async.txt index c6949216..b42c6aff 100644 --- a/docs/code_samples/us_mail_v3_async.txt +++ b/docs/code_samples/us_mail_v3_async.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -7,7 +12,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::US::UsMail::UsMailV3 ) diff --git a/docs/code_samples/us_w9_v1.txt b/docs/code_samples/us_w9_v1.txt index 73725cca..9eb9fdf4 100644 --- a/docs/code_samples/us_w9_v1.txt +++ b/docs/code_samples/us_w9_v1.txt @@ -1,3 +1,8 @@ +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client diff --git a/docs/code_samples/workflow_execution.txt b/docs/code_samples/workflow_execution.txt deleted file mode 100644 index f658f8bf..00000000 --- a/docs/code_samples/workflow_execution.txt +++ /dev/null @@ -1,29 +0,0 @@ -require 'mindee' - -workflow_id = 'workflow-id' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Send the file to the workflow -result = mindee_client.execute_workflow( - input_source, - workflow_id -) - -# Alternatively, set an alias & a priority for the execution. -# result = mindee_client.execute_workflow( -# input_source, -# workflow_id, -# document_alias: "my-alias", -# priority: Mindee::Parsing::Common::ExecutionPriority::LOW -# ) - -# Print the execution's ID to make sure it worked -puts result.execution.id - -# Print the inference, if present -# puts result.document.inference diff --git a/docs/custom_v1.md b/docs/custom_v1.md deleted file mode 100644 index 0d5c34c8..00000000 --- a/docs/custom_v1.md +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: Custom API Ruby (Deprecated) -category: 622b805aaec68102ea7fcbc2 -slug: ruby-api-builder-ocr -parentDoc: 6294d97ee723f1008d2ab28e ---- -> 🚧 This product is still supported, but is considered to be deprecated. If you are looking for the docTI API documentation, you can find it [here](https://developers.mindee.com/docs/ruby-generated-ocr). - -# Quick-Start - -```rb -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Initialize a custom endpoint for this product -custom_endpoint = mindee_client.create_endpoint( - account_name: 'my-account', - endpoint_name: 'my-endpoint' -) - -# Parse the file -result = mindee_client.parse( - input_source, - Mindee::Product::Custom::CustomV1, - endpoint: custom_endpoint -) - -# Print a full summary of the parsed data in RST format -puts result.document - -# Print the document-level parsed data -# puts result.document.inference.prediction - -# Looping over all prediction values -result.document.inference.prediction.fields.each do |field_name, field_data| - puts field_name - puts field_data.values - puts field_data.to_s -end -``` - -# Custom Endpoints - -You may have noticed in the previous step that in order to access a custom build, you will need to provide an account and an endpoint name at the very least. - -Although it is optional, the version number should match the latest version of your build in most use-cases. -If it is not set, it will default to "1". - - -# Field Types - -## Custom Fields - -### List Field - -A `ListField` is a special type of custom list that implements the following: - -* **confidence** (`Float`): the confidence score of the field prediction. -* **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it). -* **values** (`Array<`[ListFieldItem](#list-field-item)`>`): list of value fields - -Since the inner contents can vary, the value isn't accessed through a property, but rather through the following functions: -* **contents_list()** (`[Array, Hash, String, nil]`): returns a list of values for each element. -* **contents_str(separator:' ')** (`String`): returns a list of concatenated values, with an optional **separator** `String` between them. -* **to_s()**: returns a string representation of all values, with an empty space between each of them. - -#### List Field Item - -Values of `ListField`s are stored in a `ListFieldItem` structure, which is implemented as follows: -* **content** (`String`): extracted content of the prediction -* **confidence** (`Float`): the confidence score of the prediction -* **bounding_box** (`Quadrilateral`): 4 relative vertices corrdinates of a rectangle containing the word in the document. -* **polygon** (`Polygon`): vertices of a polygon containing the word. -* **page_id** (`Integer`): the ID of the page, is `nil` when at document-level. - -### Classification Field - -A `ClassificationField` is a special type of custom classification that implements the following: - -* **value** (`String`): the value of the classification. Corresponds to one of the values specified during training. -* **confidence** (`Float`): the confidence score of the field prediction. -* **to_s()**: returns a string representation of all values, with an empty space between each of them. - -# Attributes - -Custom builds always have access to at least two attributes: - -## Fields - -**fields** ({`String`=> [ListField](#list-field)}): - -```rb -puts result.document.inference.prediction.fields[:my_field].value -``` - -## Classifications - -**classifications** ({`String` => [ClassificationField](#classification-field)}): The purchase category among predefined classes. - -```js -console.log(result.document.inference.prediction.classifications["my-classification"].to_s); -``` - -# Questions? - -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/getting_started.md b/docs/getting_started.md index 796c128d..311e083a 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -1,5 +1,5 @@ --- -title: Ruby Getting Started +title: Getting Started category: 622b805aaec68102ea7fcbc2 slug: ruby-getting-started parentDoc: 6294d97ee723f1008d2ab28e @@ -9,10 +9,10 @@ This guide will help you get the most out of the Mindee Ruby client library to e ## Installation ### Requirements -The following Ruby versions are tested and supported: 2.6, 2.7, 3.0, 3.1, 3.2 +The following Ruby versions are tested and supported: 3.0, 3.1, 3.2, 3.3 ### Standard Installation -To quickly get started with the Ruby OCR SDK, Install by adding this line to your application's Gemfile: +To quickly get started with the Ruby Client Library, Install by adding this line to your application's Gemfile: ```shell gem 'mindee' @@ -75,7 +75,8 @@ Using Mindee's APIs can be broken down into the following steps: Let's take a deep dive into how this works. ## Initializing the Client -The `Client` automatically connects to the default endpoints for each product (or creates one with given parameters for Custom APIs). +The `Client` automatically connects to the default endpoints for each product (or creates one with given parameters for +Universal APIs). The `Client` requires your [API key](https://developers.mindee.com/docs/make-your-first-request#create-an-api-key). @@ -83,7 +84,7 @@ You can either pass these directly to the constructor or through environment var ### Pass the API key directly -```ruby +```rb # Init a new client and passing the key directly mindee_client = Mindee::Client.new(api_key: 'my-api-key') ``` @@ -97,7 +98,7 @@ MINDEE_API_KEY=my-api-key ``` Then in your code: -```ruby +```rb # Init a new client without an API key mindee_client = Mindee::Client.new ``` @@ -118,86 +119,33 @@ all supported types automatically. Once a document is loaded, interacting with it is done in exactly the same way, regardless of how it was loaded. -There are a few different ways of loading a document file, depending on your use case: - -* [Path](#path) -* [File Object](#file-object) -* [Base64](#base64) -* [Bytes](#bytes) -* [Urls](#url) - -### Path -Load from a file directly from disk. Requires an absolute path, as a string. - -```ruby -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Parse the file -result = mindee_client.parse( - input_source, - Mindee::Product::Invoice::InvoiceV4 -) -# Print a full summary of the parsed data in RST format -puts result.document -``` - -### File Object -A normal Ruby file object with a path. Must be in binary mode. +There are a few different ways of loading a document file, depending on your use case, you can use a: -**Note**: The original filename is required when calling the method. +* [File path](https://developers.mindee.com/docs/ruby-document-loading#loading-from-a-local-path): using the Mindee Client's `source_from_path()` method. +* [File Object](https://developers.mindee.com/docs/ruby-document-loading#loading-from-a-file-object): using the Mindee Client's `source_from_file()` method. +* [Base64 String](https://developers.mindee.com/docs/ruby-document-loading#loading-from-a-base64-encoded-string): using the Mindee Client's `source_from_b64string()` method. +* [Raw Byte sequence](https://developers.mindee.com/docs/ruby-document-loading#loading-from-raw-bytes): using the Mindee Client's `source_from_bytes()` method. +* [URL](https://developers.mindee.com/docs/ruby-document-loading#loading-by-url): using the Mindee Client's `source_from_url()` method. -```ruby -File.open(INVOICE_FILE, 'rb') do |fo| - input_source = mindee_client.source_from_file(fo, "invoice.jpg") -end +More details about file loading on the [dedicated page](https://developers.mindee.com/docs/ruby-document-loading). -result = mindee_client.parse( - input_source, - Mindee::Product::Invoice::InvoiceV4 -) -``` - -### Base64 -Load file contents from a base64-encoded string. - -**Note**: The original filename is required when calling the method. - -```ruby -b64_string = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLD...." - -input_source = mindee_client.source_from_b64string(b64_string, "receipt.jpg") - -result = mindee_client.parse( - input_source, - Mindee::Product::Receipt::ReceiptV5 -) -``` +## Sending a File +To send a file to the API, we need to specify how to process the document. +This will determine which API endpoint is used and how the API return will be handled internally by the library. -### Bytes -Requires raw bytes. +More specifically, we need to set a `Mindee::Product` class as the first parameter of the `create_endpoint` method. -**Note**: The original filename is required when calling the method. +This is because the `Endpoint`'s urls will be set according to it -```ruby -raw_bytes = b"%PDF-1.3\n%\xbf\xf7\xa2\xfe\n1 0 ob..." -input_source = mindee_client.source_from_bytes(raw_bytes, "invoice.pdf") +Each document type available in the library has its corresponding class, which inherit from the base +`Mindee::Parsing::Common::Predict` class. -result = mindee_client.parse( - input_source, - Mindee::Product::Invoice::InvoiceV4 -) -``` +This is detailed in each document-specific guide. -### URL -Requires an url as a String. +### Off-the-Shelf Documents +Simply setting the correct class is enough: -**Note**: the url must start with `https://`. -```ruby -input_source = mindee_client.source_from_url("https://www.example.com/invoice.pdf") +```rb result = mindee_client.parse( input_source, @@ -205,44 +153,42 @@ result = mindee_client.parse( ) ``` -## Sending a File -To send a file to the API, we need to specify how to process the document. -This will determine which API endpoint is used and how the API return will be handled internally by the library. - -More specifically, we need to set a `Mindee::Product` class as the first parameter of the `create_endpoint` method. - -This is because the `Endpoint`'s urls will be set according to it - -Each document type available in the library has its corresponding class, which inherit from the base `Mindee::Parsing::Common::Predict` class. -This is detailed in each document-specific guide. +#### Specific call method +Some products, such as InvoiceV4, ReceiptV5 & FinancialDocumentV1 support both asynchronous polling and synchronous +HTTP calls. +We recommend letting the client library decide which is better by default, but you can override the behavior by setting +the `enqueue` parameter to `true` or `false`. -### Off-the-Shelf Documents -Simply setting the correct class is enough: -```ruby +```rb result = mindee_client.parse( input_source, - Mindee::Product::Invoice::InvoiceV4 + Mindee::Product::Invoice::InvoiceV4, + enqueue: false ) ``` -### Custom Documents (docTI) +> 🚧 WARNING: this feature is not available for all products, and may result in errors if used inappropriately. +> Only use it if you are certain of what you are doing. +### Universal Documents (docTI) For custom documents, the endpoint to use must also be set, and it must take in an `endpoint_name`: -```ruby +```rb endpoint = mindee_client.create_endpoint(endpoint_name: 'wnine', account_name: 'my-account') -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, - Mindee::Product::Generated::GeneratedV1, + Mindee::Product::Universal::Universal, endpoint: endpoint ) ``` -This is because the `GeneratedV1` class is enough to handle the return processing, but the actual endpoint needs to be specified. +This is because the `Universal` class is enough to handle the return processing, but the actual endpoint needs to be +specified. ## Process the Result -The response object is common to all documents, including custom documents. The main properties are: +The response object is common to all documents, including custom documents (using the Universal product). The main +properties are: * `id` — Mindee ID of the document * `name` — Filename sent to the API @@ -261,7 +207,7 @@ It contains the data extracted from the entire document, all pages combined. It's possible to have the same field in various pages, but at the document level, only the highest confidence field data will be shown (this is all done automatically at the API level). -```ruby +```rb # as an object, complete pp result.document.inference.prediction @@ -279,7 +225,7 @@ All response objects have this property, regardless of the number of pages. Single page documents will have a single entry. Iteration is done like any Ruby array: -```ruby +```rb response.document.inference.pages.each do |page| # as an object, complete pp page.prediction @@ -290,36 +236,22 @@ end ``` #### Page Orientation -The orientation field is only available at the page level as it describes whether the page image should be rotated to be upright. +The orientation field is only available at the page level as it describes whether the page image should be rotated to +be upright. -If the page requires rotation for correct display, the orientation field gives a prediction among these 3 possible outputs: +If the page requires rotation for correct display, the orientation field gives a prediction among these 3 possible +outputs: * 0 degrees: the page is already upright * 90 degrees: the page must be rotated clockwise to be upright * 270 degrees: the page must be rotated counterclockwise to be upright -```ruby +```rb response.document.inference.pages.each do |page| puts page.orientation.value end ``` -## 🧪 Experimental Features - -### PDF repair - -Some PDF files might appear fine on your computer, but can be rejected by the server. -This _experimental_ feature attempts to fix the file's header information before sending it to the server. - -> ⚠️ **Warning**: This feature copies your file and then **alters** it. The original file will be left alone, but the copy might get partially corrupted, and improperly parsed as a result. Use at your own discretion. - -To enable it, simply set the `fix_pdf` flag to `true` during source creation: - -```rb -input_source = mindee_client.source_from_file(input_file, "name-of-my-file.ext", fix_pdf: true) -``` - -Note: This only works for local files, files sent by URL will not be processed. ## Questions? [Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/global_products.md b/docs/global_products.md new file mode 100644 index 00000000..05ddff77 --- /dev/null +++ b/docs/global_products.md @@ -0,0 +1,6 @@ +--- +title: Global Products +category: 622b805aaec68102ea7fcbc2 +slug: ruby-global-products +parentDoc: 6294d97ee723f1008d2ab28e +--- diff --git a/docs/barcode_reader_v1.md b/docs/global_products/barcode_reader_v1.md similarity index 66% rename from docs/barcode_reader_v1.md rename to docs/global_products/barcode_reader_v1.md index 94777528..bf7078b0 100644 --- a/docs/barcode_reader_v1.md +++ b/docs/global_products/barcode_reader_v1.md @@ -1,16 +1,34 @@ --- -title: Barcode Reader OCR Ruby +title: Ruby Client Library - Barcode Reader category: 622b805aaec68102ea7fcbc2 slug: ruby-barcode-reader-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Barcode Reader API](https://platform.mindee.com/mindee/barcode_reader). +The Ruby Client Library supports the [Barcode Reader API](https://platform.mindee.com/mindee/barcode_reader). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/barcode_reader/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `barcode_reader` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ❌ No | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🌐 Global | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/barcode_reader/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Barcode Reader sample](https://github.com/mindee/client-lib-test-data/blob/main/products/barcode_reader/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -30,7 +48,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -70,12 +87,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -90,7 +107,7 @@ The following fields are extracted for Barcode Reader V1: **codes_1d** (Array<[StringField](#string-field)>): List of decoded 1D barcodes. ```rb -for codes_1d_elem in result.document.inference.prediction.codes_1d do +result.document.inference.prediction.codes_1d do |codes_1d_elem| puts codes_1d_elem.value end ``` @@ -99,7 +116,7 @@ end **codes_2d** (Array<[StringField](#string-field)>): List of decoded 2D barcodes. ```rb -for codes_2d_elem in result.document.inference.prediction.codes_2d do +result.document.inference.prediction.codes_2d do |codes_2d_elem| puts codes_2d_elem.value end ``` diff --git a/docs/bill_of_lading_v1.md b/docs/global_products/bill_of_lading_v1.md similarity index 80% rename from docs/bill_of_lading_v1.md rename to docs/global_products/bill_of_lading_v1.md index 658434f6..b8206eb7 100644 --- a/docs/bill_of_lading_v1.md +++ b/docs/global_products/bill_of_lading_v1.md @@ -1,16 +1,42 @@ --- -title: Bill of Lading OCR Ruby +title: Ruby Client Library - Bill of Lading category: 622b805aaec68102ea7fcbc2 slug: ruby-bill-of-lading-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Bill of Lading API](https://platform.mindee.com/mindee/bill_of_lading). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bill_of_lading/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Bill of Lading API](https://platform.mindee.com/mindee/bill_of_lading). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `bill_of_lading` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bill_of_lading/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Bill of Lading sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bill_of_lading/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::BillOfLading::BillOfLadingV1 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -89,18 +114,18 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. @@ -110,14 +135,15 @@ The text field `StringField` only has one constraint: it's **value** is a `Strin ## Specific Fields Fields which are specific to this product; they are not used in any other product. -### Carrier Field -The shipping company responsible for transporting the goods. +### Shipper Field +The party responsible for shipping the goods. -A `BillOfLadingV1Carrier` implements the following attributes: +A `BillOfLadingV1Shipper` implements the following attributes: -* `name` (String): The name of the carrier. -* `professional_number` (String): The professional number of the carrier. -* `scac` (String): The Standard Carrier Alpha Code (SCAC) of the carrier. +* `address` (String): The address of the shipper. +* `email` (String): The email of the shipper. +* `name` (String): The name of the shipper. +* `phone` (String): The phone number of the shipper. Fields which are specific to this product; they are not used in any other product. ### Consignee Field @@ -131,19 +157,6 @@ A `BillOfLadingV1Consignee` implements the following attributes: * `phone` (String): The phone number of the consignee. Fields which are specific to this product; they are not used in any other product. -### Items Field -The goods being shipped. - -A `BillOfLadingV1CarrierItem` implements the following attributes: - -* `description` (String): A description of the item. -* `gross_weight` (Float): The gross weight of the item. -* `measurement` (Float): The measurement of the item. -* `measurement_unit` (String): The unit of measurement for the measurement. -* `quantity` (Float): The quantity of the item being shipped. -* `weight_unit` (String): The unit of measurement for weights. -Fields which are specific to this product; they are not used in any other product. - ### Notify Party Field The party to be notified of the arrival of the goods. @@ -155,15 +168,27 @@ A `BillOfLadingV1NotifyParty` implements the following attributes: * `phone` (String): The phone number of the notify party. Fields which are specific to this product; they are not used in any other product. -### Shipper Field -The party responsible for shipping the goods. +### Carrier Field +The shipping company responsible for transporting the goods. -A `BillOfLadingV1Shipper` implements the following attributes: +A `BillOfLadingV1Carrier` implements the following attributes: -* `address` (String): The address of the shipper. -* `email` (String): The email of the shipper. -* `name` (String): The name of the shipper. -* `phone` (String): The phone number of the shipper. +* `name` (String): The name of the carrier. +* `professional_number` (String): The professional number of the carrier. +* `scac` (String): The Standard Carrier Alpha Code (SCAC) of the carrier. +Fields which are specific to this product; they are not used in any other product. + +### Items Field +The goods being shipped. + +A `BillOfLadingV1CarrierItem` implements the following attributes: + +* `description` (String): A description of the item. +* `gross_weight` (Float): The gross weight of the item. +* `measurement` (Float): The measurement of the item. +* `measurement_unit` (String): The unit of measurement for the measurement. +* `quantity` (Float): The quantity of the item being shipped. +* `weight_unit` (String): The unit of measurement for weights. # Attributes The following fields are extracted for Bill of Lading V1: @@ -186,7 +211,7 @@ puts result.document.inference.prediction.carrier.value **carrier_items** (Array<[BillOfLadingV1CarrierItem](#items-field)>): The goods being shipped. ```rb -for carrier_items_elem in result.document.inference.prediction.carrier_items do +result.document.inference.prediction.carrier_items do |carrier_items_elem| puts carrier_items_elem.value end ``` diff --git a/docs/business_card_v1.md b/docs/global_products/business_card_v1.md similarity index 70% rename from docs/business_card_v1.md rename to docs/global_products/business_card_v1.md index bb770835..d0ddcd1f 100644 --- a/docs/business_card_v1.md +++ b/docs/global_products/business_card_v1.md @@ -1,16 +1,42 @@ --- -title: Business Card OCR Ruby +title: Ruby Client Library - Business Card category: 622b805aaec68102ea7fcbc2 slug: ruby-business-card-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Business Card API](https://platform.mindee.com/mindee/business_card). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/business_card/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Business Card API](https://platform.mindee.com/mindee/business_card). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `business_card` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/business_card/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Business Card sample](https://github.com/mindee/client-lib-test-data/blob/main/products/business_card/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::BusinessCard::BusinessCardV1 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -70,12 +95,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -153,7 +178,7 @@ puts result.document.inference.prediction.phone_number.value **social_media** (Array<[StringField](#string-field)>): The social media profiles of the person or company. ```rb -for social_media_elem in result.document.inference.prediction.social_media do +result.document.inference.prediction.social_media do |social_media_elem| puts social_media_elem.value end ``` diff --git a/docs/cropper_v1.md b/docs/global_products/cropper_v1.md similarity index 63% rename from docs/cropper_v1.md rename to docs/global_products/cropper_v1.md index 754555a4..8591a34e 100644 --- a/docs/cropper_v1.md +++ b/docs/global_products/cropper_v1.md @@ -1,16 +1,34 @@ --- -title: Cropper OCR Ruby +title: Ruby Client Library - Cropper category: 622b805aaec68102ea7fcbc2 slug: ruby-cropper-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Cropper API](https://platform.mindee.com/mindee/cropper). +The Ruby Client Library supports the [Cropper API](https://platform.mindee.com/mindee/cropper). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/cropper/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `cropper` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ❌ No | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🌐 Global | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/cropper/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Cropper sample](https://github.com/mindee/client-lib-test-data/blob/main/products/cropper/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -27,7 +45,6 @@ result = mindee_client.parse( # Print a full summary of the parsed data in RST format puts result.document - ``` **Output (RST):** @@ -63,21 +80,23 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Position Field -The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, **polygon** and **page_id**. On top of these, it has access to: +The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, +**polygon** and **page_id**. On top of these, it has access to: -* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond canvas). +* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond +canvas). * **quadrangle** (`Mindee::Geometry::Quadrilateral`): a free polygon made up of four points. ## Page-Level Fields @@ -90,14 +109,14 @@ The following fields are extracted for Cropper V1: [📄](#page-level-fields "This field is only present on individual pages.")**cropping** (Array<[PositionField](#position-field)>): List of documents found in the image. ```rb -for page in result.document.inference.pages do - for cropping_elem in page.prediction.cropping do - puts cropping_elem.polygon.to_s + result.document.inference.pages do |page| + page.prediction.cropping do |cropping_elem| + puts cropping_elem.polygon.to_s puts cropping_elem.quadrangle.to_s puts cropping_elem.rectangle.to_s puts cropping_elem.boundingBox.to_s + end end -end ``` # Questions? diff --git a/docs/delivery_notes_v1.md b/docs/global_products/delivery_notes_v1.md similarity index 69% rename from docs/delivery_notes_v1.md rename to docs/global_products/delivery_notes_v1.md index 88543d25..16e18d98 100644 --- a/docs/delivery_notes_v1.md +++ b/docs/global_products/delivery_notes_v1.md @@ -1,16 +1,42 @@ --- -title: Delivery note OCR Ruby +title: Ruby Client Library - Delivery note category: 622b805aaec68102ea7fcbc2 slug: ruby-delivery-note-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Delivery note API](https://platform.mindee.com/mindee/delivery_notes). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/delivery_notes/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Delivery note API](https://platform.mindee.com/mindee/delivery_notes). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `delivery_notes` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/delivery_notes/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Delivery note sample](https://github.com/mindee/client-lib-test-data/blob/main/products/delivery_notes/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::DeliveryNote::DeliveryNoteV1 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -65,12 +90,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -80,7 +105,7 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`). ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. diff --git a/docs/driver_license_v1.md b/docs/global_products/driver_license_v1.md similarity index 73% rename from docs/driver_license_v1.md rename to docs/global_products/driver_license_v1.md index 8c31e285..34346eba 100644 --- a/docs/driver_license_v1.md +++ b/docs/global_products/driver_license_v1.md @@ -1,16 +1,42 @@ --- -title: Driver License OCR Ruby +title: Ruby Client Library - Driver License category: 622b805aaec68102ea7fcbc2 slug: ruby-driver-license-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Driver License API](https://platform.mindee.com/mindee/driver_license). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Driver License API](https://platform.mindee.com/mindee/driver_license). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `driver_license` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Driver License sample](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::DriverLicense::DriverLicenseV1 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -71,18 +96,18 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. diff --git a/docs/expense_receipts_v5.md b/docs/global_products/expense_receipts_v5.md similarity index 80% rename from docs/expense_receipts_v5.md rename to docs/global_products/expense_receipts_v5.md index 3dc12e4d..b5ee5f37 100644 --- a/docs/expense_receipts_v5.md +++ b/docs/global_products/expense_receipts_v5.md @@ -1,41 +1,42 @@ --- -title: Receipt OCR Ruby +title: Ruby Client Library - Receipt category: 622b805aaec68102ea7fcbc2 slug: ruby-receipt-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Receipt API](https://platform.mindee.com/mindee/expense_receipts). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/expense_receipts/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Receipt API](https://platform.mindee.com/mindee/expense_receipts). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `expense_receipts` | +> | Recommended Version | `v5.3` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/expense_receipts/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Receipt sample](https://github.com/mindee/client-lib-test-data/blob/main/products/expense_receipts/default_sample.jpg?raw=true) # Quick-Start ```rb -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Parse the file -result = mindee_client.parse( - input_source, - Mindee::Product::Receipt::ReceiptV5 -) - -# Print a full summary of the parsed data in RST format -puts result.document - -# Print the document-level parsed data -# puts result.document.inference.prediction +# +# Install the Ruby client library by running: +# gem install mindee +# -``` - -You can also call this product asynchronously: - -```rb require 'mindee' # Init a new client @@ -45,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::Receipt::ReceiptV5 ) @@ -55,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -145,12 +145,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -161,26 +161,30 @@ The amount field `AmountField` only has one constraint: its **value** is a `Floa ### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **page_id**. +The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements +**value**, **confidence** and **page_id**. > Note: a classification field's `value is always a `String`. ### Company Registration Field -Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the following: +Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the +following: * **type** (`String`): the type of company. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. ### Locale Field -The locale field `LocaleField` only implements the **value**, **confidence** and **page_id** base `Field` attributes, but it comes with its own: +The locale field `LocaleField` only implements the **value**, **confidence** and **page_id** base `Field` attributes, +but it comes with its own: * **language** (`String`): ISO 639-1 language code (e.g.: `en` for English). Can be `nil`. -* **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`. +* **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`. * **currency** (`String`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `nil`. ### String Field @@ -194,10 +198,12 @@ Aside from the basic `Field` attributes, the tax field `TaxField` also implement * **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`. * **base** (`Float`): base amount used for the tax. Can be `nil`. -> Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure. +> Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like +structure. #### Taxes (Array) -The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several objects, it has access to a custom `to_s` method that can render a `TaxField` object as a table line. +The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several +objects, it has access to a custom `to_s` method that can render a `TaxField` object as a table line. ## Specific Fields Fields which are specific to this product; they are not used in any other product. @@ -254,7 +260,7 @@ puts result.document.inference.prediction.document_type.value **line_items** (Array<[ReceiptV5LineItem](#line-items-field)>): List of line item details. ```rb -for line_items_elem in result.document.inference.prediction.line_items do +result.document.inference.prediction.line_items do |line_items_elem| puts line_items_elem.value end ``` @@ -298,7 +304,7 @@ puts result.document.inference.prediction.supplier_address.value **supplier_company_registrations** (Array<[CompanyRegistrationField](#company-registration-field)>): List of company registrations associated to the supplier. ```rb -for supplier_company_registrations_elem in result.document.inference.prediction.supplier_company_registrations do +result.document.inference.prediction.supplier_company_registrations do |supplier_company_registrations_elem| puts supplier_company_registrations_elem.value end ``` @@ -321,7 +327,7 @@ puts result.document.inference.prediction.supplier_phone_number.value **taxes** (Array<[TaxField](#taxes-field)>): List of tax lines information. ```rb -for taxes_elem in result.document.inference.prediction.taxes do +result.document.inference.prediction.taxes do |taxes_elem| puts taxes_elem.value end ``` diff --git a/docs/financial_document_v1.md b/docs/global_products/financial_document_v1.md similarity index 84% rename from docs/financial_document_v1.md rename to docs/global_products/financial_document_v1.md index 53786c2e..870f16bd 100644 --- a/docs/financial_document_v1.md +++ b/docs/global_products/financial_document_v1.md @@ -1,41 +1,42 @@ --- -title: Financial Document OCR Ruby +title: Ruby Client Library - Financial Document category: 622b805aaec68102ea7fcbc2 slug: ruby-financial-document-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Financial Document API](https://platform.mindee.com/mindee/financial_document). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/financial_document/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Financial Document API](https://platform.mindee.com/mindee/financial_document). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `financial_document` | +> | Recommended Version | `v1.11` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/financial_document/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Financial Document sample](https://github.com/mindee/client-lib-test-data/blob/main/products/financial_document/default_sample.jpg?raw=true) # Quick-Start ```rb -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Parse the file -result = mindee_client.parse( - input_source, - Mindee::Product::FinancialDocument::FinancialDocumentV1 -) - -# Print a full summary of the parsed data in RST format -puts result.document - -# Print the document-level parsed data -# puts result.document.inference.prediction +# +# Install the Ruby client library by running: +# gem install mindee +# -``` - -You can also call this product asynchronously: - -```rb require 'mindee' # Init a new client @@ -45,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FinancialDocument::FinancialDocumentV1 ) @@ -55,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -181,12 +181,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -197,30 +197,35 @@ The amount field `AmountField` only has one constraint: its **value** is a `Floa ### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **page_id**. +The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements +**value**, **confidence** and **page_id**. > Note: a classification field's `value is always a `String`. ### Company Registration Field -Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the following: +Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the +following: * **type** (`String`): the type of company. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. ### Locale Field -The locale field `LocaleField` only implements the **value**, **confidence** and **page_id** base `Field` attributes, but it comes with its own: +The locale field `LocaleField` only implements the **value**, **confidence** and **page_id** base `Field` attributes, +but it comes with its own: * **language** (`String`): ISO 639-1 language code (e.g.: `en` for English). Can be `nil`. -* **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`. +* **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`. * **currency** (`String`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `nil`. ### Payment Details Field -Aside from the basic `Field` attributes, the payment details field `PaymentDetailsField` also implements the following: +Aside from the basic `Field` attributes, the payment details field `PaymentDetailsField` also implements the +following: * **account_number** (`String`): number of an account, expressed as a string. Can be `nil`. * **iban** (`String`): International Bank Account Number. Can be `nil`. @@ -238,10 +243,12 @@ Aside from the basic `Field` attributes, the tax field `TaxField` also implement * **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`. * **base** (`Float`): base amount used for the tax. Can be `nil`. -> Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure. +> Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like +structure. #### Taxes (Array) -The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several objects, it has access to a custom `to_s` method that can render a `TaxField` object as a table line. +The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several +objects, it has access to a custom `to_s` method that can render a `TaxField` object as a table line. ## Specific Fields Fields which are specific to this product; they are not used in any other product. @@ -298,7 +305,7 @@ puts result.document.inference.prediction.customer_address.value **customer_company_registrations** (Array<[CompanyRegistrationField](#company-registration-field)>): List of company registrations associated to the customer. ```rb -for customer_company_registrations_elem in result.document.inference.prediction.customer_company_registrations do +result.document.inference.prediction.customer_company_registrations do |customer_company_registrations_elem| puts customer_company_registrations_elem.value end ``` @@ -362,7 +369,7 @@ puts result.document.inference.prediction.invoice_number.value **line_items** (Array<[FinancialDocumentV1LineItem](#line-items-field)>): List of line item details. ```rb -for line_items_elem in result.document.inference.prediction.line_items do +result.document.inference.prediction.line_items do |line_items_elem| puts line_items_elem.value end ``` @@ -399,7 +406,7 @@ puts result.document.inference.prediction.receipt_number.value **reference_numbers** (Array<[StringField](#string-field)>): List of Reference numbers, including PO number. ```rb -for reference_numbers_elem in result.document.inference.prediction.reference_numbers do +result.document.inference.prediction.reference_numbers do |reference_numbers_elem| puts reference_numbers_elem.value end ``` @@ -436,7 +443,7 @@ puts result.document.inference.prediction.supplier_address.value **supplier_company_registrations** (Array<[CompanyRegistrationField](#company-registration-field)>): List of company registrations associated to the supplier. ```rb -for supplier_company_registrations_elem in result.document.inference.prediction.supplier_company_registrations do +result.document.inference.prediction.supplier_company_registrations do |supplier_company_registrations_elem| puts supplier_company_registrations_elem.value end ``` @@ -459,11 +466,11 @@ puts result.document.inference.prediction.supplier_name.value **supplier_payment_details** (Array<[PaymentDetailsField](#payment-details-field)>): List of payment details associated to the supplier. ```rb -for supplier_payment_details_elem in result.document.inference.prediction.supplier_payment_details do +result.document.inference.prediction.supplier_payment_details do |supplier_payment_details_elem| puts supplier_payment_details_elem.value - puts supplier_payment_details_elem.rate - puts supplier_payment_details_elem.code - puts supplier_payment_details_elem.basis + puts supplier_payment_details_elem.rate + puts supplier_payment_details_elem.code + puts supplier_payment_details_elem.basis end ``` @@ -485,7 +492,7 @@ puts result.document.inference.prediction.supplier_website.value **taxes** (Array<[TaxField](#taxes-field)>): List of tax lines information. ```rb -for taxes_elem in result.document.inference.prediction.taxes do +result.document.inference.prediction.taxes do |taxes_elem| puts taxes_elem.value end ``` diff --git a/docs/international_id_v2.md b/docs/global_products/international_id_v2.md similarity index 75% rename from docs/international_id_v2.md rename to docs/global_products/international_id_v2.md index 03edbf42..ba7d2c3f 100644 --- a/docs/international_id_v2.md +++ b/docs/global_products/international_id_v2.md @@ -1,16 +1,42 @@ --- -title: International ID OCR Ruby +title: Ruby Client Library - International ID category: 622b805aaec68102ea7fcbc2 slug: ruby-international-id-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [International ID API](https://platform.mindee.com/mindee/international_id). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/international_id/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [International ID API](https://platform.mindee.com/mindee/international_id). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `international_id` | +> | Recommended Version | `v2.1` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/international_id/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![International ID sample](https://github.com/mindee/client-lib-test-data/blob/main/products/international_id/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::InternationalId::InternationalIdV2 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -76,24 +101,25 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **page_id**. +The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements +**value**, **confidence** and **page_id**. > Note: a classification field's `value is always a `String`. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. @@ -164,7 +190,7 @@ puts result.document.inference.prediction.expiry_date.value **given_names** (Array<[StringField](#string-field)>): The list of the document holder's given names. ```rb -for given_names_elem in result.document.inference.prediction.given_names do +result.document.inference.prediction.given_names do |given_names_elem| puts given_names_elem.value end ``` @@ -229,7 +255,7 @@ puts result.document.inference.prediction.state_of_issue.value **surnames** (Array<[StringField](#string-field)>): The list of the document holder's family names. ```rb -for surnames_elem in result.document.inference.prediction.surnames do +result.document.inference.prediction.surnames do |surnames_elem| puts surnames_elem.value end ``` diff --git a/docs/invoice_splitter_v1.md b/docs/global_products/invoice_splitter_v1.md similarity index 59% rename from docs/invoice_splitter_v1.md rename to docs/global_products/invoice_splitter_v1.md index e890db8f..9e4f2b5b 100644 --- a/docs/invoice_splitter_v1.md +++ b/docs/global_products/invoice_splitter_v1.md @@ -2,11 +2,30 @@ title: Invoice Splitter API Ruby category: 622b805aaec68102ea7fcbc2 slug: ruby-invoice-splitter-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Invoice Splitter API](https://platform.mindee.com/mindee/invoice_splitter). - -Using [this sample](https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/default_sample.pdf), we are going to illustrate how to detect the pages of multiple invoices within the same document. +The Ruby Client Library supports the [Invoice Splitter API](https://platform.mindee.com/mindee/invoice_splitter). + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ |--------------------| +> | Endpoint Name | `invoice_splitter` | +> | Recommended Version | `v1.2` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- |---------------| +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + +Using [this sample](https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/default_sample.pdf), we are going to illustrate detect the pages of multiple invoices within the same document using the +Ruby Client Library. # Quick-Start @@ -19,7 +38,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') # Load a file from disk input_source = mindee_client.source_from_path('/path/to/the/file.ext') -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::InvoiceSplitter::InvoiceSplitterV1 ) @@ -79,7 +98,7 @@ The following fields are extracted for Invoice Splitter V1: **invoice_page_groups** (Array<[InvoiceSplitterV1PageGroup](#invoice-splitter-v1-page-group)>): List of page indexes that belong to the same invoice in the PDF. ```rb -for invoice_page_groups_elem in result.document.inference.prediction.invoice_page_groups do +result.document.inference.prediction.invoice_page_groups.each do |invoice_page_groups_elem| puts invoice_page_groups_elem.page_indexes.join(', ') end ``` diff --git a/docs/invoices_v4.md b/docs/global_products/invoices_v4.md similarity index 82% rename from docs/invoices_v4.md rename to docs/global_products/invoices_v4.md index c624a202..3ae7acf9 100644 --- a/docs/invoices_v4.md +++ b/docs/global_products/invoices_v4.md @@ -1,41 +1,42 @@ --- -title: Invoice OCR Ruby +title: Ruby Client Library - Invoice category: 622b805aaec68102ea7fcbc2 slug: ruby-invoice-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Invoice API](https://platform.mindee.com/mindee/invoices). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/invoices/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Invoice API](https://platform.mindee.com/mindee/invoices). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `invoices` | +> | Recommended Version | `v4.9` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/invoices/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Invoice sample](https://github.com/mindee/client-lib-test-data/blob/main/products/invoices/default_sample.jpg?raw=true) # Quick-Start ```rb -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Parse the file -result = mindee_client.parse( - input_source, - Mindee::Product::Invoice::InvoiceV4 -) - -# Print a full summary of the parsed data in RST format -puts result.document - -# Print the document-level parsed data -# puts result.document.inference.prediction +# +# Install the Ruby client library by running: +# gem install mindee +# -``` - -You can also call this product asynchronously: - -```rb require 'mindee' # Init a new client @@ -45,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::Invoice::InvoiceV4 ) @@ -55,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -169,12 +169,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -185,30 +185,35 @@ The amount field `AmountField` only has one constraint: its **value** is a `Floa ### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **page_id**. +The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements +**value**, **confidence** and **page_id**. > Note: a classification field's `value is always a `String`. ### Company Registration Field -Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the following: +Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the +following: * **type** (`String`): the type of company. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. ### Locale Field -The locale field `LocaleField` only implements the **value**, **confidence** and **page_id** base `Field` attributes, but it comes with its own: +The locale field `LocaleField` only implements the **value**, **confidence** and **page_id** base `Field` attributes, +but it comes with its own: * **language** (`String`): ISO 639-1 language code (e.g.: `en` for English). Can be `nil`. -* **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`. +* **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`. * **currency** (`String`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `nil`. ### Payment Details Field -Aside from the basic `Field` attributes, the payment details field `PaymentDetailsField` also implements the following: +Aside from the basic `Field` attributes, the payment details field `PaymentDetailsField` also implements the +following: * **account_number** (`String`): number of an account, expressed as a string. Can be `nil`. * **iban** (`String`): International Bank Account Number. Can be `nil`. @@ -226,10 +231,12 @@ Aside from the basic `Field` attributes, the tax field `TaxField` also implement * **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`. * **base** (`Float`): base amount used for the tax. Can be `nil`. -> Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure. +> Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like +structure. #### Taxes (Array) -The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several objects, it has access to a custom `to_s` method that can render a `TaxField` object as a table line. +The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several +objects, it has access to a custom `to_s` method that can render a `TaxField` object as a table line. ## Specific Fields Fields which are specific to this product; they are not used in any other product. @@ -269,7 +276,7 @@ puts result.document.inference.prediction.customer_address.value **customer_company_registrations** (Array<[CompanyRegistrationField](#company-registration-field)>): List of company registrations associated to the customer. ```rb -for customer_company_registrations_elem in result.document.inference.prediction.customer_company_registrations do +result.document.inference.prediction.customer_company_registrations do |customer_company_registrations_elem| puts customer_company_registrations_elem.value end ``` @@ -324,7 +331,7 @@ puts result.document.inference.prediction.invoice_number.value **line_items** (Array<[InvoiceV4LineItem](#line-items-field)>): List of line item details. ```rb -for line_items_elem in result.document.inference.prediction.line_items do +result.document.inference.prediction.line_items do |line_items_elem| puts line_items_elem.value end ``` @@ -354,7 +361,7 @@ puts result.document.inference.prediction.po_number.value **reference_numbers** (Array<[StringField](#string-field)>): List of Reference numbers, including PO number. ```rb -for reference_numbers_elem in result.document.inference.prediction.reference_numbers do +result.document.inference.prediction.reference_numbers do |reference_numbers_elem| puts reference_numbers_elem.value end ``` @@ -377,7 +384,7 @@ puts result.document.inference.prediction.supplier_address.value **supplier_company_registrations** (Array<[CompanyRegistrationField](#company-registration-field)>): List of company registrations associated to the supplier. ```rb -for supplier_company_registrations_elem in result.document.inference.prediction.supplier_company_registrations do +result.document.inference.prediction.supplier_company_registrations do |supplier_company_registrations_elem| puts supplier_company_registrations_elem.value end ``` @@ -400,11 +407,11 @@ puts result.document.inference.prediction.supplier_name.value **supplier_payment_details** (Array<[PaymentDetailsField](#payment-details-field)>): List of payment details associated to the supplier. ```rb -for supplier_payment_details_elem in result.document.inference.prediction.supplier_payment_details do +result.document.inference.prediction.supplier_payment_details do |supplier_payment_details_elem| puts supplier_payment_details_elem.value - puts supplier_payment_details_elem.rate - puts supplier_payment_details_elem.code - puts supplier_payment_details_elem.basis + puts supplier_payment_details_elem.rate + puts supplier_payment_details_elem.code + puts supplier_payment_details_elem.basis end ``` @@ -426,7 +433,7 @@ puts result.document.inference.prediction.supplier_website.value **taxes** (Array<[TaxField](#taxes-field)>): List of tax line details. ```rb -for taxes_elem in result.document.inference.prediction.taxes do +result.document.inference.prediction.taxes do |taxes_elem| puts taxes_elem.value end ``` diff --git a/docs/multi_receipts_detector_v1.md b/docs/global_products/multi_receipts_detector_v1.md similarity index 66% rename from docs/multi_receipts_detector_v1.md rename to docs/global_products/multi_receipts_detector_v1.md index adb57c8c..650be0a7 100644 --- a/docs/multi_receipts_detector_v1.md +++ b/docs/global_products/multi_receipts_detector_v1.md @@ -1,16 +1,34 @@ --- -title: Multi Receipts Detector OCR Ruby +title: Ruby Client Library - Multi Receipts Detector category: 622b805aaec68102ea7fcbc2 slug: ruby-multi-receipts-detector-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Multi Receipts Detector API](https://platform.mindee.com/mindee/multi_receipts_detector). +The Ruby Client Library supports the [Multi Receipts Detector API](https://platform.mindee.com/mindee/multi_receipts_detector). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/multi_receipts_detector/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `multi_receipts_detector` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ❌ No | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🌐 Global | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/multi_receipts_detector/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Multi Receipts Detector sample](https://github.com/mindee/client-lib-test-data/blob/main/products/multi_receipts_detector/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -30,7 +48,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -76,21 +93,23 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Position Field -The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, **polygon** and **page_id**. On top of these, it has access to: +The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, +**polygon** and **page_id**. On top of these, it has access to: -* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond canvas). +* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond +canvas). * **quadrangle** (`Mindee::Geometry::Quadrilateral`): a free polygon made up of four points. # Attributes @@ -100,11 +119,11 @@ The following fields are extracted for Multi Receipts Detector V1: **receipts** (Array<[PositionField](#position-field)>): Positions of the receipts on the document. ```rb -for receipts_elem in result.document.inference.prediction.receipts do +result.document.inference.prediction.receipts do |receipts_elem| puts receipts_elem.polygon.to_s - puts receipts_elem.quadrangle.to_s - puts receipts_elem.rectangle.to_s - puts receipts_elem.boundingBox.to_s + puts receipts_elem.quadrangle.to_s + puts receipts_elem.rectangle.to_s + puts receipts_elem.boundingBox.to_s end ``` diff --git a/docs/nutrition_facts_v1.md b/docs/global_products/nutrition_facts_v1.md similarity index 87% rename from docs/nutrition_facts_v1.md rename to docs/global_products/nutrition_facts_v1.md index 59c5a88f..17b40638 100644 --- a/docs/nutrition_facts_v1.md +++ b/docs/global_products/nutrition_facts_v1.md @@ -1,16 +1,42 @@ --- -title: Nutrition Facts Label OCR Ruby +title: Ruby Client Library - Nutrition Facts Label category: 622b805aaec68102ea7fcbc2 slug: ruby-nutrition-facts-label-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Nutrition Facts Label API](https://platform.mindee.com/mindee/nutrition_facts). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/nutrition_facts/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Nutrition Facts Label API](https://platform.mindee.com/mindee/nutrition_facts). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `nutrition_facts` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/nutrition_facts/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Nutrition Facts Label sample](https://github.com/mindee/client-lib-test-data/blob/main/products/nutrition_facts/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -119,12 +144,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -136,14 +161,13 @@ The amount field `AmountField` only has one constraint: its **value** is a `Floa ## Specific Fields Fields which are specific to this product; they are not used in any other product. -### Added Sugars Field -The amount of added sugars in the product. +### Serving Size Field +The size of a single serving of the product. -A `NutritionFactsLabelV1AddedSugar` implements the following attributes: +A `NutritionFactsLabelV1ServingSize` implements the following attributes: -* `daily_value` (Float): DVs are the recommended amounts of added sugars to consume or not to exceed each day. -* `per_100g` (Float): The amount of added sugars per 100g of the product. -* `per_serving` (Float): The amount of added sugars per serving of the product. +* `amount` (Float): The amount of a single serving. +* `unit` (String): The unit for the amount of a single serving. Fields which are specific to this product; they are not used in any other product. ### Calories Field @@ -156,46 +180,14 @@ A `NutritionFactsLabelV1Calorie` implements the following attributes: * `per_serving` (Float): The amount of calories per serving of the product. Fields which are specific to this product; they are not used in any other product. -### Cholesterol Field -The amount of cholesterol in the product. - -A `NutritionFactsLabelV1Cholesterol` implements the following attributes: - -* `daily_value` (Float): DVs are the recommended amounts of cholesterol to consume or not to exceed each day. -* `per_100g` (Float): The amount of cholesterol per 100g of the product. -* `per_serving` (Float): The amount of cholesterol per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### Dietary Fiber Field -The amount of dietary fiber in the product. - -A `NutritionFactsLabelV1DietaryFiber` implements the following attributes: - -* `daily_value` (Float): DVs are the recommended amounts of dietary fiber to consume or not to exceed each day. -* `per_100g` (Float): The amount of dietary fiber per 100g of the product. -* `per_serving` (Float): The amount of dietary fiber per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### nutrients Field -The amount of nutrients in the product. - -A `NutritionFactsLabelV1Nutrient` implements the following attributes: - -* `daily_value` (Float): DVs are the recommended amounts of nutrients to consume or not to exceed each day. -* `name` (String): The name of nutrients of the product. -* `per_100g` (Float): The amount of nutrients per 100g of the product. -* `per_serving` (Float): The amount of nutrients per serving of the product. -* `unit` (String): The unit of measurement for the amount of nutrients. -Fields which are specific to this product; they are not used in any other product. - -### Protein Field -The amount of protein in the product. +### Total Fat Field +The total amount of fat in the product. -A `NutritionFactsLabelV1Protein` implements the following attributes: +A `NutritionFactsLabelV1TotalFat` implements the following attributes: -* `daily_value` (Float): DVs are the recommended amounts of protein to consume or not to exceed each day. -* `per_100g` (Float): The amount of protein per 100g of the product. -* `per_serving` (Float): The amount of protein per serving of the product. +* `daily_value` (Float): DVs are the recommended amounts of total fat to consume or not to exceed each day. +* `per_100g` (Float): The amount of total fat per 100g of the product. +* `per_serving` (Float): The amount of total fat per serving of the product. Fields which are specific to this product; they are not used in any other product. ### Saturated Fat Field @@ -208,24 +200,24 @@ A `NutritionFactsLabelV1SaturatedFat` implements the following attributes: * `per_serving` (Float): The amount of saturated fat per serving of the product. Fields which are specific to this product; they are not used in any other product. -### Serving Size Field -The size of a single serving of the product. +### Trans Fat Field +The amount of trans fat in the product. -A `NutritionFactsLabelV1ServingSize` implements the following attributes: +A `NutritionFactsLabelV1TransFat` implements the following attributes: -* `amount` (Float): The amount of a single serving. -* `unit` (String): The unit for the amount of a single serving. +* `daily_value` (Float): DVs are the recommended amounts of trans fat to consume or not to exceed each day. +* `per_100g` (Float): The amount of trans fat per 100g of the product. +* `per_serving` (Float): The amount of trans fat per serving of the product. Fields which are specific to this product; they are not used in any other product. -### sodium Field -The amount of sodium in the product. +### Cholesterol Field +The amount of cholesterol in the product. -A `NutritionFactsLabelV1Sodium` implements the following attributes: +A `NutritionFactsLabelV1Cholesterol` implements the following attributes: -* `daily_value` (Float): DVs are the recommended amounts of sodium to consume or not to exceed each day. -* `per_100g` (Float): The amount of sodium per 100g of the product. -* `per_serving` (Float): The amount of sodium per serving of the product. -* `unit` (String): The unit of measurement for the amount of sodium. +* `daily_value` (Float): DVs are the recommended amounts of cholesterol to consume or not to exceed each day. +* `per_100g` (Float): The amount of cholesterol per 100g of the product. +* `per_serving` (Float): The amount of cholesterol per serving of the product. Fields which are specific to this product; they are not used in any other product. ### Total Carbohydrate Field @@ -238,14 +230,14 @@ A `NutritionFactsLabelV1TotalCarbohydrate` implements the following attributes: * `per_serving` (Float): The amount of total carbohydrates per serving of the product. Fields which are specific to this product; they are not used in any other product. -### Total Fat Field -The total amount of fat in the product. +### Dietary Fiber Field +The amount of dietary fiber in the product. -A `NutritionFactsLabelV1TotalFat` implements the following attributes: +A `NutritionFactsLabelV1DietaryFiber` implements the following attributes: -* `daily_value` (Float): DVs are the recommended amounts of total fat to consume or not to exceed each day. -* `per_100g` (Float): The amount of total fat per 100g of the product. -* `per_serving` (Float): The amount of total fat per serving of the product. +* `daily_value` (Float): DVs are the recommended amounts of dietary fiber to consume or not to exceed each day. +* `per_100g` (Float): The amount of dietary fiber per 100g of the product. +* `per_serving` (Float): The amount of dietary fiber per serving of the product. Fields which are specific to this product; they are not used in any other product. ### Total Sugars Field @@ -258,14 +250,47 @@ A `NutritionFactsLabelV1TotalSugar` implements the following attributes: * `per_serving` (Float): The amount of total sugars per serving of the product. Fields which are specific to this product; they are not used in any other product. -### Trans Fat Field -The amount of trans fat in the product. +### Added Sugars Field +The amount of added sugars in the product. -A `NutritionFactsLabelV1TransFat` implements the following attributes: +A `NutritionFactsLabelV1AddedSugar` implements the following attributes: -* `daily_value` (Float): DVs are the recommended amounts of trans fat to consume or not to exceed each day. -* `per_100g` (Float): The amount of trans fat per 100g of the product. -* `per_serving` (Float): The amount of trans fat per serving of the product. +* `daily_value` (Float): DVs are the recommended amounts of added sugars to consume or not to exceed each day. +* `per_100g` (Float): The amount of added sugars per 100g of the product. +* `per_serving` (Float): The amount of added sugars per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### Protein Field +The amount of protein in the product. + +A `NutritionFactsLabelV1Protein` implements the following attributes: + +* `daily_value` (Float): DVs are the recommended amounts of protein to consume or not to exceed each day. +* `per_100g` (Float): The amount of protein per 100g of the product. +* `per_serving` (Float): The amount of protein per serving of the product. +Fields which are specific to this product; they are not used in any other product. + +### sodium Field +The amount of sodium in the product. + +A `NutritionFactsLabelV1Sodium` implements the following attributes: + +* `daily_value` (Float): DVs are the recommended amounts of sodium to consume or not to exceed each day. +* `per_100g` (Float): The amount of sodium per 100g of the product. +* `per_serving` (Float): The amount of sodium per serving of the product. +* `unit` (String): The unit of measurement for the amount of sodium. +Fields which are specific to this product; they are not used in any other product. + +### nutrients Field +The amount of nutrients in the product. + +A `NutritionFactsLabelV1Nutrient` implements the following attributes: + +* `daily_value` (Float): DVs are the recommended amounts of nutrients to consume or not to exceed each day. +* `name` (String): The name of nutrients of the product. +* `per_100g` (Float): The amount of nutrients per 100g of the product. +* `per_serving` (Float): The amount of nutrients per serving of the product. +* `unit` (String): The unit of measurement for the amount of nutrients. # Attributes The following fields are extracted for Nutrition Facts Label V1: @@ -302,7 +327,7 @@ puts result.document.inference.prediction.dietary_fiber.value **nutrients** (Array<[NutritionFactsLabelV1Nutrient](#nutrients-field)>): The amount of nutrients in the product. ```rb -for nutrients_elem in result.document.inference.prediction.nutrients do +result.document.inference.prediction.nutrients do |nutrients_elem| puts nutrients_elem.value end ``` diff --git a/docs/passport_v1.md b/docs/global_products/passport_v1.md similarity index 77% rename from docs/passport_v1.md rename to docs/global_products/passport_v1.md index ccee5739..87b75482 100644 --- a/docs/passport_v1.md +++ b/docs/global_products/passport_v1.md @@ -1,16 +1,34 @@ --- -title: Passport OCR Ruby +title: Ruby Client Library - Passport category: 622b805aaec68102ea7fcbc2 slug: ruby-passport-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Passport API](https://platform.mindee.com/mindee/passport). +The Ruby Client Library supports the [Passport API](https://platform.mindee.com/mindee/passport). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/passport/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `passport` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ❌ No | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🌐 Global | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/passport/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Passport sample](https://github.com/mindee/client-lib-test-data/blob/main/products/passport/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -30,7 +48,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -86,18 +103,18 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. @@ -146,7 +163,7 @@ puts result.document.inference.prediction.gender.value **given_names** (Array<[StringField](#string-field)>): The given name(s) of the passport holder. ```rb -for given_names_elem in result.document.inference.prediction.given_names do +result.document.inference.prediction.given_names do |given_names_elem| puts given_names_elem.value end ``` diff --git a/docs/resume_v1.md b/docs/global_products/resume_v1.md similarity index 82% rename from docs/resume_v1.md rename to docs/global_products/resume_v1.md index 84eddf98..1b8eb175 100644 --- a/docs/resume_v1.md +++ b/docs/global_products/resume_v1.md @@ -1,16 +1,42 @@ --- -title: Resume OCR Ruby +title: Ruby Client Library - Resume category: 622b805aaec68102ea7fcbc2 slug: ruby-resume-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports the [Resume API](https://platform.mindee.com/mindee/resume). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/resume/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Resume API](https://platform.mindee.com/mindee/resume). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `resume` | +> | Recommended Version | `v1.2` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/resume/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Resume sample](https://github.com/mindee/client-lib-test-data/blob/main/products/resume/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::Resume::ResumeV1 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -114,19 +139,20 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **page_id**. +The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements +**value**, **confidence** and **page_id**. > Note: a classification field's `value is always a `String`. @@ -136,29 +162,13 @@ The text field `StringField` only has one constraint: it's **value** is a `Strin ## Specific Fields Fields which are specific to this product; they are not used in any other product. -### Certificates Field -The list of certificates obtained by the candidate. - -A `ResumeV1Certificate` implements the following attributes: - -* `grade` (String): The grade obtained for the certificate. -* `name` (String): The name of certification. -* `provider` (String): The organization or institution that issued the certificate. -* `year` (String): The year when a certificate was issued or received. -Fields which are specific to this product; they are not used in any other product. - -### Education Field -The list of the candidate's educational background. +### Social Networks Field +The list of social network profiles of the candidate. -A `ResumeV1Education` implements the following attributes: +A `ResumeV1SocialNetworksUrl` implements the following attributes: -* `degree_domain` (String): The area of study or specialization. -* `degree_type` (String): The type of degree obtained, such as Bachelor's, Master's, or Doctorate. -* `end_month` (String): The month when the education program or course was completed. -* `end_year` (String): The year when the education program or course was completed. -* `school` (String): The name of the school. -* `start_month` (String): The month when the education program or course began. -* `start_year` (String): The year when the education program or course began. +* `name` (String): The name of the social network. +* `url` (String): The URL of the social network. Fields which are specific to this product; they are not used in any other product. ### Languages Field @@ -175,7 +185,21 @@ A `ResumeV1Language` implements the following attributes: - Proficient - Intermediate - Beginner + +Fields which are specific to this product; they are not used in any other product. + +### Education Field +The list of the candidate's educational background. + +A `ResumeV1Education` implements the following attributes: +* `degree_domain` (String): The area of study or specialization. +* `degree_type` (String): The type of degree obtained, such as Bachelor's, Master's, or Doctorate. +* `end_month` (String): The month when the education program or course was completed. +* `end_year` (String): The year when the education program or course was completed. +* `school` (String): The name of the school. +* `start_month` (String): The month when the education program or course began. +* `start_year` (String): The year when the education program or course began. Fields which are specific to this product; they are not used in any other product. ### Professional Experiences Field @@ -190,7 +214,7 @@ A `ResumeV1ProfessionalExperience` implements the following attributes: - Part-Time - Internship - Freelance - + * `department` (String): The specific department or division within the company. * `description` (String): The description of the professional experience as written in the document. * `employer` (String): The name of the company or organization. @@ -201,13 +225,15 @@ A `ResumeV1ProfessionalExperience` implements the following attributes: * `start_year` (String): The year when the professional experience began. Fields which are specific to this product; they are not used in any other product. -### Social Networks Field -The list of social network profiles of the candidate. +### Certificates Field +The list of certificates obtained by the candidate. -A `ResumeV1SocialNetworksUrl` implements the following attributes: +A `ResumeV1Certificate` implements the following attributes: -* `name` (String): The name of the social network. -* `url` (String): The URL of the social network. +* `grade` (String): The grade obtained for the certificate. +* `name` (String): The name of certification. +* `provider` (String): The organization or institution that issued the certificate. +* `year` (String): The year when a certificate was issued or received. # Attributes The following fields are extracted for Resume V1: @@ -223,7 +249,7 @@ puts result.document.inference.prediction.address.value **certificates** (Array<[ResumeV1Certificate](#certificates-field)>): The list of certificates obtained by the candidate. ```rb -for certificates_elem in result.document.inference.prediction.certificates do +result.document.inference.prediction.certificates do |certificates_elem| puts certificates_elem.value end ``` @@ -251,7 +277,7 @@ puts result.document.inference.prediction.document_type.value **education** (Array<[ResumeV1Education](#education-field)>): The list of the candidate's educational background. ```rb -for education_elem in result.document.inference.prediction.education do +result.document.inference.prediction.education do |education_elem| puts education_elem.value end ``` @@ -267,7 +293,7 @@ puts result.document.inference.prediction.email_address.value **given_names** (Array<[StringField](#string-field)>): The candidate's first or given names. ```rb -for given_names_elem in result.document.inference.prediction.given_names do +result.document.inference.prediction.given_names do |given_names_elem| puts given_names_elem.value end ``` @@ -276,7 +302,7 @@ end **hard_skills** (Array<[StringField](#string-field)>): The list of the candidate's technical abilities and knowledge. ```rb -for hard_skills_elem in result.document.inference.prediction.hard_skills do +result.document.inference.prediction.hard_skills do |hard_skills_elem| puts hard_skills_elem.value end ``` @@ -292,7 +318,7 @@ puts result.document.inference.prediction.job_applied.value **languages** (Array<[ResumeV1Language](#languages-field)>): The list of languages that the candidate is proficient in. ```rb -for languages_elem in result.document.inference.prediction.languages do +result.document.inference.prediction.languages do |languages_elem| puts languages_elem.value end ``` @@ -322,7 +348,7 @@ puts result.document.inference.prediction.profession.value **professional_experiences** (Array<[ResumeV1ProfessionalExperience](#professional-experiences-field)>): The list of the candidate's professional experiences. ```rb -for professional_experiences_elem in result.document.inference.prediction.professional_experiences do +result.document.inference.prediction.professional_experiences do |professional_experiences_elem| puts professional_experiences_elem.value end ``` @@ -331,7 +357,7 @@ end **social_networks_urls** (Array<[ResumeV1SocialNetworksUrl](#social-networks-field)>): The list of social network profiles of the candidate. ```rb -for social_networks_urls_elem in result.document.inference.prediction.social_networks_urls do +result.document.inference.prediction.social_networks_urls do |social_networks_urls_elem| puts social_networks_urls_elem.value end ``` @@ -340,7 +366,7 @@ end **soft_skills** (Array<[StringField](#string-field)>): The list of the candidate's interpersonal and communication abilities. ```rb -for soft_skills_elem in result.document.inference.prediction.soft_skills do +result.document.inference.prediction.soft_skills do |soft_skills_elem| puts soft_skills_elem.value end ``` @@ -349,7 +375,7 @@ end **surnames** (Array<[StringField](#string-field)>): The candidate's last names. ```rb -for surnames_elem in result.document.inference.prediction.surnames do +result.document.inference.prediction.surnames do |surnames_elem| puts surnames_elem.value end ``` diff --git a/docs/generated_v1.md b/docs/global_products/universal.md similarity index 53% rename from docs/generated_v1.md rename to docs/global_products/universal.md index 46935222..d6e2577f 100644 --- a/docs/generated_v1.md +++ b/docs/global_products/universal.md @@ -1,15 +1,34 @@ --- -title: Generated API Ruby +title: Universal API Ruby category: 622b805aaec68102ea7fcbc2 -slug: ruby-generated-ocr -parentDoc: 6294d97ee723f1008d2ab28e +slug: ruby-universal-ocr +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports generated APIs. -Generated APIs can theoretically support all APIs in a catch-all generic format. +The Ruby Client Library implements a universal wrapper class for all products. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ |-----------------------------------------------------------------| +> | Endpoint Name | `` | +> | Recommended Version | `v` Defaults to 1 for custom products. | +> | Supports Polling/Webhooks | ❓️ Variable | +> | Support Synchronous HTTP Calls | ❓ Variable | +> | Geography | ❓ Variable | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- |---------------| +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + +The `Universal` product supports all products in a catch-all generic format, and can be used in the following manner: # Quick-Start -```ruby +```rb require 'mindee' # Init a new client @@ -26,9 +45,9 @@ custom_endpoint = mindee_client.create_endpoint( ) # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, - Mindee::Product::Generated::GeneratedV1, + Mindee::Product::Universal::Universal, endpoint: custom_endpoint ) @@ -36,22 +55,22 @@ result = mindee_client.enqueue_and_parse( puts result.document ``` -# Generated Endpoints +# Universal Endpoints -You may have noticed in the previous step that in order to access a custom build, you will need to provide an account and an endpoint name at the very least. +You may have noticed in the previous step that in order to access a universal build, you will need to provide an account and an endpoint name at the very least. Although it is optional, the version number should match the latest version of your build in most use-cases. If it is not set, it will default to "1". # Field Types -## Generated Fields +## Universal Fields -### Generated List Field +### Universal List Field -A `GeneratedListField` is a special type of custom list that implements the following: +A `UniversalListField` is a special type of custom list that implements the following: -- **values** (`Array`): the confidence score of the field prediction. +- **values** (`Array`): the confidence score of the field prediction. - **page_id** (`Integer`): only available for some documents ATM. Since the inner contents can vary, the value isn't accessed through a property, but rather through the following functions: @@ -60,9 +79,9 @@ Since the inner contents can vary, the value isn't accessed through a property, - **contents_string(separator=" ")** (`-> String`): returns a list of concatenated values, with an optional **separator** `String` between them. > **Note:** the `to_s` method returns a string representation of all values of this object, with an empty space between each of them. -### Generated Object Field +### Universal Object Field -Unrecognized structures and sometimes values of `ListField`s are stored in a `GeneratedObjectField` structure, which is implemented dynamically depending on the object's structure. +Unrecognized structures and sometimes values of `ListField`s are stored in a `UniversalObjectField` structure, which is implemented dynamically depending on the object's structure. - **page_id** (`[Integer, nil]`): the ID of the page, is `nil` when at document-level. - **raw_value** (`[String, nil]`): an optional field for when some post-processing has been done on fields (e.g. amounts). `nil` in most instances. @@ -78,13 +97,13 @@ The text field `StringField` only has one constraint: its **value** is an `Optio # Attributes -Generated builds always have access to at least two attributes: +Universal builds always have access to at least two attributes: ## Fields -**fields** (`Hash>`): +**fields** (`Hash>`): -```ruby +```rb puts result.document.inference.prediction.fields["my-field"].to_s ``` diff --git a/docs/loading_a_document.md b/docs/loading_a_document.md new file mode 100644 index 00000000..7fae7448 --- /dev/null +++ b/docs/loading_a_document.md @@ -0,0 +1,316 @@ +--- +title: Document Loading +category: 622b805aaec68102ea7fcbc2 +slug: ruby-document-loading +parentDoc: 6294d97ee723f1008d2ab28e +--- + +## Calling the Mindee API using webhooks + +> 🚧 This feature is only available for compatible products, see the see `Supports Polling/Webhooks` on the product's +> documentation. + +After [setting up a webhook for your account](https://developers.mindee.com/docs/webhooks), you can send a document, +and then retrieve the results from an API call in the following fashion: + +```rb +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Send the file to the server +enqueue_response = mindee_client.enqueue( + input_source, + Mindee::Product::Receipt::ReceiptV5 # ReceiptV5 supports asynchronous polling +) +``` + +Once your prediction is ready, the server will send it to your webhook. You can then use the payload as a regular +prediction: + +```rb +# Load the JSON string sent by the Mindee webhook POST callback. +# Reading the callback data will vary greatly depending on your HTTP server. +# This is therefore beyond the scope of this example. + +local_response = Mindee::Input::LocalResponse.new(request.body.string) + +# You can also use a File object as the input. +# FILE_PATH = File.join('path', 'to', 'file.json').freeze +# local_response = Mindee::Input::LocalResponse.new(FILE_PATH); + +# Optional: verify the HMAC signature. +unless local_response.valid_hmac_signature?(my_secret_key, 'invalid signature') + raise "Invalid HMAC signature!" +end + + +# Deserialize the response: +result = mindee_client.load_prediction( + Mindee::Product::Receipt::ReceiptV5, # The prediction type must match the initial enqueuing to work properly. + local_response +) + +# Print a summary of the parsed data in RST format +puts result.document +``` + +## Enqueueing and polling manually + +> ❗️ We _strongly_ recommend you rely on a webhook setup, or a simple `parse()` call for most operations. Only use +> manual polling if you are certain that it is the best solution for you. + +> 🚧 This feature is only available for compatible products, see the see `Supports Polling/Webhooks` on the product's +> documentation. + +Instead of relying on the `parse()` method, you can enqueue documents and poll +the server manually: + +```rb +# Load a file from disk +input_source = mindee_client.source_from_path('/path/to/the/file.ext') + +# Send the file to the server +enqueue_response = mindee_client.enqueue( + input_source, + Mindee::Product::Invoice::InvoiceV4 # InvoiceV4 supports asynchronous polling +) + +job_id = enqueue_response.job.id + +queue_res = parse_queued(job_id, Mindee::Product::Invoice::InvoiceV4, endpoint: endpoint) +polling_attempts = 0 + +while [Mindee::Parsing::Common::JobStatus::PROCESSING, Mindee::Parsing::Common::JobStatus::WAITING].include?( + queue_res.job.status) && polling_attempts < 80 # Recommended amounts of total retries for asynchronous polling. + sleep(1.5) # Recommended waiting time for re-attempts + queue_res = parse_queued(job_id, Mindee::Product::Invoice::InvoiceV4) + polling_attempts += 1 +end + +# If all went well, print a short summary of the result. +if queue_res.job.status == Mindee::Parsing::Common::JobStatus::COMPLETED + puts queue_res.document +end +``` + +## Parsing operations + +Operations pertaining to the Client's `parse()` method. The parsing process supports both synchronous and asynchronous +modes, and you can fine-tune its behavior using several options. + +### Polling options + +When performing an asynchronous parse (i.e. when the document is enqueued), the client will poll the API for the result. +The following options control the polling behavior: + +- `initial_delay_sec`: The initial delay (in seconds) before the first polling attempt. +- `delay_sec`: The delay (in seconds) between subsequent polls. +- `max_retries`: The maximum number of polling attempts before timing out. + +These parameters ensure that the client does not overload the API with too-frequent requests and also avoid premature +timeouts. + +Example: +```rb +result = mindee_client.parse( + input_source, + Mindee::Product::Invoice::InvoiceV4, + options: { + initial_delay_sec: 2, # Wait 2 seconds before the first poll. + delay_sec: 1.5, # Wait 1.5 seconds between polls. + max_retries: 80 # Try polling a maximum of 80 times. + } +) +``` +> ⚠️ Warning: Setting `delay_sec` too low might lead to insufficient wait time between polls, causing the server to +> block your API calls for a short time. + +### Page operations + +When parsing PDFs, you can preprocess the document using page operations. Using the `page_options` parameter, you can +specify which pages to keep or remove even before the file is sent to the server. This is especially useful if your +document contains extraneous pages that you do not want to process. + +The available options are: +* `page_indexes`: An array of zero-based page indexes. +* `operation`: The operation to perform—either: + * `:KEEP_ONLY` (keep only the specified pages) + * `:REMOVE` (remove the specified pages). +* `on_min_pages`: Apply the operation only if the document has at least the specified number of pages. + +Example: +```rb +page_options = { + page_indexes:[1, 3], # Only target pages 1 and 3. + operation: :KEEP_ONLY, # Remove all other pages. + on_min_pages: 3 # Only apply if the document has at least 3 pages. +} + +result = mindee_client.parse( + input_source, + Mindee::Product::Invoice::InvoiceV4, + options: { + page_options: page_options + } +) +``` +> ⚠️ Warning: Page operations alter the document's content. Ensure that this behavior is acceptable for your use case, +> as there is no undo once the pages are modified. + +## Workflow operations + +Workflow operations are similar to parsing operations, but they apply to calls made through the workflow feature. + +Example: +```rb +workflow_options = { + document_alias: "my_document", + priority: :high, + page_options: { + page_indexes:[0, 1], + operation: :REMOVE + } + } + +result = mindee_client.execute_workflow( + input_source, + "workflow_id", + options: workflow_options +) +``` + +## Loading a Document File + +Before sending a document to Mindee’s API, you first need to load the file into one of our input source wrappers. +These wrappers not only validate the file type (using a trusted MIME type check) but also give you access the following +helper methods: +* [image compression](https://developers.mindee.com/docs/ruby-advanced-file-operations#image-compression) +* [pdf compression](https://developers.mindee.com/docs/ruby-advanced-file-operations#pdf-compression) +* [PDF fixing](https://developers.mindee.com/docs/ruby-advanced-file-operations#pdf-fixing) + +> 📘 Regardless of how a document is loaded, the subsequent parsing or workflow operations remain the same. + + +Mindee’s Ruby client supports several methods for loading a document. + + +These can either be done locally: +* Loading from a [local path](#loading-from-a-local-path) +* Loading from a [File object](#loading-from-a-file-object) +* Loading from a [Base64-encoded string](#loading-from-a-base64-encoded-string) +* Loading from a [raw sequence of bytes](#loading-from-raw-bytes) + +These four methods inherit from the `LocalInputSource` class, which provides a few common utility features described +[here](#under-the-hood---local-input-source-details). + +Or loading from a [URL](#loading-by-url). + +### Loading from a Local Path + +The most straightforward way of loading a document: load a file directly from disk by providing its path. + +Example: +```rb +# Initialize the client. +mindee_client = Mindee::Client.new(api_key: 'my-api-key') + +# Load a file from disk using its absolute path. +input_source = mindee_client.source_from_path('/absolute/path/to/file.ext') +``` + +### Loading from a File Object + +When you already have an open file (in binary mode), you can pass it along with its original filename. + +Example: + +```rb +File.open('invoice.jpg', 'rb') do |file_obj| + # Creating a local input source from the file object. + input_source = mindee_client.source_from_file(file_obj, "invoice.jpg") + # Parsing happens similarly. +end +``` + + +### Loading from a Base64-Encoded String + +For cases where you have file data encoded in Base64, load the document by providing the encoded string along with the +original filename. This converts the Base64 string into a local input source for further processing. + +Example: + +```rb +b64_string = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGB..." # Example dummy b64_string. + +input_source = mindee_client.source_from_b64string(b64_string, "receipt.jpg") +``` + + +### Loading from Raw Bytes + +If you have the file’s raw binary data (as bytes), create an input source by passing the bytes and the original +filename. + +Example: + +```rb +raw_bytes = b"%PDF-1.3\n%\xbf\xf7\xa2\xfe\n1 0 obj..." # Example dummy raw bytes sequence. + +input_source = mindee_client.source_from_bytes(raw_bytes, "invoice.pdf") +``` + +### Loading by URL + +For remote documents, you can load a file through its URL. The server will accept direct urls if: +* They begin with "https://". +* They point to a valid file. +* They do not redirect the request (e.g. Google Drive documents or proxies). + +Under the hood, the +[Mindee::Input::Source::URLInputSource](https://mindee.github.io/mindee-api-ruby/Mindee/Input/Source/URLInputSource.html) +class validates the URL, but won't perform an HTTP GET request unless specifically requested (using Ruby’s Net::HTTP). + +Example: +```rb +input_source = mindee_client.source_from_url("https://www.example.com/invoice.pdf") +result = mindee_client.parse(input_source, Mindee::Product::Invoice::InvoiceV4) +``` + +To download the files before sending them, you can use the `as_local_input_source` method. It allows to follow +redirects, and supports optional authentication (via basic auth or JWT tokens). You can optionally download and save the file locally or convert it into a local input source for further processing—thus benefiting from the same processing methods as local files. + +Additional URL features include: + +* Validation: The URLInputSource throws an error if the URL does not start with “https://”. +* Authentication: You can supply basic authentication (username/password) or a bearer token. +* Local Conversion: Methods such as `write_to_file` let you download and inspect the file locally. Alternatively, +* `as_local_input_source` converts the downloaded content into a LocalInputSource so you can apply operations like +* compression. + +Example: +```rb +# Load the URL input normally: +remote_input_source = mindee_client.source_from_url("https://www.example.com/invoice.pdf") + +# Download the file and convert it to a `BytesInputSource` (type of `LocalInputSource`): +local_input_source = remote_input_source.as_local_input_source(filename: 'my_downloaded_invoice.pdf') + +# Download the file and save it to the specified directory: +local_downloaded_file_path = remote_input_source.write_to_file("path/to/my/downloaded/invoice.pdf") +``` + +### Under the Hood - Local Input Source Details + +When loading using from either a path, file, raw byte sequence or base64 string, the created object inherits from +[Mindee::Input::Source::LocalInputSource](https://mindee.github.io/mindee-api-ruby/Mindee/Input/Source/LocalInputSource.html). Key features include: + +* Automatic MIME Type Validation using Marcel to check for server file format compliance. +* An option ([repair_pdf](https://mindee.github.io/mindee-api-ruby/Mindee/Input/Source/LocalInputSource.html#initialize-instance_method)) to attempt recovery of PDFs with broken header information. +* File Operations: + * [compress!](https://mindee.github.io/mindee-api-ruby/Mindee/Input/Source/LocalInputSource.html#compress!-instance_method) – Compresses the file by invoking either the PDFCompressor for PDFs or the ImageCompressor for images. Parameters such as quality, max dimensions, and options to force or disable source text (for PDFs) are available. + * `write_to_file` ([URLInputSource version](https://mindee.github.io/mindee-api-ruby/Mindee/Input/Source/URLInputSource.html#write_to_file-instance_method), [LocalInputSource version](https://mindee.github.io/mindee-api-ruby/Mindee/Input/Source/LocalInputSource.html#write_to_file-instance_method)) – Saves the current state of the input (after possible operations) to disk. This is handy for inspection before parsing. + * [count_pages](https://mindee.github.io/mindee-api-ruby/Mindee/Input/Source/LocalInputSource.html#count_pages-instance_method) – For PDF files, returns the total page count; by default, non-PDF files are assumed to be single-page documents. + +## Questions? +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/localized_products.md b/docs/localized_products.md new file mode 100644 index 00000000..db1706bf --- /dev/null +++ b/docs/localized_products.md @@ -0,0 +1,6 @@ +--- +title: Localized Products +category: 622b805aaec68102ea7fcbc2 +slug: ruby-localized-products +parentDoc: 6294d97ee723f1008d2ab28e +--- diff --git a/docs/bank_account_details_v2.md b/docs/localized_products/bank_account_details_v2.md similarity index 76% rename from docs/bank_account_details_v2.md rename to docs/localized_products/bank_account_details_v2.md index 69540f72..c3387574 100644 --- a/docs/bank_account_details_v2.md +++ b/docs/localized_products/bank_account_details_v2.md @@ -1,16 +1,34 @@ --- -title: FR Bank Account Details OCR Ruby +title: Ruby Client Library - FR Bank Account Details category: 622b805aaec68102ea7fcbc2 slug: ruby-fr-bank-account-details-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [Bank Account Details API](https://platform.mindee.com/mindee/bank_account_details). +The Ruby Client Library supports the [Bank Account Details API](https://platform.mindee.com/mindee/bank_account_details). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_account_details/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `bank_account_details` | +> | Recommended Version | `v2.0` | +> | Supports Polling/Webhooks | ❌ No | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🇫🇷 France | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_account_details/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Bank Account Details sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_account_details/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -30,7 +48,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -80,12 +97,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. diff --git a/docs/bank_check_v1.md b/docs/localized_products/bank_check_v1.md similarity index 72% rename from docs/bank_check_v1.md rename to docs/localized_products/bank_check_v1.md index e8cb950c..b05accb9 100644 --- a/docs/bank_check_v1.md +++ b/docs/localized_products/bank_check_v1.md @@ -1,16 +1,34 @@ --- -title: US Bank Check OCR Ruby +title: Ruby Client Library - US Bank Check category: 622b805aaec68102ea7fcbc2 slug: ruby-us-bank-check-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [Bank Check API](https://platform.mindee.com/mindee/bank_check). +The Ruby Client Library supports the [Bank Check API](https://platform.mindee.com/mindee/bank_check). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_check/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `bank_check` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ❌ No | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🇺🇸 United States | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_check/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Bank Check sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_check/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -30,7 +48,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -80,12 +97,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -95,15 +112,17 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`). ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. ### Position Field -The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, **polygon** and **page_id**. On top of these, it has access to: +The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, +**polygon** and **page_id**. On top of these, it has access to: -* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond canvas). +* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond +canvas). * **quadrangle** (`Mindee::Geometry::Quadrilateral`): a free polygon made up of four points. ### String Field @@ -140,9 +159,9 @@ puts result.document.inference.prediction.check_number.value [📄](#page-level-fields "This field is only present on individual pages.")**check_position** ([PositionField](#position-field)): The position of the check on the document. ```rb -for check_position_elem in result.document.check_position do - puts check_position_elem.polygon -end + result.document.check_position.each do |check_position_elem| + puts check_position_elem.polygon + end ``` ## Check Issue Date @@ -156,7 +175,7 @@ puts result.document.inference.prediction.date.value **payees** (Array<[StringField](#string-field)>): List of the check's payees (recipients). ```rb -for payees_elem in result.document.inference.prediction.payees do +result.document.inference.prediction.payees do |payees_elem| puts payees_elem.value end ``` @@ -172,14 +191,14 @@ puts result.document.inference.prediction.routing_number.value [📄](#page-level-fields "This field is only present on individual pages.")**signatures_positions** (Array<[PositionField](#position-field)>): List of signature positions ```rb -for page in result.document.inference.pages do - for signatures_positions_elem in page.prediction.signatures_positions do - puts signatures_positions_elem.polygon.to_s + result.document.inference.pages do |page| + page.prediction.signatures_positions do |signatures_positions_elem| + puts signatures_positions_elem.polygon.to_s puts signatures_positions_elem.quadrangle.to_s puts signatures_positions_elem.rectangle.to_s puts signatures_positions_elem.boundingBox.to_s + end end -end ``` # Questions? diff --git a/docs/bank_statement_fr_v2.md b/docs/localized_products/bank_statement_fr_v2.md similarity index 81% rename from docs/bank_statement_fr_v2.md rename to docs/localized_products/bank_statement_fr_v2.md index 253e7f35..aa7f9074 100644 --- a/docs/bank_statement_fr_v2.md +++ b/docs/localized_products/bank_statement_fr_v2.md @@ -1,16 +1,42 @@ --- -title: FR Bank Statement OCR Ruby +title: Ruby Client Library - FR Bank Statement category: 622b805aaec68102ea7fcbc2 slug: ruby-fr-bank-statement-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [Bank Statement API](https://platform.mindee.com/mindee/bank_statement_fr). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_statement_fr/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Bank Statement API](https://platform.mindee.com/mindee/bank_statement_fr). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `bank_statement_fr` | +> | Recommended Version | `v2.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇫🇷 France | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_statement_fr/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Bank Statement sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_statement_fr/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FR::BankStatement::BankStatementV2 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -108,12 +133,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -123,7 +148,7 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`). ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. @@ -177,7 +202,7 @@ puts result.document.inference.prediction.client_address.value **client_names** (Array<[StringField](#string-field)>): The name of the clients who own the bank statement. ```rb -for client_names_elem in result.document.inference.prediction.client_names do +result.document.inference.prediction.client_names do |client_names_elem| puts client_names_elem.value end ``` @@ -235,7 +260,7 @@ puts result.document.inference.prediction.total_debits.value **transactions** (Array<[BankStatementV2Transaction](#transactions-field)>): The list of values that represent the financial transactions recorded in a bank statement. ```rb -for transactions_elem in result.document.inference.prediction.transactions do +result.document.inference.prediction.transactions do |transactions_elem| puts transactions_elem.value end ``` diff --git a/docs/carte_grise_v1.md b/docs/localized_products/carte_grise_v1.md similarity index 88% rename from docs/carte_grise_v1.md rename to docs/localized_products/carte_grise_v1.md index eb4c6345..c2c9a1a5 100644 --- a/docs/carte_grise_v1.md +++ b/docs/localized_products/carte_grise_v1.md @@ -1,16 +1,34 @@ --- -title: FR Carte Grise OCR Ruby +title: Ruby Client Library - FR Carte Grise category: 622b805aaec68102ea7fcbc2 slug: ruby-fr-carte-grise-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [Carte Grise API](https://platform.mindee.com/mindee/carte_grise). +The Ruby Client Library supports the [Carte Grise API](https://platform.mindee.com/mindee/carte_grise). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/carte_grise/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `carte_grise` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ❌ No | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🇫🇷 France | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/carte_grise/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Carte Grise sample](https://github.com/mindee/client-lib-test-data/blob/main/products/carte_grise/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -30,7 +48,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -146,18 +163,18 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. diff --git a/docs/energy_bill_fra_v1.md b/docs/localized_products/energy_bill_fra_v1.md similarity index 84% rename from docs/energy_bill_fra_v1.md rename to docs/localized_products/energy_bill_fra_v1.md index 71f80405..3cfb5603 100644 --- a/docs/energy_bill_fra_v1.md +++ b/docs/localized_products/energy_bill_fra_v1.md @@ -1,16 +1,42 @@ --- -title: FR Energy Bill OCR Ruby +title: Ruby Client Library - FR Energy Bill category: 622b805aaec68102ea7fcbc2 slug: ruby-fr-energy-bill-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [Energy Bill API](https://platform.mindee.com/mindee/energy_bill_fra). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/energy_bill_fra/default_sample.pdf), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Energy Bill API](https://platform.mindee.com/mindee/energy_bill_fra). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `energy_bill_fra` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇫🇷 France | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/energy_bill_fra/default_sample.pdf), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Energy Bill sample](https://github.com/mindee/client-lib-test-data/blob/main/products/energy_bill_fra/default_sample.pdf?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FR::EnergyBill::EnergyBillV1 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -100,12 +125,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -115,7 +140,7 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`). ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. @@ -125,6 +150,15 @@ The text field `StringField` only has one constraint: it's **value** is a `Strin ## Specific Fields Fields which are specific to this product; they are not used in any other product. +### Energy Supplier Field +The company that supplies the energy. + +A `EnergyBillV1EnergySupplier` implements the following attributes: + +* `address` (String): The address of the energy supplier. +* `name` (String): The name of the energy supplier. +Fields which are specific to this product; they are not used in any other product. + ### Energy Consumer Field The entity that consumes the energy. @@ -134,13 +168,17 @@ A `EnergyBillV1EnergyConsumer` implements the following attributes: * `name` (String): The name of the energy consumer. Fields which are specific to this product; they are not used in any other product. -### Energy Supplier Field -The company that supplies the energy. +### Subscription Field +The subscription details fee for the energy service. -A `EnergyBillV1EnergySupplier` implements the following attributes: +A `EnergyBillV1Subscription` implements the following attributes: -* `address` (String): The address of the energy supplier. -* `name` (String): The name of the energy supplier. +* `description` (String): Description or details of the subscription. +* `end_date` (String): The end date of the subscription. +* `start_date` (String): The start date of the subscription. +* `tax_rate` (Float): The rate of tax applied to the total cost. +* `total` (Float): The total cost of subscription. +* `unit_price` (Float): The price per unit of subscription. Fields which are specific to this product; they are not used in any other product. ### Energy Usage Field @@ -156,6 +194,19 @@ A `EnergyBillV1EnergyUsage` implements the following attributes: * `unit_price` (Float): The price per unit of energy consumed. Fields which are specific to this product; they are not used in any other product. +### Taxes and Contributions Field +Details of Taxes and Contributions. + +A `EnergyBillV1TaxesAndContribution` implements the following attributes: + +* `description` (String): Description or details of the Taxes and Contributions. +* `end_date` (String): The end date of the Taxes and Contributions. +* `start_date` (String): The start date of the Taxes and Contributions. +* `tax_rate` (Float): The rate of tax applied to the total cost. +* `total` (Float): The total cost of Taxes and Contributions. +* `unit_price` (Float): The price per unit of Taxes and Contributions. +Fields which are specific to this product; they are not used in any other product. + ### Meter Details Field Information about the energy meter. @@ -169,34 +220,8 @@ A `EnergyBillV1MeterDetail` implements the following attributes: - gas - water - None - + * `unit` (String): The unit of measurement for energy consumption, which can be kW, m³, or L. -Fields which are specific to this product; they are not used in any other product. - -### Subscription Field -The subscription details fee for the energy service. - -A `EnergyBillV1Subscription` implements the following attributes: - -* `description` (String): Description or details of the subscription. -* `end_date` (String): The end date of the subscription. -* `start_date` (String): The start date of the subscription. -* `tax_rate` (Float): The rate of tax applied to the total cost. -* `total` (Float): The total cost of subscription. -* `unit_price` (Float): The price per unit of subscription. -Fields which are specific to this product; they are not used in any other product. - -### Taxes and Contributions Field -Details of Taxes and Contributions. - -A `EnergyBillV1TaxesAndContribution` implements the following attributes: - -* `description` (String): Description or details of the Taxes and Contributions. -* `end_date` (String): The end date of the Taxes and Contributions. -* `start_date` (String): The start date of the Taxes and Contributions. -* `tax_rate` (Float): The rate of tax applied to the total cost. -* `total` (Float): The total cost of Taxes and Contributions. -* `unit_price` (Float): The price per unit of Taxes and Contributions. # Attributes The following fields are extracted for Energy Bill V1: @@ -240,7 +265,7 @@ puts result.document.inference.prediction.energy_supplier.value **energy_usage** (Array<[EnergyBillV1EnergyUsage](#energy-usage-field)>): Details of energy consumption. ```rb -for energy_usage_elem in result.document.inference.prediction.energy_usage do +result.document.inference.prediction.energy_usage do |energy_usage_elem| puts energy_usage_elem.value end ``` @@ -270,7 +295,7 @@ puts result.document.inference.prediction.meter_details.value **subscription** (Array<[EnergyBillV1Subscription](#subscription-field)>): The subscription details fee for the energy service. ```rb -for subscription_elem in result.document.inference.prediction.subscription do +result.document.inference.prediction.subscription do |subscription_elem| puts subscription_elem.value end ``` @@ -279,7 +304,7 @@ end **taxes_and_contributions** (Array<[EnergyBillV1TaxesAndContribution](#taxes-and-contributions-field)>): Details of Taxes and Contributions. ```rb -for taxes_and_contributions_elem in result.document.inference.prediction.taxes_and_contributions do +result.document.inference.prediction.taxes_and_contributions do |taxes_and_contributions_elem| puts taxes_and_contributions_elem.value end ``` diff --git a/docs/french_healthcard_v1.md b/docs/localized_products/french_healthcard_v1.md similarity index 63% rename from docs/french_healthcard_v1.md rename to docs/localized_products/french_healthcard_v1.md index a64c3e92..27411816 100644 --- a/docs/french_healthcard_v1.md +++ b/docs/localized_products/french_healthcard_v1.md @@ -1,16 +1,42 @@ --- -title: FR Health Card OCR Ruby +title: Ruby Client Library - FR Health Card category: 622b805aaec68102ea7fcbc2 slug: ruby-fr-health-card-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [Health Card API](https://platform.mindee.com/mindee/french_healthcard). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/french_healthcard/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Health Card API](https://platform.mindee.com/mindee/french_healthcard). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `french_healthcard` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇫🇷 France | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/french_healthcard/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Health Card sample](https://github.com/mindee/client-lib-test-data/blob/main/products/french_healthcard/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FR::HealthCard::HealthCardV1 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -62,18 +87,18 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. @@ -87,7 +112,7 @@ The following fields are extracted for Health Card V1: **given_names** (Array<[StringField](#string-field)>): The given names of the card holder. ```rb -for given_names_elem in result.document.inference.prediction.given_names do +result.document.inference.prediction.given_names do |given_names_elem| puts given_names_elem.value end ``` diff --git a/docs/idcard_fr_v2.md b/docs/localized_products/idcard_fr_v2.md similarity index 79% rename from docs/idcard_fr_v2.md rename to docs/localized_products/idcard_fr_v2.md index b18893f7..93311d6f 100644 --- a/docs/idcard_fr_v2.md +++ b/docs/localized_products/idcard_fr_v2.md @@ -1,16 +1,34 @@ --- -title: FR Carte Nationale d'Identité OCR Ruby +title: Ruby Client Library - FR Carte Nationale d'Identité category: 622b805aaec68102ea7fcbc2 slug: ruby-fr-carte-nationale-didentite-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [Carte Nationale d'Identité API](https://platform.mindee.com/mindee/idcard_fr). +The Ruby Client Library supports the [Carte Nationale d'Identité API](https://platform.mindee.com/mindee/idcard_fr). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/idcard_fr/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `idcard_fr` | +> | Recommended Version | `v2.0` | +> | Supports Polling/Webhooks | ❌ No | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🇫🇷 France | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/idcard_fr/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Carte Nationale d'Identité sample](https://github.com/mindee/client-lib-test-data/blob/main/products/idcard_fr/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -30,7 +48,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -98,24 +115,25 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **page_id**. +The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements +**value**, **confidence** and **page_id**. > Note: a classification field's `value is always a `String`. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. @@ -179,9 +197,9 @@ puts result.document.inference.prediction.document_number.value - RECTO & VERSO ```rb -for document_side_elem in result.document.document_side do - puts document_side_elem.value -end + result.document.document_side.each do |document_side_elem| + puts document_side_elem.value + end ``` ## Document Type @@ -192,9 +210,9 @@ end - OLD ```rb -for document_type_elem in result.document.document_type do - puts document_type_elem.value -end + result.document.document_type.each do |document_type_elem| + puts document_type_elem.value + end ``` ## Expiry Date @@ -215,7 +233,7 @@ puts result.document.inference.prediction.gender.value **given_names** (Array<[StringField](#string-field)>): The given name(s) of the card holder. ```rb -for given_names_elem in result.document.inference.prediction.given_names do +result.document.inference.prediction.given_names do |given_names_elem| puts given_names_elem.value end ``` diff --git a/docs/ind_passport_v1.md b/docs/localized_products/ind_passport_v1.md similarity index 79% rename from docs/ind_passport_v1.md rename to docs/localized_products/ind_passport_v1.md index 401f72d6..8a35420c 100644 --- a/docs/ind_passport_v1.md +++ b/docs/localized_products/ind_passport_v1.md @@ -1,16 +1,42 @@ --- -title: IND Passport - India OCR Ruby +title: Ruby Client Library - IND Passport - India category: 622b805aaec68102ea7fcbc2 slug: ruby-ind-passport---india-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [Passport - India API](https://platform.mindee.com/mindee/ind_passport). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/ind_passport/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Passport - India API](https://platform.mindee.com/mindee/ind_passport). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `ind_passport` | +> | Recommended Version | `v1.2` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇮🇳 India | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/ind_passport/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Passport - India sample](https://github.com/mindee/client-lib-test-data/blob/main/products/ind_passport/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::IND::IndianPassport::IndianPassportV1 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -81,24 +106,25 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **page_id**. +The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements +**value**, **confidence** and **page_id**. > Note: a classification field's `value is always a `String`. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. diff --git a/docs/license_plates_v1.md b/docs/localized_products/license_plates_v1.md similarity index 64% rename from docs/license_plates_v1.md rename to docs/localized_products/license_plates_v1.md index eb9baf0d..c448e4bc 100644 --- a/docs/license_plates_v1.md +++ b/docs/localized_products/license_plates_v1.md @@ -1,16 +1,34 @@ --- -title: EU License Plate OCR Ruby +title: Ruby Client Library - EU License Plate category: 622b805aaec68102ea7fcbc2 slug: ruby-eu-license-plate-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [License Plate API](https://platform.mindee.com/mindee/license_plates). +The Ruby Client Library supports the [License Plate API](https://platform.mindee.com/mindee/license_plates). -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/license_plates/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `license_plates` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ❌ No | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🇪🇺 Europe | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/license_plates/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![License Plate sample](https://github.com/mindee/client-lib-test-data/blob/main/products/license_plates/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -30,7 +48,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -66,12 +83,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -86,7 +103,7 @@ The following fields are extracted for License Plate V1: **license_plates** (Array<[StringField](#string-field)>): List of all license plates found in the image. ```rb -for license_plates_elem in result.document.inference.prediction.license_plates do +result.document.inference.prediction.license_plates do |license_plates_elem| puts license_plates_elem.value end ``` diff --git a/docs/payslip_fra_v3.md b/docs/localized_products/payslip_fra_v3.md similarity index 84% rename from docs/payslip_fra_v3.md rename to docs/localized_products/payslip_fra_v3.md index 76827ce5..bab3ecff 100644 --- a/docs/payslip_fra_v3.md +++ b/docs/localized_products/payslip_fra_v3.md @@ -1,16 +1,42 @@ --- -title: FR Payslip OCR Ruby +title: Ruby Client Library - FR Payslip category: 622b805aaec68102ea7fcbc2 slug: ruby-fr-payslip-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [Payslip API](https://platform.mindee.com/mindee/payslip_fra). - -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. +The Ruby Client Library supports the [Payslip API](https://platform.mindee.com/mindee/payslip_fra). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `payslip_fra` | +> | Recommended Version | `v3.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇫🇷 France | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +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 Ruby Client Library. ![Payslip sample](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::FR::Payslip::PayslipV3 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -123,12 +148,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -136,14 +161,16 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met ## Specific Fields Fields which are specific to this product; they are not used in any other product. -### Bank Account Details Field -Information about the employee's bank account. +### Pay Period Field +Information about the pay period. -A `PayslipV3BankAccountDetail` implements the following attributes: +A `PayslipV3PayPeriod` implements the following attributes: -* `bank_name` (String): The name of the bank. -* `iban` (String): The IBAN of the bank account. -* `swift` (String): The SWIFT code of the bank. +* `end_date` (String): The end date of the pay period. +* `month` (String): The month of the pay period. +* `payment_date` (String): The date of payment for the pay period. +* `start_date` (String): The start date of the pay period. +* `year` (String): The year of the pay period. Fields which are specific to this product; they are not used in any other product. ### Employee Field @@ -174,6 +201,16 @@ A `PayslipV3Employer` implements the following attributes: * `urssaf_number` (String): The URSSAF number of the employer. Fields which are specific to this product; they are not used in any other product. +### Bank Account Details Field +Information about the employee's bank account. + +A `PayslipV3BankAccountDetail` implements the following attributes: + +* `bank_name` (String): The name of the bank. +* `iban` (String): The IBAN of the bank account. +* `swift` (String): The SWIFT code of the bank. +Fields which are specific to this product; they are not used in any other product. + ### Employment Field Information about the employment. @@ -188,28 +225,16 @@ A `PayslipV3Employment` implements the following attributes: * `start_date` (String): The start date of the employment. Fields which are specific to this product; they are not used in any other product. -### Paid Time Off Field -Information about paid time off. - -A `PayslipV3PaidTimeOff` implements the following attributes: - -* `accrued` (Float): The amount of paid time off accrued in the period. -* `period` (String): The paid time off period. - -#### Possible values include: - - N - - N-1 - - N-2 - -* `pto_type` (String): The type of paid time off. +### Salary Details Field +Detailed information about the earnings. -#### Possible values include: - - VACATION - - RTT - - COMPENSATORY +A `PayslipV3SalaryDetail` implements the following attributes: -* `remaining` (Float): The remaining amount of paid time off at the end of the period. -* `used` (Float): The amount of paid time off used in the period. +* `amount` (Float): The amount of the earning. +* `base` (Float): The base rate value of the earning. +* `description` (String): The description of the earnings. +* `number` (Float): The number of units in the earning. +* `rate` (Float): The rate of the earning. Fields which are specific to this product; they are not used in any other product. ### Pay Detail Field @@ -229,28 +254,28 @@ A `PayslipV3PayDetail` implements the following attributes: * `total_taxes_and_deductions` (Float): The total taxes and deductions of the employee. Fields which are specific to this product; they are not used in any other product. -### Pay Period Field -Information about the pay period. - -A `PayslipV3PayPeriod` implements the following attributes: +### Paid Time Off Field +Information about paid time off. -* `end_date` (String): The end date of the pay period. -* `month` (String): The month of the pay period. -* `payment_date` (String): The date of payment for the pay period. -* `start_date` (String): The start date of the pay period. -* `year` (String): The year of the pay period. -Fields which are specific to this product; they are not used in any other product. +A `PayslipV3PaidTimeOff` implements the following attributes: -### Salary Details Field -Detailed information about the earnings. +* `accrued` (Float): The amount of paid time off accrued in the period. +* `period` (String): The paid time off period. -A `PayslipV3SalaryDetail` implements the following attributes: +#### Possible values include: + - N + - N-1 + - N-2 + +* `pto_type` (String): The type of paid time off. -* `amount` (Float): The amount of the earning. -* `base` (Float): The base rate value of the earning. -* `description` (String): The description of the earnings. -* `number` (Float): The number of units in the earning. -* `rate` (Float): The rate of the earning. +#### Possible values include: + - VACATION + - RTT + - COMPENSATORY + +* `remaining` (Float): The remaining amount of paid time off at the end of the period. +* `used` (Float): The amount of paid time off used in the period. # Attributes The following fields are extracted for Payslip V3: @@ -287,7 +312,7 @@ puts result.document.inference.prediction.employment.value **paid_time_off** (Array<[PayslipV3PaidTimeOff](#paid-time-off-field)>): Information about paid time off. ```rb -for paid_time_off_elem in result.document.inference.prediction.paid_time_off do +result.document.inference.prediction.paid_time_off do |paid_time_off_elem| puts paid_time_off_elem.value end ``` @@ -310,7 +335,7 @@ puts result.document.inference.prediction.pay_period.value **salary_details** (Array<[PayslipV3SalaryDetail](#salary-details-field)>): Detailed information about the earnings. ```rb -for salary_details_elem in result.document.inference.prediction.salary_details do +result.document.inference.prediction.salary_details do |salary_details_elem| puts salary_details_elem.value end ``` diff --git a/docs/us_healthcare_cards_v1.md b/docs/localized_products/us_healthcare_cards_v1.md similarity index 74% rename from docs/us_healthcare_cards_v1.md rename to docs/localized_products/us_healthcare_cards_v1.md index bde75916..24621d0a 100644 --- a/docs/us_healthcare_cards_v1.md +++ b/docs/localized_products/us_healthcare_cards_v1.md @@ -1,16 +1,42 @@ --- -title: US Healthcare Card OCR Ruby +title: Ruby Client Library - US Healthcare Card category: 622b805aaec68102ea7fcbc2 slug: ruby-us-healthcare-card-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [Healthcare Card API](https://platform.mindee.com/mindee/us_healthcare_cards). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/us_healthcare_cards/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [Healthcare Card API](https://platform.mindee.com/mindee/us_healthcare_cards). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `us_healthcare_cards` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇺🇸 United States | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/us_healthcare_cards/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![Healthcare Card sample](https://github.com/mindee/client-lib-test-data/blob/main/products/us_healthcare_cards/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::US::HealthcareCard::HealthcareCardV1 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -84,18 +109,18 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: * **date_object** (`Date`): an accessible representation of the value as a JavaScript object. @@ -127,7 +152,7 @@ puts result.document.inference.prediction.company_name.value **copays** (Array<[HealthcareCardV1Copay](#copays-field)>): Is a fixed amount for a covered service. ```rb -for copays_elem in result.document.inference.prediction.copays do +result.document.inference.prediction.copays do |copays_elem| puts copays_elem.value end ``` @@ -136,7 +161,7 @@ end **dependents** (Array<[StringField](#string-field)>): The list of dependents covered by the healthcare plan. ```rb -for dependents_elem in result.document.inference.prediction.dependents do +result.document.inference.prediction.dependents do |dependents_elem| puts dependents_elem.value end ``` diff --git a/docs/us_mail_v3.md b/docs/localized_products/us_mail_v3.md similarity index 73% rename from docs/us_mail_v3.md rename to docs/localized_products/us_mail_v3.md index 49602d9d..385bb895 100644 --- a/docs/us_mail_v3.md +++ b/docs/localized_products/us_mail_v3.md @@ -1,16 +1,42 @@ --- -title: US US Mail OCR Ruby +title: Ruby Client Library - US US Mail category: 622b805aaec68102ea7fcbc2 slug: ruby-us-us-mail-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [US Mail API](https://platform.mindee.com/mindee/us_mail). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/us_mail/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. +The Ruby Client Library supports the [US Mail API](https://platform.mindee.com/mindee/us_mail). + + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `us_mail` | +> | Recommended Version | `v3.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇺🇸 United States | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | Default Value | +> | ------------------------------- | ----------------------- | ------------- | +> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds | +> | Default Delay Between Calls | `delay_sec` | 1.5 seconds | +> | Polling Attempts Before Timeout | `max_retries` | 80 retries | + + +Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/us_mail/default_sample.jpg), +we are going to illustrate how to extract the data that we want using the Ruby Client Library. ![US Mail sample](https://github.com/mindee/client-lib-test-data/blob/main/products/us_mail/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -20,7 +46,7 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path('/path/to/the/file.ext') # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::US::UsMail::UsMailV3 ) @@ -30,7 +56,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** @@ -73,12 +98,12 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. @@ -89,6 +114,18 @@ The text field `StringField` only has one constraint: it's **value** is a `Strin ## Specific Fields Fields which are specific to this product; they are not used in any other product. +### Sender Address Field +The address of the sender. + +A `UsMailV3SenderAddress` implements the following attributes: + +* `city` (String): The city of the sender's address. +* `complete` (String): The complete address of the sender. +* `postal_code` (String): The postal code of the sender's address. +* `state` (String): Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. +* `street` (String): The street of the sender's address. +Fields which are specific to this product; they are not used in any other product. + ### Recipient Addresses Field The addresses of the recipients. @@ -96,24 +133,12 @@ A `UsMailV3RecipientAddress` implements the following attributes: * `city` (String): The city of the recipient's address. * `complete` (String): The complete address of the recipient. -* `is_address_change` (Boolean): Indicates if the recipient's address is a change of address. +* `is_address_change` (bool): Indicates if the recipient's address is a change of address. * `postal_code` (String): The postal code of the recipient's address. * `private_mailbox_number` (String): The private mailbox number of the recipient's address. * `state` (String): Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. * `street` (String): The street of the recipient's address. * `unit` (String): The unit number of the recipient's address. -Fields which are specific to this product; they are not used in any other product. - -### Sender Address Field -The address of the sender. - -A `UsMailV3SenderAddress` implements the following attributes: - -* `city` (String): The city of the sender's address. -* `complete` (String): The complete address of the sender. -* `postal_code` (String): The postal code of the sender's address. -* `state` (String): Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. -* `street` (String): The street of the sender's address. # Attributes The following fields are extracted for US Mail V3: @@ -129,7 +154,7 @@ puts result.document.inference.prediction.is_return_to_sender.value **recipient_addresses** (Array<[UsMailV3RecipientAddress](#recipient-addresses-field)>): The addresses of the recipients. ```rb -for recipient_addresses_elem in result.document.inference.prediction.recipient_addresses do +result.document.inference.prediction.recipient_addresses do |recipient_addresses_elem| puts recipient_addresses_elem.value end ``` @@ -138,7 +163,7 @@ end **recipient_names** (Array<[StringField](#string-field)>): The names of the recipients. ```rb -for recipient_names_elem in result.document.inference.prediction.recipient_names do +result.document.inference.prediction.recipient_names do |recipient_names_elem| puts recipient_names_elem.value end ``` diff --git a/docs/us_w9_v1.md b/docs/localized_products/us_w9_v1.md similarity index 66% rename from docs/us_w9_v1.md rename to docs/localized_products/us_w9_v1.md index e2c21a74..3acdbfa3 100644 --- a/docs/us_w9_v1.md +++ b/docs/localized_products/us_w9_v1.md @@ -1,16 +1,34 @@ --- -title: US W9 OCR Ruby +title: Ruby Client Library - US W9 category: 622b805aaec68102ea7fcbc2 slug: ruby-us-w9-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49e29a2cd6f08d69a40d8 --- -The Ruby OCR SDK supports the [W9 API](https://platform.mindee.com/mindee/us_w9). +The Ruby Client Library supports the [W9 API](https://platform.mindee.com/mindee/us_w9). -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. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ | -------------------------------------------------- | +> | Endpoint Name | `us_w9` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ❌ No | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🇺🇸 United States | + + +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 Ruby Client Library. ![W9 sample](https://github.com/mindee/client-lib-test-data/blob/main/products/us_w9/default_sample.jpg?raw=true) # Quick-Start ```rb +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -27,7 +45,6 @@ result = mindee_client.parse( # Print a full summary of the parsed data in RST format puts result.document - ``` **Output (RST):** @@ -73,21 +90,23 @@ These fields are generic and used in several products. Each prediction object contains a set of fields that inherit from the generic `Field` class. A typical `Field` object will have the following attributes: -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. +* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted. * **confidence** (Float, nil): the confidence score of the field prediction. * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it). 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. ### Position Field -The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, **polygon** and **page_id**. On top of these, it has access to: +The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, +**polygon** and **page_id**. On top of these, it has access to: -* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond canvas). +* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond +canvas). * **quadrangle** (`Mindee::Geometry::Quadrilateral`): a free polygon made up of four points. ### String Field @@ -103,108 +122,108 @@ The following fields are extracted for W9 V1: [📄](#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. ```rb -for address_elem in result.document.address do - puts address_elem.value -end + result.document.address.each do |address_elem| + puts address_elem.value + end ``` ## Business Name [📄](#page-level-fields "This field is only present on individual pages.")**business_name** ([StringField](#string-field)): The business name or disregarded entity name, if different from Name. ```rb -for business_name_elem in result.document.business_name do - puts business_name_elem.value -end + result.document.business_name.each do |business_name_elem| + puts business_name_elem.value + end ``` ## City State Zip [📄](#page-level-fields "This field is only present on individual pages.")**city_state_zip** ([StringField](#string-field)): The city, state, and ZIP code of the applicant. ```rb -for city_state_zip_elem in result.document.city_state_zip do - puts city_state_zip_elem.value -end + result.document.city_state_zip.each do |city_state_zip_elem| + puts city_state_zip_elem.value + end ``` ## EIN [📄](#page-level-fields "This field is only present on individual pages.")**ein** ([StringField](#string-field)): The employer identification number. ```rb -for ein_elem in result.document.ein do - puts ein_elem.value -end + result.document.ein.each do |ein_elem| + puts ein_elem.value + end ``` ## Name [📄](#page-level-fields "This field is only present on individual pages.")**name** ([StringField](#string-field)): Name as shown on the applicant's income tax return. ```rb -for name_elem in result.document.name do - puts name_elem.value -end + result.document.name.each do |name_elem| + puts name_elem.value + end ``` ## Signature Date Position [📄](#page-level-fields "This field is only present on individual pages.")**signature_date_position** ([PositionField](#position-field)): Position of the signature date on the document. ```rb -for signature_date_position_elem in result.document.signature_date_position do - puts signature_date_position_elem.polygon -end + result.document.signature_date_position.each do |signature_date_position_elem| + puts signature_date_position_elem.polygon + end ``` ## Signature Position [📄](#page-level-fields "This field is only present on individual pages.")**signature_position** ([PositionField](#position-field)): Position of the signature on the document. ```rb -for signature_position_elem in result.document.signature_position do - puts signature_position_elem.polygon -end + result.document.signature_position.each do |signature_position_elem| + puts signature_position_elem.polygon + end ``` ## SSN [📄](#page-level-fields "This field is only present on individual pages.")**ssn** ([StringField](#string-field)): The applicant's social security number. ```rb -for ssn_elem in result.document.ssn do - puts ssn_elem.value -end + result.document.ssn.each do |ssn_elem| + puts ssn_elem.value + end ``` ## Tax Classification [📄](#page-level-fields "This field is only present on individual pages.")**tax_classification** ([StringField](#string-field)): The federal tax classification, which can vary depending on the revision date. ```rb -for tax_classification_elem in result.document.tax_classification do - puts tax_classification_elem.value -end + result.document.tax_classification.each do |tax_classification_elem| + puts tax_classification_elem.value + end ``` ## Tax Classification LLC [📄](#page-level-fields "This field is only present on individual pages.")**tax_classification_llc** ([StringField](#string-field)): Depending on revision year, among S, C, P or D for Limited Liability Company Classification. ```rb -for tax_classification_llc_elem in result.document.tax_classification_llc do - puts tax_classification_llc_elem.value -end + result.document.tax_classification_llc.each do |tax_classification_llc_elem| + puts tax_classification_llc_elem.value + end ``` ## Tax Classification Other Details [📄](#page-level-fields "This field is only present on individual pages.")**tax_classification_other_details** ([StringField](#string-field)): Tax Classification Other Details. ```rb -for tax_classification_other_details_elem in result.document.tax_classification_other_details do - puts tax_classification_other_details_elem.value -end + result.document.tax_classification_other_details.each do |tax_classification_other_details_elem| + puts tax_classification_other_details_elem.value + end ``` ## W9 Revision Date [📄](#page-level-fields "This field is only present on individual pages.")**w9_revision_date** ([StringField](#string-field)): The Revision month and year of the W9 form. ```rb -for w9_revision_date_elem in result.document.w9_revision_date do - puts w9_revision_date_elem.value -end + result.document.w9_revision_date.each do |w9_revision_date_elem| + puts w9_revision_date_elem.value + end ``` # Questions? diff --git a/docs/payslip_fra_v2.md b/docs/payslip_fra_v2.md deleted file mode 100644 index a9095386..00000000 --- a/docs/payslip_fra_v2.md +++ /dev/null @@ -1,294 +0,0 @@ ---- -title: FR Payslip OCR Ruby -category: 622b805aaec68102ea7fcbc2 -slug: ruby-fr-payslip-ocr -parentDoc: 6294d97ee723f1008d2ab28e ---- -The Ruby OCR SDK supports the [Payslip API](https://platform.mindee.com/mindee/payslip_fra). - -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. -![Payslip sample](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg?raw=true) - -# Quick-Start -```rb -require 'mindee' - -# Init a new client -mindee_client = Mindee::Client.new(api_key: 'my-api-key') - -# Load a file from disk -input_source = mindee_client.source_from_path('/path/to/the/file.ext') - -# Parse the file -result = mindee_client.enqueue_and_parse( - input_source, - Mindee::Product::FR::Payslip::PayslipV2 -) - -# Print a full summary of the parsed data in RST format -puts result.document - -# Print the document-level parsed data -# puts result.document.inference.prediction - -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 972edba5-25aa-49d0-8431-e2557ddd788e -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/payslip_fra v2.0 -:Rotation applied: No - -Prediction -========== -:Employee: - :Address: 52 RUE DES FLEURS 33500 LIBOURNE FRANCE - :Date of Birth: - :First Name: Jean Luc - :Last Name: Picard - :Phone Number: - :Registration Number: - :Social Security Number: 123456789012345 -:Employer: - :Address: 1 RUE DU TONNOT 25210 DOUBS - :Company ID: 12345678901234 - :Company Site: - :NAF Code: 1234A - :Name: DEMO COMPANY - :Phone Number: - :URSSAF Number: -:Bank Account Details: - :Bank Name: - :IBAN: - :SWIFT: -:Employment: - :Category: Cadre - :Coefficient: 600.00 - :Collective Agreement: Construction -- Promotion - :Job Title: Directeur Régional du Développement - :Position Level: - :Start Date: 2022-05-01 -:Salary Details: - +--------------+-----------+--------------------------------------+-----------+ - | Amount | Base | Description | Rate | - +==============+===========+======================================+===========+ - | 6666.67 | | Salaire de base | | - +--------------+-----------+--------------------------------------+-----------+ - | 9.30 | | Part patronale Mutuelle NR | | - +--------------+-----------+--------------------------------------+-----------+ - | 508.30 | | Avantages en nature voiture | | - +--------------+-----------+--------------------------------------+-----------+ -:Pay Detail: - :Gross Salary: 7184.27 - :Gross Salary YTD: 18074.81 - :Income Tax Rate: 17.60 - :Income Tax Withheld: 1030.99 - :Net Paid: 3868.32 - :Net Paid Before Tax: 4899.31 - :Net Taxable: 5857.90 - :Net Taxable YTD: 14752.73 - :Total Cost Employer: 10486.94 - :Total Taxes and Deductions: 1650.36 -:PTO: - :Accrued This Period: 6.17 - :Balance End of Period: 6.17 - :Used This Period: -:Pay Period: - :End Date: 2023-03-31 - :Month: 03 - :Payment Date: 2023-03-29 - :Start Date: 2023-03-01 - :Year: 2023 -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. -* **confidence** (Float, nil): the confidence score of the field prediction. -* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - - -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. - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Bank Account Details Field -Information about the employee's bank account. - -A `PayslipV2BankAccountDetail` implements the following attributes: - -* `bank_name` (String): The name of the bank. -* `iban` (String): The IBAN of the bank account. -* `swift` (String): The SWIFT code of the bank. -Fields which are specific to this product; they are not used in any other product. - -### Employee Field -Information about the employee. - -A `PayslipV2Employee` implements the following attributes: - -* `address` (String): The address of the employee. -* `date_of_birth` (String): The date of birth of the employee. -* `first_name` (String): The first name of the employee. -* `last_name` (String): The last name of the employee. -* `phone_number` (String): The phone number of the employee. -* `registration_number` (String): The registration number of the employee. -* `social_security_number` (String): The social security number of the employee. -Fields which are specific to this product; they are not used in any other product. - -### Employer Field -Information about the employer. - -A `PayslipV2Employer` implements the following attributes: - -* `address` (String): The address of the employer. -* `company_id` (String): The company ID of the employer. -* `company_site` (String): The site of the company. -* `naf_code` (String): The NAF code of the employer. -* `name` (String): The name of the employer. -* `phone_number` (String): The phone number of the employer. -* `urssaf_number` (String): The URSSAF number of the employer. -Fields which are specific to this product; they are not used in any other product. - -### Employment Field -Information about the employment. - -A `PayslipV2Employment` implements the following attributes: - -* `category` (String): The category of the employment. -* `coefficient` (Float): The coefficient of the employment. -* `collective_agreement` (String): The collective agreement of the employment. -* `job_title` (String): The job title of the employee. -* `position_level` (String): The position level of the employment. -* `start_date` (String): The start date of the employment. -Fields which are specific to this product; they are not used in any other product. - -### Pay Detail Field -Detailed information about the pay. - -A `PayslipV2PayDetail` implements the following attributes: - -* `gross_salary` (Float): The gross salary of the employee. -* `gross_salary_ytd` (Float): The year-to-date gross salary of the employee. -* `income_tax_rate` (Float): The income tax rate of the employee. -* `income_tax_withheld` (Float): The income tax withheld from the employee's pay. -* `net_paid` (Float): The net paid amount of the employee. -* `net_paid_before_tax` (Float): The net paid amount before tax of the employee. -* `net_taxable` (Float): The net taxable amount of the employee. -* `net_taxable_ytd` (Float): The year-to-date net taxable amount of the employee. -* `total_cost_employer` (Float): The total cost to the employer. -* `total_taxes_and_deductions` (Float): The total taxes and deductions of the employee. -Fields which are specific to this product; they are not used in any other product. - -### Pay Period Field -Information about the pay period. - -A `PayslipV2PayPeriod` implements the following attributes: - -* `end_date` (String): The end date of the pay period. -* `month` (String): The month of the pay period. -* `payment_date` (String): The date of payment for the pay period. -* `start_date` (String): The start date of the pay period. -* `year` (String): The year of the pay period. -Fields which are specific to this product; they are not used in any other product. - -### PTO Field -Information about paid time off. - -A `PayslipV2Pto` implements the following attributes: - -* `accrued_this_period` (Float): The amount of paid time off accrued in this period. -* `balance_end_of_period` (Float): The balance of paid time off at the end of the period. -* `used_this_period` (Float): The amount of paid time off used in this period. -Fields which are specific to this product; they are not used in any other product. - -### Salary Details Field -Detailed information about the earnings. - -A `PayslipV2SalaryDetail` implements the following attributes: - -* `amount` (Float): The amount of the earnings. -* `base` (Float): The base value of the earnings. -* `description` (String): The description of the earnings. -* `rate` (Float): The rate of the earnings. - -# Attributes -The following fields are extracted for Payslip V2: - -## Bank Account Details -**bank_account_details** ([PayslipV2BankAccountDetail](#bank-account-details-field)): Information about the employee's bank account. - -```rb -puts result.document.inference.prediction.bank_account_details.value -``` - -## Employee -**employee** ([PayslipV2Employee](#employee-field)): Information about the employee. - -```rb -puts result.document.inference.prediction.employee.value -``` - -## Employer -**employer** ([PayslipV2Employer](#employer-field)): Information about the employer. - -```rb -puts result.document.inference.prediction.employer.value -``` - -## Employment -**employment** ([PayslipV2Employment](#employment-field)): Information about the employment. - -```rb -puts result.document.inference.prediction.employment.value -``` - -## Pay Detail -**pay_detail** ([PayslipV2PayDetail](#pay-detail-field)): Detailed information about the pay. - -```rb -puts result.document.inference.prediction.pay_detail.value -``` - -## Pay Period -**pay_period** ([PayslipV2PayPeriod](#pay-period-field)): Information about the pay period. - -```rb -puts result.document.inference.prediction.pay_period.value -``` - -## PTO -**pto** ([PayslipV2Pto](#pto-field)): Information about paid time off. - -```rb -puts result.document.inference.prediction.pto.value -``` - -## Salary Details -**salary_details** (Array<[PayslipV2SalaryDetail](#salary-details-field)>): Detailed information about the earnings. - -```rb -for salary_details_elem in result.document.inference.prediction.salary_details do - puts salary_details_elem.value -end -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/examples/auto_invoice_splitter_extraction.rb b/examples/auto_invoice_splitter_extraction.rb index cd87989a..b4653002 100644 --- a/examples/auto_invoice_splitter_extraction.rb +++ b/examples/auto_invoice_splitter_extraction.rb @@ -6,7 +6,7 @@ def invoice_splitter_auto_extraction(file_path) mindee_client = Mindee::Client.new(api_key: 'my-api-key') input_source = mindee_client.source_from_path(file_path) - if input_source.pdf? && input_source.count_pdf_pages > 1 + if input_source.pdf? && input_source.count_pages > 1 parse_multi_page(mindee_client, input_source) else parse_single_page(mindee_client, input_source) @@ -22,11 +22,11 @@ def parse_single_page(mindee_client, input_source) end def parse_multi_page(mindee_client, input_source) - pdf_extractor = Mindee::Extraction::PdfExtractor::PdfExtractor.new(input_source) - invoice_splitter_response = mindee_client.enqueue_and_parse( + pdf_extractor = Mindee::PDF::PDFExtractor::PDFExtractor.new(input_source) + invoice_splitter_response = mindee_client.parse( input_source, Mindee::Product::InvoiceSplitter::InvoiceSplitterV1, - close_file: false + options: { close_file: false } ) page_groups = invoice_splitter_response.document.inference.prediction.invoice_page_groups extracted_pdfs = pdf_extractor.extract_invoices(page_groups, strict: false) @@ -38,7 +38,7 @@ def parse_multi_page(mindee_client, input_source) invoice_result = mindee_client.parse( extracted_pdf.as_input_source, Mindee::Product::Invoice::InvoiceV4, - close_file: false + options: { close_file: false } ) puts invoice_result.document end diff --git a/examples/auto_multi_receipts_detector_extraction.rb b/examples/auto_multi_receipts_detector_extraction.rb index 97d95930..6280ecde 100644 --- a/examples/auto_multi_receipts_detector_extraction.rb +++ b/examples/auto_multi_receipts_detector_extraction.rb @@ -1,19 +1,18 @@ # frozen_string_literal: true require 'mindee' -require 'mindee/extraction' mindee_client = Mindee::Client.new(api_key: 'my-api-key') def multi_receipts_detection(file_path, mindee_client) input_source = mindee_client.source_from_path(file_path) - result_split = mindee_client.parse( + result_multi_receipts = mindee_client.parse( input_source, Mindee::Product::MultiReceiptsDetector::MultiReceiptsDetectorV1, - close_file: false + options: { close_file: false } ) - images = Mindee::Extraction::MultiReceiptsExtractor.extract_receipts(input_source, result_split.document.inference) + images = Mindee::Extraction.extract_receipts(input_source, result_multi_receipts.document.inference) images.each do |sub_image| # Optional: Save the files locally # sub_image.write_to_file("/path/to/my/extracted/file/folder") @@ -21,7 +20,7 @@ def multi_receipts_detection(file_path, mindee_client) result_receipt = mindee_client.parse( sub_image.as_source, Mindee::Product::Receipt::ReceiptV5, - close_file: false + options: { close_file: false } ) puts result_receipt.document end diff --git a/lib/mindee.rb b/lib/mindee.rb index ca57a06f..26f2be43 100644 --- a/lib/mindee.rb +++ b/lib/mindee.rb @@ -1,9 +1,17 @@ # frozen_string_literal: true require 'mindee/client' -require 'mindee/extraction' +require 'mindee/logging' module Mindee + # Mindee internal error module. + module Errors + end + + # Custom extraction module + module Extraction + end + # Mindee internal http module. module HTTP end @@ -29,8 +37,8 @@ module ImageCompressor end end - # Custom extraction module - module Extraction + # Logging + module Logging end # Parsing internals and fields. @@ -39,16 +47,12 @@ module Parsing module Common end - # Custom fields and functions. - module Custom - end - # Standard fields and functions. module Standard end - # Generated fields and functions. - module Generated + # Universal fields and functions. + module Universal end end @@ -66,8 +70,17 @@ module EU module FR end + # Indian-specific products. + module IND + end + # US-specific products. module US end end end + +# Shorthand to call the logger from anywhere. +def logger + Mindee::Logging.logger +end diff --git a/lib/mindee/client.rb b/lib/mindee/client.rb index 8ed4a69d..4680efe0 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -4,8 +4,103 @@ require_relative 'http' require_relative 'product' require_relative 'parsing/common/api_response' +require_relative 'parsing/common/job' +require_relative 'parsing/common/workflow_response' +require_relative 'logging' + +# Default owner for products. +OTS_OWNER = 'mindee' module Mindee + # Class for page options in parse calls. + # + # @!attribute page_indexes [Array[Integer]] Zero-based list of page indexes. + # @!attribute operation [:KEEP_ONLY, :REMOVE] Operation to apply on the document, given the specified page indexes: + # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # * `:REMOVE` - remove the specified pages, and keep all others. + # @!attribute on_min_pages [Integer, nil] Apply the operation only if the document has at least this many pages. + class PageOptions + attr_accessor :page_indexes, :operation, :on_min_pages + + def initialize(params: {}) + params ||= {} + params = params.transform_keys(&:to_sym) + @page_indexes = params.fetch( + :page_indexes, + [] # : Array[Integer] + ) + @operation = params.fetch(:operation, :KEEP_ONLY) + @on_min_pages = params.fetch(:on_min_pages, nil) + end + end + + # Class for configuration options in parse calls. + # + # @!attribute all_words [bool] Whether to include the full text for each page. + # This performs a full OCR operation on the server and will increase response time. + # @!attribute full_text [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # @!attribute close_file [bool] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # @!attribute page_options [PageOptions, Hash, nil] Page cutting/merge options: + # * `:page_indexes` Zero-based list of page indexes. + # * `:operation` Operation to apply on the document, given the specified page indexes: + # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # * `:REMOVE` - remove the specified pages, and keep all others. + # * `:on_min_pages` Apply the operation only if the document has at least this many pages. + # @!attribute cropper [bool] Whether to include cropper results for each page. + # This performs a cropping operation on the server and will increase response time. + # @!attribute initial_delay_sec [Numeric] Initial delay before polling. Defaults to 2. + # @!attribute delay_sec [Numeric] Delay between polling attempts. Defaults to 1.5. + # @!attribute max_retries [Integer] Maximum number of retries. Defaults to 80. + class ParseOptions + attr_accessor :all_words, :full_text, :close_file, :page_options, :cropper, + :initial_delay_sec, :delay_sec, :max_retries + + def initialize(params: {}) + params = params.transform_keys(&:to_sym) + @all_words = params.fetch(:all_words, false) + @full_text = params.fetch(:full_text, false) + @close_file = params.fetch(:close_file, true) + raw_page_options = params.fetch(:page_options, nil) + raw_page_options = PageOptions.new(params: raw_page_options) unless raw_page_options.is_a?(PageOptions) + @page_options = raw_page_options + @cropper = params.fetch(:cropper, false) + @initial_delay_sec = params.fetch(:initial_delay_sec, 2) + @delay_sec = params.fetch(:delay_sec, 1.5) + @max_retries = params.fetch(:max_retries, 80) + end + end + + # Class for configuration options in workflow executions. + # + # @!attribute document_alias [String, nil] Alias to give to the document. + # @!attribute priority [Symbol, nil] Priority to give to the document. + # @!attribute full_text [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # @!attribute public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without + # requiring authentication. + # @!attribute page_options [PageOptions, Hash, nil] Page cutting/merge options: + # * `:page_indexes` Zero-based list of page indexes. + # * `:operation` Operation to apply on the document, given the specified page indexes: + # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # * `:REMOVE` - remove the specified pages, and keep all others. + # * `:on_min_pages` Apply the operation only if the document has at least this many pages. + class WorkflowOptions + attr_accessor :document_alias, :priority, :full_text, :public_url, :page_options + + def initialize(params: {}) + params = params.transform_keys(&:to_sym) + @document_alias = params.fetch(:document_alias, nil) + @priority = params.fetch(:priority, nil) + @full_text = params.fetch(:full_text, false) + @public_url = params.fetch(:public_url, nil) + raw_page_options = params.fetch(:page_options, nil) + raw_page_options = PageOptions.new(params: raw_page_options) unless raw_page_options.is_a?(PageOptions) + @page_options = raw_page_options + end + end + # Mindee API Client. # See: https://developers.mindee.com/docs class Client @@ -14,225 +109,235 @@ def initialize(api_key: '') @api_key = api_key end - # Call prediction API on a document and parse the results. - # - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] - # @param product_class [Mindee::Inference] class of the product - # @param endpoint [HTTP::Endpoint] Endpoint of the API - # Doesn't need to be set in the case of OTS APIs. - # - # @param all_words [Boolean] Whether to include the full text for each page. - # This performs a full OCR operation on the server and will increase response time. - # - # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs. - # This performs a full OCR operation on the server and may increase response time. - # - # @param close_file [Boolean] Whether to `close()` the file after parsing it. - # Set to false if you need to access the file after this operation. - # - # @param page_options [Hash, nil] Page cutting/merge options: - # - # * `:page_indexes` Zero-based list of page indexes. - # * `:operation` Operation to apply on the document, given the `page_indexes specified: - # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # * `:REMOVE` - remove the specified pages, and keep all others. - # * `:on_min_pages` Apply the operation only if document has at least this many pages. - # - # @param cropper [Boolean] Whether to include cropper results for each page. - # This performs a cropping operation on the server and will increase response time. + # Enqueue a document for parsing and automatically try to retrieve it if needed. # + # Accepts options either as a Hash or as a ParseOptions struct. # + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # @param product_class [Mindee::Inference] The class of the product. + # @param endpoint [Mindee::HTTP::Endpoint, nil] Endpoint of the API. + # @param options [Hash] A hash of options to configure the parsing behavior. Possible keys: + # * `:all_words` [bool] Whether to extract all the words on each page. + # This performs a full OCR operation on the server and will increase response time. + # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # * `:close_file` [bool] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # * `:page_options` [Hash, nil] Page cutting/merge options: + # - `:page_indexes` [Array] Zero-based list of page indexes. + # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: + # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # - `:REMOVE` - remove the specified pages, and keep all others. + # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. + # * `:cropper` [bool, nil] Whether to include cropper results for each page. + # This performs a cropping operation on the server and will increase response time. + # * `:initial_delay_sec` [Numeric] Initial delay before polling. Defaults to 2. + # * `:delay_sec` [Numeric] Delay between polling attempts. Defaults to 1.5. + # * `:max_retries` [Integer] Maximum number of retries. Defaults to 80. + # @param enqueue [bool] Whether to enqueue the file. # @return [Mindee::Parsing::Common::ApiResponse] - def parse( - input_source, - product_class, - endpoint: nil, - all_words: false, - full_text: false, - close_file: true, - page_options: nil, - cropper: false - ) - if input_source.is_a?(Mindee::Input::Source::LocalInputSource) && !page_options.nil? && input_source.pdf? - input_source.process_pdf(page_options) + def parse(input_source, product_class, endpoint: nil, options: {}, enqueue: true) + opts = normalize_parse_options(options) + process_pdf_if_required(input_source, opts) if input_source.is_a?(Input::Source::LocalInputSource) + endpoint ||= initialize_endpoint(product_class) + + if enqueue && product_class.has_async + enqueue_and_parse(input_source, product_class, endpoint, opts) + else + parse_sync(input_source, product_class, endpoint, opts) end - endpoint = initialize_endpoint(product_class) if endpoint.nil? - prediction, raw_http = endpoint.predict(input_source, all_words, full_text, close_file, cropper) - Mindee::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http) end - # Enqueue a document for async parsing + # Call prediction API on a document and parse the results. # + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # @param product_class [Mindee::Inference] class of the product - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] - # @param endpoint [HTTP::Endpoint, nil] Endpoint of the API. - # Doesn't need to be set in the case of OTS APIs. - # - # @param all_words [Boolean] Whether to extract all the words on each page. - # This performs a full OCR operation on the server and will increase response time. - # - # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs. - # This performs a full OCR operation on the server and may increase response time. - # - # @param close_file [Boolean] Whether to `close()` the file after parsing it. - # Set to false if you need to access the file after this operation. - # - # @param page_options [Hash, nil] Page cutting/merge options: - # - # * `:page_indexes` Zero-based list of page indexes. - # * `:operation` Operation to apply on the document, given the `page_indexes specified: - # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # * `:REMOVE` - remove the specified pages, and keep all others. - # * `:on_min_pages` Apply the operation only if document has at least this many pages. - # - # @param cropper [Boolean] Whether to include cropper results for each page. - # This performs a cropping operation on the server and will increase response time. - # + # @param endpoint [Mindee::HTTP::Endpoint, nil] Endpoint of the API. + # @param options [Hash] A hash of options to configure the parsing behavior. Possible keys: + # * `:all_words` [bool] Whether to extract all the words on each page. + # This performs a full OCR operation on the server and will increase response time. + # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # * `:close_file` [bool] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # * `:page_options` [Hash, nil] Page cutting/merge options: + # - `:page_indexes` [Array] Zero-based list of page indexes. + # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: + # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # - `:REMOVE` - remove the specified pages, and keep all others. + # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. + # * `:cropper` [bool, nil] Whether to include cropper results for each page. + # This performs a cropping operation on the server and will increase response time. + # @return [Mindee::Parsing::Common::ApiResponse] + def parse_sync(input_source, product_class, endpoint, options) + logger.debug("Parsing document as '#{endpoint.url_root}'") + + prediction, raw_http = endpoint.predict( + input_source, + options.all_words, + options.full_text, + options.close_file, + options.cropper + ) + + Mindee::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http) + end + + # Enqueue a document for async parsing # + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # The source of the input document (local file or URL). + # @param product_class [Mindee::Inference] The class of the product. + # @param options [Hash] A hash of options to configure the enqueue behavior. Possible keys: + # * `:endpoint` [HTTP::Endpoint, nil] Endpoint of the API. + # Doesn't need to be set in the case of OTS APIs. + # * `:all_words` [bool] Whether to extract all the words on each page. + # This performs a full OCR operation on the server and will increase response time. + # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # * `:close_file` [bool] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # * `:page_options` [Hash, nil] Page cutting/merge options: + # - `:page_indexes` [Array] Zero-based list of page indexes. + # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: + # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # - `:REMOVE` - remove the specified pages, and keep all others. + # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. + # * `:cropper` [bool] Whether to include cropper results for each page. + # This performs a cropping operation on the server and will increase response time. + # @param endpoint [Mindee::HTTP::Endpoint] Endpoint of the API. # @return [Mindee::Parsing::Common::ApiResponse] - def enqueue( - input_source, - product_class, - endpoint: nil, - all_words: false, - full_text: false, - close_file: true, - page_options: nil, - cropper: false - ) - if input_source.is_a?(Mindee::Input::Source::LocalInputSource) && !page_options.nil? && input_source.pdf? - input_source.process_pdf(page_options) - end - endpoint = initialize_endpoint(product_class) if endpoint.nil? - prediction, raw_http = endpoint.predict_async(input_source, all_words, full_text, close_file, cropper) - Mindee::Parsing::Common::ApiResponse.new(product_class, - prediction, raw_http) + def enqueue(input_source, product_class, endpoint: nil, options: {}) + opts = normalize_parse_options(options) + endpoint ||= initialize_endpoint(product_class) + logger.debug("Enqueueing document as '#{endpoint.url_root}'") + + prediction, raw_http = endpoint.predict_async( + input_source, + opts.all_words, + opts.full_text, + opts.close_file, + opts.cropper + ) + Mindee::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http) end # Parses a queued document # - # @param job_id [String] Id of the job (queue) to poll from + # @param job_id [String] ID of the job (queue) to poll from # @param product_class [Mindee::Inference] class of the product # @param endpoint [HTTP::Endpoint, nil] Endpoint of the API # Doesn't need to be set in the case of OTS APIs. # # @return [Mindee::Parsing::Common::ApiResponse] - def parse_queued( - job_id, - product_class, - endpoint: nil - ) + def parse_queued(job_id, product_class, endpoint: nil) endpoint = initialize_endpoint(product_class) if endpoint.nil? + logger.debug("Fetching queued document as '#{endpoint.url_root}'") prediction, raw_http = endpoint.parse_async(job_id) Mindee::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http) end - # rubocop:disable Metrics/ParameterLists - # Enqueue a document for async parsing and automatically try to retrieve it # - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] - # @param product_class [Mindee::Inference] class of the product - # @param endpoint [HTTP::Endpoint, nil] Endpoint of the API. - # Doesn't need to be set in the case of OTS APIs. - # @param all_words [Boolean] Whether to extract all the words on each page. - # This performs a full OCR operation on the server and will increase response time. - # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs. - # This performs a full OCR operation on the server and may increase response time. - # @param close_file [Boolean] Whether to `close()` the file after parsing it. - # Set to false if you need to access the file after this operation. - # @param page_options [Hash, nil] Page cutting/merge options: - # * `:page_indexes` Zero-based list of page indexes. - # * `:operation` Operation to apply on the document, given the `page_indexes specified: - # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # * `:REMOVE` - remove the specified pages, and keep all others. - # * `:on_min_pages` Apply the operation only if document has at least this many pages. - # @param cropper [Boolean, nil] Whether to include cropper results for each page. - # This performs a cropping operation on the server and will increase response time. - # @param initial_delay_sec [Integer, Float] initial delay before polling. Defaults to 2. - # @param delay_sec [Integer, Float] delay between polling attempts. Defaults to 1.5. - # @param max_retries [Integer] maximum amount of retries. Defaults to 80. + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # The source of the input document (local file or URL). + # @param product_class [Mindee::Inference] The class of the product. + # @param options [Hash] A hash of options to configure the parsing behavior. Possible keys: + # * `:endpoint` [HTTP::Endpoint, nil] Endpoint of the API. + # Doesn't need to be set in the case of OTS APIs. + # * `:all_words` [bool] Whether to extract all the words on each page. + # This performs a full OCR operation on the server and will increase response time. + # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # * `:close_file` [bool] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # * `:page_options` [Hash, nil] Page cutting/merge options: + # - `:page_indexes` [Array] Zero-based list of page indexes. + # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: + # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # - `:REMOVE` - remove the specified pages, and keep all others. + # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. + # * `:cropper` [bool, nil] Whether to include cropper results for each page. + # This performs a cropping operation on the server and will increase response time. + # * `:initial_delay_sec` [Numeric] Initial delay before polling. Defaults to 2. + # * `:delay_sec` [Numeric] Delay between polling attempts. Defaults to 1.5. + # * `:max_retries` [Integer] Maximum number of retries. Defaults to 80. + # @param endpoint [Mindee::HTTP::Endpoint] Endpoint of the API. # @return [Mindee::Parsing::Common::ApiResponse] - def enqueue_and_parse( - input_source, - product_class, - endpoint: nil, - all_words: false, - full_text: false, - close_file: true, - page_options: nil, - cropper: false, - initial_delay_sec: 2, - delay_sec: 1.5, - max_retries: 80 - ) - enqueue_res = enqueue( - input_source, - product_class, - endpoint: endpoint, - all_words: all_words, - full_text: full_text, - close_file: close_file, - page_options: page_options, - cropper: cropper - ) - sleep(initial_delay_sec) + def enqueue_and_parse(input_source, product_class, endpoint, options) + validate_async_params(options.initial_delay_sec, options.delay_sec, options.max_retries) + enqueue_res = enqueue(input_source, product_class, endpoint: endpoint, options: options) + job = enqueue_res.job or raise Errors::MindeeAPIError, 'Expected job to be present' + job_id = job.id + + sleep(options.initial_delay_sec) polling_attempts = 1 - job_id = enqueue_res.job.id + logger.debug("Successfully enqueued document with job id: '#{job_id}'") queue_res = parse_queued(job_id, product_class, endpoint: endpoint) - while queue_res.job.status != Mindee::Parsing::Common::JobStatus::COMPLETED && polling_attempts < max_retries - sleep(delay_sec) + queue_res_job = queue_res.job or raise Errors::MindeeAPIError, 'Expected job to be present' + valid_statuses = [ + Mindee::Parsing::Common::JobStatus::WAITING, + Mindee::Parsing::Common::JobStatus::PROCESSING, + ] + # @type var valid_statuses: Array[(:waiting | :processing | :completed | :failed)] + while valid_statuses.include?(queue_res_job.status) && polling_attempts < options.max_retries + logger.debug("Polling server for parsing result with job id: '#{job_id}'. Attempt #{polling_attempts}") + sleep(options.delay_sec) queue_res = parse_queued(job_id, product_class, endpoint: endpoint) + queue_res_job = queue_res.job or raise Errors::MindeeAPIError, 'Expected job to be present' polling_attempts += 1 end - if queue_res.job.status != Mindee::Parsing::Common::JobStatus::COMPLETED - elapsed = initial_delay_sec + (polling_attempts * delay_sec) - raise "Asynchronous parsing request timed out after #{elapsed} seconds (#{polling_attempts} tries)" + + if queue_res_job.status != Mindee::Parsing::Common::JobStatus::COMPLETED + elapsed = options.initial_delay_sec + (polling_attempts * options.delay_sec.to_f) + raise Errors::MindeeAPIError, + "Asynchronous parsing request timed out after #{elapsed} seconds (#{polling_attempts} tries)" end queue_res end - # rubocop:enable Metrics/ParameterLists - - # Sends a document to a workflow. + # Same idea applies to execute_workflow: # - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] - # @param document_alias [String, nil] Alias to give to the document. - # @param priority [Symbol, nil] Priority to give to the document. - # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs. - # This performs a full OCR operation on the server and may increase response time. - # - # @param public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without - # requiring authentication. - # @param page_options [Hash, nil] Page cutting/merge options: + # Sends a document to a workflow. # - # * `:page_indexes` Zero-based list of page indexes. - # * `:operation` Operation to apply on the document, given the `page_indexes specified: - # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # * `:REMOVE` - remove the specified pages, and keep all others. - # * `:on_min_pages` Apply the operation only if document has at least this many pages. + # Accepts options either as a Hash or as a WorkflowOptions struct. # + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # @param workflow_id [String] + # @param options [Hash, WorkflowOptions] Options to configure workflow behavior. Possible keys: + # * `document_alias` [String, nil] Alias to give to the document. + # * `priority` [Symbol, nil] Priority to give to the document. + # * `full_text` [bool] Whether to include the full OCR text response in compatible APIs. # + # * `public_url` [String, nil] A unique, encrypted URL for accessing the document validation interface without + # requiring authentication. + # * `page_options` [Hash, nil] Page cutting/merge options: + # * `:page_indexes` Zero-based list of page indexes. + # * `:operation` Operation to apply on the document, given the `page_indexes specified: + # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # * `:REMOVE` - remove the specified pages, and keep all others. + # * `:on_min_pages` Apply the operation only if document has at least this many pa # @return [Mindee::Parsing::Common::WorkflowResponse] - def execute_workflow( - input_source, - workflow_id, - document_alias: nil, - priority: nil, - full_text: false, - public_url: nil, - page_options: nil - ) - if input_source.is_a?(Mindee::Input::Source::LocalInputSource) && !page_options.nil? && input_source.pdf? - input_source.process_pdf(page_options) + def execute_workflow(input_source, workflow_id, options: {}) + opts = options.is_a?(WorkflowOptions) ? options : WorkflowOptions.new(params: options) + if opts.respond_to?(:page_options) && input_source.is_a?(Input::Source::LocalInputSource) + process_pdf_if_required(input_source, + opts) end workflow_endpoint = Mindee::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key) - prediction, raw_http = workflow_endpoint.execute_workflow(input_source, full_text, document_alias, priority, - public_url) - Mindee::Parsing::Common::WorkflowResponse.new(Product::Generated::GeneratedV1, - prediction, raw_http) + logger.debug("Sending document to workflow '#{workflow_id}'") + + prediction, raw_http = workflow_endpoint.execute_workflow( + input_source, + opts.full_text, + opts.document_alias, + opts.priority, + opts.public_url + ) + + Mindee::Parsing::Common::WorkflowResponse.new(Product::Universal::Universal, prediction, raw_http) end # Load a prediction. @@ -241,51 +346,56 @@ def execute_workflow( # @param local_response [Mindee::Input::LocalResponse] # @return [Mindee::Parsing::Common::ApiResponse] def load_prediction(product_class, local_response) - Mindee::Parsing::Common::ApiResponse.new(product_class, local_response.as_hash, local_response.as_hash.to_json) - rescue KeyError - raise 'No prediction found in local response.' + raise Errors::MindeeAPIError, 'Expected LocalResponse to not be nil.' if local_response.nil? + + response_hash = local_response.as_hash || {} + raise Errors::MindeeAPIError, 'Expected LocalResponse#as_hash to return a hash.' if response_hash.nil? + + Mindee::Parsing::Common::ApiResponse.new(product_class, response_hash, response_hash.to_json) + rescue KeyError, Errors::MindeeAPIError + raise Errors::MindeeInputError, 'No prediction found in local response.' end # Load a document from an absolute path, as a string. # @param input_path [String] Path of file to open - # @param fix_pdf [Boolean] Attempts to fix broken pdf if true + # @param repair_pdf [bool] Attempts to fix broken pdf if true # @return [Mindee::Input::Source::PathInputSource] - def source_from_path(input_path, fix_pdf: false) - Input::Source::PathInputSource.new(input_path, fix_pdf: fix_pdf) + def source_from_path(input_path, repair_pdf: false) + Input::Source::PathInputSource.new(input_path, repair_pdf: repair_pdf) end # Load a document from raw bytes. # @param input_bytes [String] Encoding::BINARY byte input # @param filename [String] The name of the file (without the path) - # @param fix_pdf [Boolean] Attempts to fix broken pdf if true + # @param repair_pdf [bool] Attempts to fix broken pdf if true # @return [Mindee::Input::Source::BytesInputSource] - def source_from_bytes(input_bytes, filename, fix_pdf: false) - Input::Source::BytesInputSource.new(input_bytes, filename, fix_pdf: fix_pdf) + def source_from_bytes(input_bytes, filename, repair_pdf: false) + Input::Source::BytesInputSource.new(input_bytes, filename, repair_pdf: repair_pdf) end # Load a document from a base64 encoded string. # @param base64_string [String] Input to parse as base64 string # @param filename [String] The name of the file (without the path) - # @param fix_pdf [Boolean] Attempts to fix broken pdf if true + # @param repair_pdf [bool] Attempts to fix broken pdf if true # @return [Mindee::Input::Source::Base64InputSource] - def source_from_b64string(base64_string, filename, fix_pdf: false) - Input::Source::Base64InputSource.new(base64_string, filename, fix_pdf: fix_pdf) + def source_from_b64string(base64_string, filename, repair_pdf: false) + Input::Source::Base64InputSource.new(base64_string, filename, repair_pdf: repair_pdf) end # Load a document from a normal Ruby `File`. # @param input_file [File] Input file handle # @param filename [String] The name of the file (without the path) - # @param fix_pdf [Boolean] Attempts to fix broken pdf if true + # @param repair_pdf [bool] Attempts to fix broken pdf if true # @return [Mindee::Input::Source::FileInputSource] - def source_from_file(input_file, filename, fix_pdf: false) - Input::Source::FileInputSource.new(input_file, filename, fix_pdf: fix_pdf) + def source_from_file(input_file, filename, repair_pdf: false) + Input::Source::FileInputSource.new(input_file, filename, repair_pdf: repair_pdf) end # Load a document from a secure remote source (HTTPS). - # @param url [String] Url of the file - # @return [Mindee::Input::Source::UrlInputSource] + # @param url [String] URL of the file + # @return [Mindee::Input::Source::URLInputSource] def source_from_url(url) - Input::Source::UrlInputSource.new(url) + Input::Source::URLInputSource.new(url) end # Creates a custom endpoint with the given values. @@ -300,29 +410,36 @@ def source_from_url(url) # @param version [String] For custom endpoints, version of the product # @return [Mindee::HTTP::Endpoint] def create_endpoint(endpoint_name: '', account_name: '', version: '') - initialize_endpoint(Mindee::Product::Custom::CustomV1, endpoint_name: endpoint_name, account_name: account_name, - version: version) + initialize_endpoint( + Mindee::Product::Universal::Universal, + endpoint_name: endpoint_name, + account_name: account_name, + version: version + ) end - private - # Validates the parameters for async auto-polling - # @param initial_delay_sec [Integer, Float] initial delay before polling - # @param delay_sec [Integer, Float] delay between polling attempts + # @param initial_delay_sec [Numeric] initial delay before polling + # @param delay_sec [Numeric] delay between polling attempts # @param max_retries [Integer, nil] maximum amount of retries. def validate_async_params(initial_delay_sec, delay_sec, max_retries) min_delay_sec = 1 min_initial_delay_sec = 1 min_retries = 2 - raise "Cannot set auto-poll delay to less than #{min_delay_sec} second(s)" if delay_sec < min_delay_sec + + if delay_sec < min_delay_sec + raise ArgumentError, + "Cannot set auto-poll delay to less than #{min_delay_sec} second(s)" + end if initial_delay_sec < min_initial_delay_sec - raise "Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)" + raise ArgumentError, + "Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)" end - raise "Cannot set auto-poll retries to less than #{min_retries}" if max_retries < min_retries + raise ArgumentError, "Cannot set auto-poll retries to less than #{min_retries}" if max_retries < min_retries end # Creates an endpoint with the given values. Raises an error if the endpoint is invalid. - # @param product_class [Mindee::Inference] class of the product + # @param product_class [Mindee::Parsing::Common::Inference] class of the product # # @param endpoint_name [String] For custom endpoints, the "API name" field in the "Settings" page of the # API Builder. Do not set for standard (off the shelf) endpoints. @@ -333,33 +450,61 @@ def validate_async_params(initial_delay_sec, delay_sec, max_retries) # @param version [String] For custom endpoints, version of the product. # @return [Mindee::HTTP::Endpoint] def initialize_endpoint(product_class, endpoint_name: '', account_name: '', version: '') - if (endpoint_name.nil? || endpoint_name.empty?) && product_class == Mindee::Product::Custom::CustomV1 - raise 'Missing argument endpoint_name when using custom class' + if (endpoint_name.nil? || endpoint_name.empty?) && product_class == Mindee::Product::Universal::Universal + raise Mindee::Errors::MindeeConfigurationError, 'Missing argument endpoint_name when using custom class' end endpoint_name = fix_endpoint_name(product_class, endpoint_name) account_name = fix_account_name(account_name) version = fix_version(product_class, version) + HTTP::Endpoint.new(account_name, endpoint_name, version, api_key: @api_key) end def fix_endpoint_name(product_class, endpoint_name) - return product_class.endpoint_name if endpoint_name.nil? || endpoint_name.empty? - - endpoint_name + endpoint_name.nil? || endpoint_name.empty? ? product_class.endpoint_name : endpoint_name end def fix_account_name(account_name) - return 'mindee' if account_name.nil? || account_name.empty? + if account_name.nil? || account_name.empty? + logger.info("No account name provided, #{OTS_OWNER} will be used by default.") + return OTS_OWNER + end account_name end def fix_version(product_class, version) return version unless version.nil? || version.empty? - return '1' if product_class.endpoint_version.nil? || product_class.endpoint_version.empty? + if product_class.endpoint_version.nil? || product_class.endpoint_version.empty? + logger.debug('No version provided for a custom build, will attempt to poll version 1 by default.') + return '1' + end product_class.endpoint_version end + + # If needed, converts the parsing options provided as a hash into a proper ParseOptions object. + # @param options [Hash, ParseOptions] Options. + # @return [ParseOptions] + def normalize_parse_options(options) + return options if options.is_a?(ParseOptions) + + ParseOptions.new(params: options) + end + + # Processes a PDF if parameters were provided. + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # @param opts [ParseOptions] + def process_pdf_if_required(input_source, opts) + return unless input_source.is_a?(Mindee::Input::Source::LocalInputSource) && + opts.page_options && + input_source.pdf? + + input_source.process_pdf(opts.page_options) + end + + private :parse_sync, :validate_async_params, :initialize_endpoint, :fix_endpoint_name, :fix_version, + :fix_account_name, :process_pdf_if_required, :normalize_parse_options end end diff --git a/lib/mindee/errors.rb b/lib/mindee/errors.rb new file mode 100644 index 00000000..59117d6c --- /dev/null +++ b/lib/mindee/errors.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +require_relative 'errors/mindee_error' +require_relative 'errors/mindee_http_error' +require_relative 'errors/mindee_input_error' diff --git a/lib/mindee/errors/mindee_error.rb b/lib/mindee/errors/mindee_error.rb new file mode 100644 index 00000000..0f0cee39 --- /dev/null +++ b/lib/mindee/errors/mindee_error.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Mindee + module Errors + # Base class for all custom mindee errors. + class MindeeError < StandardError; end + + # Errors relating to library issues. + class MindeeAPIError < MindeeError; end + + # Errors relating to misuse of the library. + class MindeeConfigurationError < MindeeError; end + + # Errors relating to geometric manipulation issues. + class MindeeGeometryError < MindeeError; end + end +end diff --git a/lib/mindee/errors/mindee_http_error.rb b/lib/mindee/errors/mindee_http_error.rb new file mode 100644 index 00000000..1694ef2c --- /dev/null +++ b/lib/mindee/errors/mindee_http_error.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require_relative 'mindee_error' + +module Mindee + module Errors + # API HttpError + class MindeeHTTPError < MindeeError + # @return [String] + attr_reader :status_code + # @return [Integer] + attr_reader :api_code + # @return [String] + attr_reader :api_details + # @return [String] + attr_reader :api_message + + # @param http_error [Hash] + # @param url [String] + # @param code [Integer] + def initialize(http_error, url, code) + @status_code = code + @api_code = http_error['code'] + @api_details = http_error['details'] + @api_message = http_error['message'] + super("#{url} #{@status_code} HTTP error: #{@api_details} - #{@api_message}") + end + end + + # Base class for all client-side errors. + class MindeeHTTPClientError < MindeeHTTPError; end + + # Base class for all server-side errors. + class MindeeHTTPServerError < MindeeHTTPError; end + end +end diff --git a/lib/mindee/errors/mindee_input_error.rb b/lib/mindee/errors/mindee_input_error.rb new file mode 100644 index 00000000..267fea25 --- /dev/null +++ b/lib/mindee/errors/mindee_input_error.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Mindee + module Errors + # Base class for errors relating to input documents. + class MindeeInputError < MindeeError; end + + # Errors relating to sources (documents) handling. + class MindeeSourceError < MindeeInputError; end + + # Errors relating to mime type issues. + class MindeeMimeTypeError < MindeeSourceError + # @return [String] + attr_reader :invalid_mimetype + + # @param mime_type [String] + def initialize(mime_type) + @invalid_mimetype = mime_type + super("'#{@invalid_mimetype}' mime type not allowed, must be one of" \ + "#{Mindee::Input::Source::ALLOWED_MIME_TYPES.join(', ')}") + end + end + + # Errors relating to the handling of images. + class MindeeImageError < MindeeInputError; end + + # Errors relating to the handling of PDF documents. + class MindeePDFError < MindeeInputError; end + end +end diff --git a/lib/mindee/extraction.rb b/lib/mindee/extraction.rb index fdc0cbaf..b10552bd 100644 --- a/lib/mindee/extraction.rb +++ b/lib/mindee/extraction.rb @@ -1,6 +1,3 @@ # frozen_string_literal: true -require_relative 'extraction/tax_extractor' require_relative 'extraction/multi_receipts_extractor' -require_relative 'extraction/common' -require_relative 'extraction/pdf_extractor' diff --git a/lib/mindee/extraction/common.rb b/lib/mindee/extraction/common.rb deleted file mode 100644 index 509d4d4f..00000000 --- a/lib/mindee/extraction/common.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -require_relative 'common/extracted_image' -require_relative 'common/image_extractor' diff --git a/lib/mindee/extraction/multi_receipts_extractor.rb b/lib/mindee/extraction/multi_receipts_extractor.rb index fac4862d..188a0fd0 100644 --- a/lib/mindee/extraction/multi_receipts_extractor.rb +++ b/lib/mindee/extraction/multi_receipts_extractor.rb @@ -1,3 +1,30 @@ # frozen_string_literal: true -require_relative 'multi_receipts_extractor/multi_receipts_extractor' +module Mindee + # Custom extraction module + module Extraction + # Multi-receipts extraction + # Extracts individual receipts from multi-receipts documents. + # + # @param input_source [LocalInputSource] Local Input Source to extract sub-receipts from. + # @param inference [Inference] Results of the inference. + # @return [Array] Individual extracted receipts as an array of ExtractedMultiReceiptsImage. + def self.extract_receipts(input_source, inference) + images = [] + unless inference.prediction.receipts + raise Errors::MindeeInputError, + 'No possible receipts candidates found for Multi-Receipts extraction.' + end + + (0...input_source.count_pages).each do |page_id| + receipt_positions = inference.pages[page_id].prediction.receipts.map(&:bounding_box) + images.concat( + Mindee::Image::ImageExtractor.extract_multiple_images_from_source(input_source, page_id + 1, + receipt_positions) + ) + end + + images + end + end +end diff --git a/lib/mindee/extraction/multi_receipts_extractor/multi_receipts_extractor.rb b/lib/mindee/extraction/multi_receipts_extractor/multi_receipts_extractor.rb deleted file mode 100644 index 6b5bc729..00000000 --- a/lib/mindee/extraction/multi_receipts_extractor/multi_receipts_extractor.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require_relative '../common/image_extractor' - -module Mindee - # Image Extraction Module. - module Extraction - # Multi-receipts extraction class wrapper. - class MultiReceiptsExtractor - def self.extract_receipts(input_source, inference) - # Extracts individual receipts from multi-receipts documents. - # - # @param input_source [LocalInputSource] Local Input Source to extract sub-receipts from. - # @param inference [Inference] Results of the inference. - # @return [Array] Individual extracted receipts as an array of ExtractedMultiReceiptsImage. - - images = [] - raise 'No possible receipts candidates found for MultiReceipts extraction.' unless inference.prediction.receipts - - (0...input_source.count_pdf_pages).each do |page_id| - receipt_positions = inference.pages[page_id].prediction.receipts.map(&:bounding_box) - images.concat( - Mindee::Extraction::ImageExtractor.extract_multiple_images_from_source(input_source, page_id + 1, - receipt_positions) - ) - end - - images - end - end - end -end diff --git a/lib/mindee/extraction/pdf_extractor.rb b/lib/mindee/extraction/pdf_extractor.rb deleted file mode 100644 index 3d44dd98..00000000 --- a/lib/mindee/extraction/pdf_extractor.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -require_relative 'pdf_extractor/pdf_extractor' -require_relative 'pdf_extractor/extracted_pdf' diff --git a/lib/mindee/extraction/tax_extractor.rb b/lib/mindee/extraction/tax_extractor.rb deleted file mode 100644 index f5d3aff8..00000000 --- a/lib/mindee/extraction/tax_extractor.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -require_relative 'tax_extractor/tax_extractor' diff --git a/lib/mindee/extraction/tax_extractor/ocr_extractor.rb b/lib/mindee/extraction/tax_extractor/ocr_extractor.rb deleted file mode 100644 index 94397c6c..00000000 --- a/lib/mindee/extraction/tax_extractor/ocr_extractor.rb +++ /dev/null @@ -1,110 +0,0 @@ -# frozen_string_literal: true - -module Mindee - module Extraction - # Generic extractor class - class OcrExtractor - # Checks for a list of possible matches in a string & returns the index of the first found candidate. - # Case & diacritics insensitive. - # @param text [String] string to search for matches. - # @param str_candidates [Array] array of values to look for - # @return [Integer, nil] - def self.match_index(text, str_candidates) - idx = nil - str_candidates.each do |str_candidate| - found_idx = remove_accents(text.downcase).index(remove_accents(str_candidate.downcase)) - idx = found_idx if idx.nil? - idx = found_idx if !found_idx.nil? && found_idx >= idx - end - idx - end - - # Normalizes text by removing diacritics. - # @param input_str [String] string to handle. - # @return [String] - def self.remove_accents(input_str) - diacritics = [*0x1DC0..0x1DFF, *0x0300..0x036F, *0xFE20..0xFE2F].pack('U*') - input_str - .unicode_normalize(:nfd) - .tr(diacritics, '') - .unicode_normalize(:nfc) - .scrub - end - - # Checks if a given percentage value is within the allowed range - # @param value [Integer] The value to check - # @param min_rate_percentage [Integer] Minimum allowed rate on the tax. - # @param max_rate_percentage [Integer] Maximum allowed rate on the tax. - # @return [Boolean] - def self.valid_percentage?(value, min_rate_percentage, max_rate_percentage) - return false if value.nil? - - value > min_rate_percentage && value < max_rate_percentage - end - - # Parses a percentage from a string, and returns it as a float. - # Returns nil if candidate isn't a valid percentage. - # @param percentage_str [String] String candidate. - # @return [Float, nil] - def self.parse_percentage(percentage_str) - percentage_str.gsub!('%', '') - percentage_str.strip - percentage_str.gsub!(',', '.') - Float(percentage_str.scrub) - rescue ArgumentError - nil - end - - # Parses an amount from a string, and returns it as a float. - # Returns nil if candidate isn't a valid amount. - # @param amount_str [String] String candidate. - # @return [Float, nil] - def self.parse_amount(amount_str) - cleaned_str = amount_str.gsub(' ', '') - cleaned_str = standardize_delimiters(cleaned_str) - Float(cleaned_str) - rescue ArgumentError - nil - end - - private - - def self.standardize_delimiters(str) - if comma_decimal?(str) - str.gsub('.', '').gsub(',', '.') - elsif dot_decimal?(str) - str.gsub(',', '') - else - str - end - end - - def self.comma_decimal?(str) - (str.length > 3 && str[-3] == ',') || str[-2] == ',' - end - - def self.dot_decimal?(str) - (str.length > 3 && str[-3] == '.') || str[-2] == '.' - end - - # Removes most common currency symbols from string - # @param input_string [String] string to remove the symbols from - # @return [String] - def self.remove_currency_symbols(input_string) - # Define an array of common currency symbols - currency_symbols = ['$', '€', '£', '¥', '₹', '₽', '฿', '₺', '₴', '₿', '₡', '₮', '₱', '₲', '₪', '₫', '₩', '₵', - '₦', '₢', '₤', '₣', '₧', '₯', '₠', '₶', '₸', '₷', '₼', '₾', '₺', '﹩', '₨', '₹', '$', '﹫'] - - # Iterate over each currency symbol and remove it from the input string - currency_symbols.each do |symbol| - input_string.gsub!(symbol, '') - end - - input_string - end - - private_class_method :remove_accents, :match_index, :parse_amount, :parse_percentage, :remove_currency_symbols, - :valid_percentage?, :comma_decimal?, :dot_decimal?, :standardize_delimiters - end - end -end diff --git a/lib/mindee/extraction/tax_extractor/tax_extractor.rb b/lib/mindee/extraction/tax_extractor/tax_extractor.rb deleted file mode 100644 index c5e1da55..00000000 --- a/lib/mindee/extraction/tax_extractor/tax_extractor.rb +++ /dev/null @@ -1,338 +0,0 @@ -# frozen_string_literal: true - -require_relative 'ocr_extractor' - -# rubocop:disable Metrics/ClassLength - -module Mindee - module Extraction - # Tax extractor class - class TaxExtractor < OcrExtractor - # Extracts the most relevant candidate. - # @param candidates [Array] a candidate for the tax. - # @param tax_names [Array] list of all possible names the tax can have. - # @return [Hash, nil] - def self.pick_best(candidates, tax_names) - return candidates[0] if candidates.size == 1 - return nil if candidates.empty? - - picked = 0 - picked_score = 0 - - candidates.each_with_index do |candidate, i| - next unless valid_candidate?(candidate, tax_names) - - sum_fields_score = calculate_score(candidate, i) - - if picked_score < sum_fields_score - picked_score = sum_fields_score - picked = i - end - end - - candidates[picked] - end - - # Checks whether a tax code has been properly read. Shouldn't trigger except in case of very specific regex breaks - # due to unsupported diacritics. - # @param candidate [Hash] A candidate for the tax. - # @param tax_names [Array] list of all possible names the tax can have. - # @return [Boolean] - def self.valid_candidate?(candidate, tax_names) - return false if tax_names.empty? || candidate.nil? || candidate['code'].nil? - - tax_names.each do |tax_name| - return true if remove_accents(tax_name.downcase) == remove_accents(candidate['code'].downcase) - end - false - end - - # [Experimental] computes the score of a valid candidate for a tax. - # @param candidate [Hash] A candidate for the tax. - # @param index [Integer] - def self.calculate_score(candidate, index) - score = index + 1 - unless candidate['rate'].nil? - score += 1 - score -= 2 if candidate['rate'] > 100 - score -= 1 if candidate['rate'] > 30 - end - score += 4 unless candidate['value'].nil? - score += 1 unless candidate['base'].nil? - score - end - - # Curates tax values based on simple rules to avoid improbable data - # @param found_hash [Hash] Hash of currently retrieved values - # @param min_rate_percentage [Integer] Minimum allowed rate on the tax. - # @param max_rate_percentage [Integer] Maximum allowed rate on the tax. - # @return [Hash] - def self.curate_values(found_hash, min_rate_percentage, max_rate_percentage) - reconstructed_hash = { 'code' => nil, 'page_id' => nil, 'rate' => nil, 'base' => nil, 'value' => nil } - return reconstructed_hash if found_hash.nil? - - reconstructed_hash['code'] = - found_hash['code'].nil? ? found_hash['code'] : found_hash['code'].sub(%r{\s*\.*\s*$}, '') - - if found_hash['rate'] - if found_hash['rate'].abs < 1 - found_hash['rate'] *= 10 - elsif found_hash['rate'].abs > 100 - found_hash['rate'] /= 10 - end - end - found_hash = swap_rates_if_needed(found_hash, min_rate_percentage, max_rate_percentage) - found_hash = decimate_rates_if_needed(found_hash) - found_hash = fix_rate(found_hash) - reconstructed_hash['rate'] = found_hash['rate'] - set_base_and_value(reconstructed_hash, found_hash) - end - - # Swaps the rate with base or value if rate is out of bounds - # @param found_hash [Hash] Hash of currently retrieved values - # @param min_rate_percentage [Integer] Minimum allowed rate on the tax. - # @param max_rate_percentage [Integer] Maximum allowed rate on the tax. - # @return [Hash] - def self.swap_rates_if_needed(found_hash, min_rate_percentage, max_rate_percentage) - if found_hash['rate'] && (found_hash['rate'] > max_rate_percentage || found_hash['rate'] < min_rate_percentage) - if valid_percentage?(found_hash['base'], min_rate_percentage, max_rate_percentage) - found_hash['rate'], found_hash['base'] = found_hash['base'], found_hash['rate'] - elsif valid_percentage?(found_hash['value'], min_rate_percentage, max_rate_percentage) - found_hash['rate'], found_hash['value'] = found_hash['value'], found_hash['rate'] - end - end - found_hash - end - - # Rates can't be negative if set. - # @param found_hash [Hash] Hash of currently retrieved values - def self.fix_rate(found_hash) - found_hash['rate'] = found_hash['rate'].abs unless found_hash['rate'].nil? - found_hash - end - - # Swaps the rate with base or value if rate is out of bounds - # @param found_hash [Hash] Hash of currently retrieved values - # @return [Hash] - def self.decimate_rates_if_needed(found_hash) - if found_hash['rate'] && found_hash['rate'] > 100 - if !found_hash['base'].nil? && found_hash['rate'] > found_hash['base'] - found_hash['rate'], found_hash['base'] = found_hash['base'], found_hash['rate'] - elsif !found_hash['value'].nil? && found_hash['rate'] > found_hash['value'] - found_hash['rate'], found_hash['value'] = found_hash['value'], found_hash['rate'] - end - end - found_hash - end - - # Sets the base and value in the reconstructed hash based on certain conditions - # @param reconstructed_hash [Hash] Hash being reconstructed with new values - # @param found_hash [Hash] Hash of currently retrieved values - # @return [Hash] - def self.set_base_and_value(reconstructed_hash, found_hash) - base = found_hash['base'] - value = found_hash['value'] - - if base && value - reconstructed_hash['base'], reconstructed_hash['value'] = [base, value].minmax - elsif base - reconstructed_hash['base'] = base - elsif value - reconstructed_hash['value'] = value - calculate_base(reconstructed_hash) - end - - reconstructed_hash - end - - def self.calculate_base(hash) - rate = hash['rate'] - return unless rate&.positive? - - hash['base'] = hash['value'] / (rate / 100.0) - end - - # Extracts a single custom type of tax. - # For the sake of simplicity, this only extracts the first example, unless specifically instructed otherwise. - # @param ocr_result [Mindee::Parsing::Common::Ocr::Ocr] result of the OCR. - # @param tax_names [Array] list of all possible names the tax can have. - # @param min_rate_percentage [Integer] Minimum allowed rate on the tax. - # @param max_rate_percentage [Integer] Maximum allowed rate on the tax. - # @return [Mindee::Parsing::Standard::TaxField, nil] - def self.extract_custom_tax(ocr_result, tax_names, min_rate_percentage = 0, max_rate_percentage = 100) - return nil if ocr_result.is_a?(Mindee::Parsing::Common::Ocr) || tax_names.empty? - - tax_names.sort! - found_hash = pick_best(extract_horizontal_tax(ocr_result, tax_names), tax_names) - if found_hash.nil? || found_hash['value'].nil? - found_hash = extract_vertical_tax(ocr_result, tax_names, - found_hash) - end - found_hash = curate_values(found_hash, min_rate_percentage, max_rate_percentage) - - return if found_hash.nil? || found_hash.empty? - - create_tax_field(found_hash) - end - - # Creates a tax field from a given hash. - # @param found_hash [Hash] Hash of currently retrieved values - # @return [Mindee::Parsing::Standard::TaxField] - def self.create_tax_field(found_hash) - Mindee::Parsing::Standard::TaxField.new( - found_hash, - found_hash.key?('page_id') ? found_hash['page_id'] : nil - ) - end - - # Extracts the rate and code, if found, from matches into the found_hash. - # @param matches [MatchData] RegEx matches of the values for taxes - # @param found_hash [Hash] Hash of currently retrieved values - # @param percent_first [Boolean] Whether the percentage was found before or after the tax name. - # @return [Hash] - def self.extract_percentage_from_tax(matches, found_hash, percent_first) - if percent_first - found_hash['code'] = matches[2].strip unless matches[2].nil? - found_hash['rate'] = parse_amount(matches[1].gsub('%', '')) unless matches[1].nil? - else - found_hash['code'] = matches[1].strip unless matches[1].nil? - found_hash['rate'] = parse_amount(matches[2].gsub('%', '')) unless matches[2].nil? - end - found_hash - end - - # rubocop:disable Metrics/CyclomaticComplexity - # rubocop:disable Metrics/PerceivedComplexity - - # Extracts the basis and value of a tax from regex matches, independent of the order. - # @param matches [MatchData] RegEx matches of the values for taxes - # @param found_hash [Hash] Hash of currently retrieved values - # @return [Hash] - def self.extract_basis_and_value(matches, found_hash) - if matches[4].nil? && !matches[3].nil? - found_hash['value'] = parse_amount(matches[3]) unless matches[3].nil? - elsif matches[3].nil? && !matches[4].nil? - found_hash['value'] = parse_amount(matches[4]) unless matches[4].nil? - elsif !matches[3].nil? && !matches[4].nil? - found_hash['base'] = parse_amount(matches[3]) unless matches[3].nil? - found_hash['value'] = parse_amount(matches[4]) unless matches[4].nil? - end - found_hash - end - - # rubocop:enable Metrics/CyclomaticComplexity - # rubocop:enable Metrics/PerceivedComplexity - - # Extracts tax information from a horizontal line. - # @param line [String] Line to be processed. - # @param pattern [Regexp] RegEx pattern to search the line with. - # @param percent_first [Boolean] Whether the percentage was found before or after the tax name. - # @return [Hash] - def self.extract_tax_from_horizontal_line(line, pattern, page_id, percent_first) - found_hash = {} - - matches = line.match(pattern) - - # Edge case for when the tax is split-up between two pages, we'll consider that - # the answer belongs to the first one. - found_hash['page_id'] = page_id unless found_hash.key?('page_id') - return found_hash if matches.nil? - - found_hash = extract_percentage_from_tax(matches, found_hash, percent_first) - extract_basis_and_value(matches, found_hash) - end - - # rubocop:disable Metrics/CyclomaticComplexity - # rubocop:disable Metrics/PerceivedComplexity - - # Processes a horizontal line for tax extraction. Returns a hash of collected values. - # @param ocr_result [Mindee::Parsing::Common::Ocr::Ocr] Processed OCR results. - # @param tax_names [Array] Possible tax names candidates. - # @return [Array] - def self.extract_horizontal_tax(ocr_result, tax_names) - candidates = [{ 'code' => nil, 'value' => nil, 'base' => nil, 'rate' => nil }] - linear_pattern_percent_first = %r{ - ((?:\s*-\s*)?(?:\d*[.,])*\d+[ ]?%?|%?[ ]?(?:\s*-\s*)?(?:\d*[.,])*\d+)?[ .]? - ([a-zA-ZÀ-ÖØ-öø-ÿ .]*[a-zA-ZÀ-ÖØ-öø-ÿ]?)[ .]? - ((?:\s*-\s*)?(?:\d*[.,])+\d+)?[ .]* - ((?:\s*-\s*)?(\d*[.,])*\d+)? - }x - linear_pattern_percent_second = %r{ - ([a-zA-ZÀ-ÖØ-öø-ÿ .]*[a-zA-ZÀ-ÖØ-öø-ÿ]?)[ .]* - ((?:\s*-\s*)?(?:\d*[.,])*\d+[ ]?%?|%?[ ]?(?:\s*-\s*)?(?:\d*[.,])*\d+)?[ .]? - ((?:\s*-\s*)?(?:\d*[.,])+\d+)?[ .]* - ((?:\s*-\s*)?(\d*[.,])*\d+)? - }x - ocr_result.mvision_v1.pages.each.with_index do |page, page_id| - page.all_lines.each do |line| - clean_line = remove_currency_symbols(line.to_s.scrub.gsub(%r{[+(\[)\]¿?*_]}, '')).gsub(%r{\.{2,}}, ' ') - .gsub(%r{ +}, ' ').strip - - next if match_index(clean_line, tax_names).nil? - - unless clean_line.match(linear_pattern_percent_second).nil? - candidates.append(extract_tax_from_horizontal_line(clean_line[match_index(clean_line, tax_names)..], - linear_pattern_percent_second, page_id, false)) - end - if clean_line.include?('%') && !clean_line.match(linear_pattern_percent_first).nil? - candidates.append(extract_tax_from_horizontal_line(clean_line[clean_line.index(%r{\d*[.,]?\d* ?%})..], - linear_pattern_percent_first, page_id, true)) - elsif !clean_line.match(linear_pattern_percent_first).nil? - candidates.append(extract_tax_from_horizontal_line(clean_line, - linear_pattern_percent_first, page_id, true)) - end - end - end - candidates - end - - # rubocop:enable Metrics/CyclomaticComplexity - # rubocop:enable Metrics/PerceivedComplexity - - # Processes a vertical reconstructed line for tax extraction. Returns a hash of collected values. - # @param line [Mindee::Parsing::Common::Ocr::OcrLine] Processed OCR results. - # @param found_hash [Hash] Hash containing previously found values, if any. - # @return [Hash] - def self.extract_vertical_tax_values(line, found_hash) - amounts = [] - line.each do |reconstructed_word| - amounts.push(parse_amount(reconstructed_word.text)) unless parse_amount(reconstructed_word.text).nil? - end - if amounts.length == 1 && !found_hash.key?('value') - found_hash['value'] = amounts[0] - else - found_hash['rate'] = amounts[0] if found_hash['rate'].nil? - found_hash['value'] = amounts[1] if found_hash['value'].nil? - end - found_hash - end - - # Extracts tax data from a vertical reconstructed row. - # @param ocr_result [Mindee::Parsing::Common::Ocr] OCR raw results - # @param tax_names [Array] Array of possible names a tax can have - # @param found_hash [Hash] Hash of currently retrieved values - def self.extract_vertical_tax(ocr_result, tax_names, found_hash) - found_hash = { 'code' => nil, 'page_id' => nil } if found_hash.nil? - - ocr_result.mvision_v1.pages.each_with_index do |page, page_id| - page.all_words.each do |word| - next if match_index(word.text, tax_names).nil? - - reconstructed_line = ocr_result.reconstruct_vertically(word.polygon, page_id, 0.25) - found_hash['page_id'] = page_id if found_hash['page_id'].nil? - found_hash['code'] = word.text.strip if found_hash['code'].nil? - found_hash = extract_vertical_tax_values(reconstructed_line, found_hash) - end - end - found_hash - end - - private_class_method :extract_percentage_from_tax, :extract_basis_and_value, :extract_tax_from_horizontal_line, - :extract_horizontal_tax, :extract_vertical_tax_values, :extract_vertical_tax, - :create_tax_field, :fix_rate, :pick_best, :calculate_score, :curate_values, - :decimate_rates_if_needed, :set_base_and_value, :valid_candidate?, - :swap_rates_if_needed, :calculate_base - end - end -end -# rubocop:enable Metrics/ClassLength diff --git a/lib/mindee/geometry/polygon.rb b/lib/mindee/geometry/polygon.rb index 8fa6e66c..719f8e8c 100644 --- a/lib/mindee/geometry/polygon.rb +++ b/lib/mindee/geometry/polygon.rb @@ -13,7 +13,7 @@ def centroid # Determine if the Point is in the Polygon's Y-axis. # @param point [Mindee::Geometry::Point] - # @return [Boolean] + # @return [bool] def point_in_y?(point) min_max = Geometry.get_min_max_y(self) min_max.min <= point.y && point.y <= min_max.max diff --git a/lib/mindee/geometry/utils.rb b/lib/mindee/geometry/utils.rb index 09fdfa6a..64bfce19 100644 --- a/lib/mindee/geometry/utils.rb +++ b/lib/mindee/geometry/utils.rb @@ -4,7 +4,7 @@ module Mindee # Various helper functions for geometry. module Geometry # Transform a prediction into a Quadrilateral. - # @param prediction [Hash] + # @param prediction [Array>] # @return [Mindee::Geometry::Quadrilateral] def self.quadrilateral_from_prediction(prediction) throw "Prediction must have exactly 4 points, found #{prediction.size}" if prediction.size != 4 diff --git a/lib/mindee/http.rb b/lib/mindee/http.rb index d4b3375e..5b5a0d60 100644 --- a/lib/mindee/http.rb +++ b/lib/mindee/http.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true require_relative 'http/endpoint' -require_relative 'http/error' +require_relative 'http/http_error_handler' require_relative 'http/workflow_endpoint' diff --git a/lib/mindee/http/endpoint.rb b/lib/mindee/http/endpoint.rb index a1c91352..3700abfc 100644 --- a/lib/mindee/http/endpoint.rb +++ b/lib/mindee/http/endpoint.rb @@ -2,7 +2,7 @@ require 'json' require 'net/http' -require_relative 'error' +require_relative 'http_error_handler' require_relative '../version' require_relative 'response_validation' @@ -24,7 +24,7 @@ module HTTP TIMEOUT_DEFAULT = 120 # Default value for the user agent. - USER_AGENT = "mindee-api-ruby@v#{Mindee::VERSION} ruby-v#{RUBY_VERSION} #{Mindee::PLATFORM}" + USER_AGENT = "mindee-api-ruby@v#{Mindee::VERSION} ruby-v#{RUBY_VERSION} #{Mindee::PLATFORM}".freeze # Generic API endpoint for a product. class Endpoint @@ -40,17 +40,20 @@ def initialize(owner, url_name, version, api_key: '') @url_name = url_name @version = version @request_timeout = ENV.fetch(REQUEST_TIMEOUT_ENV_NAME, TIMEOUT_DEFAULT).to_i + if api_key.nil? && !ENV.fetch(API_KEY_ENV_NAME, API_KEY_DEFAULT).to_s.empty? + logger.debug('API key set from environment') + end @api_key = api_key.nil? || api_key.empty? ? ENV.fetch(API_KEY_ENV_NAME, API_KEY_DEFAULT) : api_key base_url = ENV.fetch(BASE_URL_ENV_NAME, BASE_URL_DEFAULT) @url_root = "#{base_url.chomp('/')}/products/#{@owner}/#{@url_name}/v#{@version}" end # Call the prediction API. - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] - # @param all_words [Boolean] Whether the full word extraction needs to be performed - # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs - # @param close_file [Boolean] Whether the file will be closed after reading - # @param cropper [Boolean] Whether a cropping operation will be applied + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # @param all_words [bool] Whether the full word extraction needs to be performed + # @param full_text [bool] Whether to include the full OCR text response in compatible APIs + # @param close_file [bool] Whether the file will be closed after reading + # @param cropper [bool] Whether a cropping operation will be applied # @return [Array] def predict(input_source, all_words, full_text, close_file, cropper) check_api_key @@ -61,29 +64,34 @@ def predict(input_source, all_words, full_text, close_file, cropper) close_file: close_file, cropper: cropper ) - hashed_response = JSON.parse(response.body, object_class: Hash) - return [hashed_response, response.body] if ResponseValidation.valid_sync_response?(response) + if !response.nil? && response.respond_to?(:body) + hashed_response = JSON.parse(response.body, object_class: Hash) + return [hashed_response, response.body] if ResponseValidation.valid_sync_response?(response) - ResponseValidation.clean_request!(response) - error = Error.handle_error(@url_name, response) + ResponseValidation.clean_request!(response) + end + error = ErrorHandler.handle_error(@url_name, response) raise error end # Call the prediction API. - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] - # @param all_words [Boolean] Whether the full word extraction needs to be performed - # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs. - # @param close_file [Boolean] Whether the file will be closed after reading - # @param cropper [Boolean] Whether a cropping operation will be applied + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # @param all_words [bool] Whether the full word extraction needs to be performed + # @param full_text [bool] Whether to include the full OCR text response in compatible APIs. + # @param close_file [bool] Whether the file will be closed after reading + # @param cropper [bool] Whether a cropping operation will be applied # @return [Array] def predict_async(input_source, all_words, full_text, close_file, cropper) check_api_key response = document_queue_req_get(input_source, all_words, full_text, close_file, cropper) - hashed_response = JSON.parse(response.body, object_class: Hash) - return [hashed_response, response.body] if ResponseValidation.valid_async_response?(response) + if !response.nil? && response.respond_to?(:body) + hashed_response = JSON.parse(response.body, object_class: Hash) + return [hashed_response, response.body] if ResponseValidation.valid_async_response?(response) - ResponseValidation.clean_request!(response) - error = Error.handle_error(@url_name, response) + ResponseValidation.clean_request!(response) + end + + error = ErrorHandler.handle_error(@url_name, response) raise error end @@ -97,22 +105,22 @@ def parse_async(job_id) return [hashed_response, response.body] if ResponseValidation.valid_async_response?(response) ResponseValidation.clean_request!(response) - error = Error.handle_error(@url_name, response) + error = ErrorHandler.handle_error(@url_name, response) raise error end private - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] - # @param all_words [Boolean] Whether the full word extraction needs to be performed - # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs. - # @param close_file [Boolean] Whether the file will be closed after reading - # @param cropper [Boolean] Whether a cropping operation will be applied + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # @param all_words [bool] Whether the full word extraction needs to be performed + # @param full_text [bool] Whether to include the full OCR text response in compatible APIs. + # @param close_file [bool] Whether the file will be closed after reading + # @param cropper [bool] Whether a cropping operation will be applied # @return [Net::HTTPResponse, nil] def predict_req_post(input_source, all_words: false, full_text: false, close_file: true, cropper: false) uri = URI("#{@url_root}/predict") - params = {} + params = {} # : Hash[Symbol | String, untyped] params[:cropper] = 'true' if cropper params[:full_text_ocr] = 'true' if full_text uri.query = URI.encode_www_form(params) @@ -122,10 +130,10 @@ def predict_req_post(input_source, all_words: false, full_text: false, close_fil 'User-Agent' => USER_AGENT, } req = Net::HTTP::Post.new(uri, headers) - form_data = if input_source.is_a?(Mindee::Input::Source::UrlInputSource) + form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource) [['document', input_source.url]] else - [input_source.read_document(close: close_file)] + [input_source.read_contents(close: close_file)] end form_data.push ['include_mvision', 'true'] if all_words @@ -137,16 +145,16 @@ def predict_req_post(input_source, all_words: false, full_text: false, close_fil response end - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] - # @param all_words [Boolean] Whether the full word extraction needs to be performed - # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs. - # @param close_file [Boolean] Whether the file will be closed after reading - # @param cropper [Boolean] Whether a cropping operation will be applied + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # @param all_words [bool] Whether the full word extraction needs to be performed + # @param full_text [bool] Whether to include the full OCR text response in compatible APIs. + # @param close_file [bool] Whether the file will be closed after reading + # @param cropper [bool] Whether a cropping operation will be applied # @return [Net::HTTPResponse, nil] def document_queue_req_get(input_source, all_words, full_text, close_file, cropper) uri = URI("#{@url_root}/predict_async") - params = {} + params = {} # : Hash[Symbol | String, untyped] params[:cropper] = 'true' if cropper params[:full_text_ocr] = 'true' if full_text uri.query = URI.encode_www_form(params) @@ -156,10 +164,10 @@ def document_queue_req_get(input_source, all_words, full_text, close_file, cropp 'User-Agent' => USER_AGENT, } req = Net::HTTP::Post.new(uri, headers) - form_data = if input_source.is_a?(Mindee::Input::Source::UrlInputSource) + form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource) [['document', input_source.url]] else - [input_source.read_document(close: close_file)] + [input_source.read_contents(close: close_file)] end form_data.push ['include_mvision', 'true'] if all_words @@ -201,9 +209,9 @@ def document_queue_req(job_id) def check_api_key return unless @api_key.nil? || @api_key.empty? - raise "Missing API key for product \"'#{@url_name}' v#{@version}\" (belonging to \"#{@owner}\"), " \ - "check your Client Configuration.\n" \ - 'You can set this using the ' \ + raise Errors::MindeeAPIError, + "Missing API key for product \"'#{@url_name}' v#{@version}\" (belonging to \"#{@owner}\"), " \ + "check your Client Configuration.\nYou can set this using the " \ "'#{HTTP::API_KEY_ENV_NAME}' environment variable." end end diff --git a/lib/mindee/http/error.rb b/lib/mindee/http/http_error_handler.rb similarity index 74% rename from lib/mindee/http/error.rb rename to lib/mindee/http/http_error_handler.rb index 84a7368c..b4ade5ac 100644 --- a/lib/mindee/http/error.rb +++ b/lib/mindee/http/http_error_handler.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true require 'json' +require_relative '../errors/mindee_http_error' module Mindee module HTTP # Mindee HTTP error module. - module Error + module ErrorHandler module_function # Extracts the HTTP error from the response hash, or the job error if there is one. @@ -80,44 +81,13 @@ def handle_error(url, response) error_obj = create_error_obj(parsed_hash) case code when 400..499 - MindeeHttpClientError.new(error_obj, url, code) + Errors::MindeeHTTPClientError.new(error_obj, url, code) when 500..599 - MindeeHttpServerError.new(error_obj, url, code) + Errors::MindeeHTTPServerError.new(error_obj, url, code) else - MindeeHttpError.new(error_obj, url, code) + Errors::MindeeHTTPError.new(error_obj, url, code) end end - - # API HttpError - class MindeeHttpError < StandardError - # @return [String] - attr_reader :status_code - # @return [Integer] - attr_reader :api_code - # @return [String] - attr_reader :api_details - # @return [String] - attr_reader :api_message - - # @param http_error [Hash] - # @param url [String] - # @param code [Integer] - def initialize(http_error, url, code) - @status_code = code - @api_code = http_error['code'] - @api_details = http_error['details'] - @api_message = http_error['message'] - super("#{url} #{@status_code} HTTP error: #{@api_details} - #{@api_message}") - end - end - - # API client HttpError - class MindeeHttpClientError < MindeeHttpError - end - - # API server HttpError - class MindeeHttpServerError < MindeeHttpError - end end end end diff --git a/lib/mindee/http/response_validation.rb b/lib/mindee/http/response_validation.rb index 69416618..4e7004c3 100644 --- a/lib/mindee/http/response_validation.rb +++ b/lib/mindee/http/response_validation.rb @@ -9,7 +9,7 @@ module HTTP module ResponseValidation # Checks if the synchronous response is valid. Returns True if the response is valid. # @param [Net::HTTPResponse] response - # @return [Boolean] + # @return [bool] def self.valid_sync_response?(response) return false unless (200..399).cover?(response.code.to_i) @@ -24,7 +24,7 @@ def self.valid_sync_response?(response) # Checks if the asynchronous response is valid. Also checks if it is a valid synchronous response. # Returns true if the response is valid. # @param [Net::HTTPResponse] response - # @return [Boolean] + # @return [bool] def self.valid_async_response?(response) return false unless valid_sync_response?(response) diff --git a/lib/mindee/http/workflow_endpoint.rb b/lib/mindee/http/workflow_endpoint.rb index 79e08897..28af8530 100644 --- a/lib/mindee/http/workflow_endpoint.rb +++ b/lib/mindee/http/workflow_endpoint.rb @@ -2,7 +2,7 @@ require 'json' require 'net/http' -require_relative 'error' +require_relative 'http_error_handler' module Mindee module HTTP @@ -23,10 +23,10 @@ def initialize(workflow_id, api_key: '') end # Sends a document to the workflow. - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # @param document_alias [String, nil] Alias to give to the document. # @param priority [Symbol, nil] Priority to give to the document. - # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs. + # @param full_text [bool] Whether to include the full OCR text response in compatible APIs. # @param public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without # requiring authentication. # @return [Array] @@ -37,20 +37,20 @@ def execute_workflow(input_source, full_text, document_alias, priority, public_u return [hashed_response, response.body] if ResponseValidation.valid_async_response?(response) ResponseValidation.clean_request!(response) - error = Error.handle_error(@url_name, response) + error = Mindee::HTTP::ErrorHandler.handle_error(@url_name, response) raise error end - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # @param document_alias [String, nil] Alias to give to the document. # @param priority [Symbol, nil] Priority to give to the document. - # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs. + # @param full_text [bool] Whether to include the full OCR text response in compatible APIs. # @param public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without # requiring authentication. # @return [Net::HTTPResponse, nil] def workflow_execution_req_post(input_source, document_alias, priority, full_text, public_url) uri = URI(@url) - params = {} + params = {} # : Hash[Symbol | String, untyped] params[:full_text_ocr] = 'true' if full_text uri.query = URI.encode_www_form(params) @@ -59,10 +59,10 @@ def workflow_execution_req_post(input_source, document_alias, priority, full_tex 'User-Agent' => USER_AGENT, } req = Net::HTTP::Post.new(uri, headers) - form_data = if input_source.is_a?(Mindee::Input::Source::UrlInputSource) + form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource) [['document', input_source.url]] else - [input_source.read_document] + [input_source.read_contents] end form_data.push ['alias', document_alias] if document_alias form_data.push ['public_url', public_url] if public_url @@ -81,9 +81,9 @@ def workflow_execution_req_post(input_source, document_alias, priority, full_tex def check_api_key return unless @api_key.nil? || @api_key.empty? - raise "Missing API key. Check your Client Configuration.\n" \ - 'You can set this using the ' \ - "'#{HTTP::API_KEY_ENV_NAME}' environment variable." + raise Errors::MindeeConfigurationError, "Missing API key. Check your Client Configuration.\n" \ + "You can set this using the '#{HTTP::API_KEY_ENV_NAME}'" \ + 'environment variable.' end end end diff --git a/lib/mindee/image.rb b/lib/mindee/image.rb index 51406f83..5664bc8f 100644 --- a/lib/mindee/image.rb +++ b/lib/mindee/image.rb @@ -1,4 +1,6 @@ # frozen_string_literal: true +require_relative 'image/extracted_image' require_relative 'image/image_compressor' +require_relative 'image/image_extractor' require_relative 'image/image_utils' diff --git a/lib/mindee/extraction/common/extracted_image.rb b/lib/mindee/image/extracted_image.rb similarity index 60% rename from lib/mindee/extraction/common/extracted_image.rb rename to lib/mindee/image/extracted_image.rb index 44a4fb07..ff764de6 100644 --- a/lib/mindee/extraction/common/extracted_image.rb +++ b/lib/mindee/image/extracted_image.rb @@ -1,16 +1,17 @@ # frozen_string_literal: true -require_relative '../../input/sources' +require_relative '../input/sources' +require_relative '../logging' module Mindee # Image Extraction Module. - module Extraction + module Image # Generic class for image extraction. class ExtractedImage - # Id of the page the image was extracted from. + # ID of the page the image was extracted from. attr_reader :page_id - # Id of the element on a given page. + # ID of the element on a given page. attr_reader :element_id # Buffer object of the file's content. @@ -25,14 +26,15 @@ class ExtractedImage # @param page_id [Integer] ID of the page the element was found on. # @param element_id [Integer, nil] ID of the element in a page. def initialize(input_source, page_id, element_id) - @buffer = StringIO.new(input_source.io_stream.read) + @buffer = StringIO.new(input_source.io_stream.read.to_s) @buffer.rewind extension = if input_source.pdf? - 'jpg' + '.jpg' else File.extname(input_source.filename) end - @internal_file_name = "#{input_source.filename}_p#{page_id}_#{element_id}.#{extension}" + base_name = File.basename(input_source.filename, File.extname(input_source.filename)) + @internal_file_name = "#{base_name}_p#{page_id}_#{element_id}#{extension}" @page_id = page_id @element_id = element_id.nil? ? 0 : element_id end @@ -43,21 +45,23 @@ def initialize(input_source, page_id, element_id) # @param file_format [String, nil] Optional MiniMagick-compatible format for the file. Inferred from file # extension if not provided. # @raise [MindeeError] If an invalid path or filename is provided. - def save_to_file(output_path, file_format = nil) - resolved_path = Pathname.new(output_path).realpath + def write_to_file(output_path, file_format = nil) + resolved_path = Pathname.new(File.expand_path(output_path)) if file_format.nil? - raise ArgumentError, 'Invalid file format.' if resolved_path.extname.delete('.').empty? + raise Errors::MindeeImageError, 'Invalid file format.' if resolved_path.extname.delete('.').empty? file_format = resolved_path.extname.delete('.').upcase end - @buffer.rewind - image = MiniMagick::Image.read(@buffer) - image.format file_format.downcase - image.write resolved_path.to_s - rescue TypeError - raise 'Invalid path/filename provided.' - rescue StandardError - raise "Could not save file #{Pathname.new(output_path).basename}." + begin + @buffer.rewind + image = MiniMagick::Image.read(@buffer) + image.format file_format.to_s.downcase + image.write resolved_path.to_s + logger.info("File saved successfully to '#{resolved_path}'") + rescue StandardError + raise Errors::MindeeImageError, "Could not save file '#{output_path}'. " \ + 'Is the provided file path valid?.' + end end # Return the file as a Mindee-compatible BufferInput source. diff --git a/lib/mindee/extraction/common/image_extractor.rb b/lib/mindee/image/image_extractor.rb similarity index 55% rename from lib/mindee/extraction/common/image_extractor.rb rename to lib/mindee/image/image_extractor.rb index acd2bd7a..6f0f1173 100644 --- a/lib/mindee/extraction/common/image_extractor.rb +++ b/lib/mindee/image/image_extractor.rb @@ -4,20 +4,19 @@ require 'origami' require 'stringio' require 'tempfile' -require_relative '../../input/sources' +require_relative '../input/sources' require_relative 'extracted_image' module Mindee # Image Extraction Module. - module Extraction + module Image # Image Extraction wrapper class. module ImageExtractor + # Attaches an image as a new page in a PdfDocument object. + # + # @param [StringIO] input_buffer Input buffer. Only supports JPEG. + # @return [Origami::PDF] A PdfDocument handle. def self.attach_image_as_new_file(input_buffer, format: 'jpg') - # Attaches an image as a new page in a PdfDocument object. - # - # @param [StringIO] input_buffer Input buffer. Only supports JPEG. - # @return [Origami::PDF] A PdfDocument handle. - magick_image = MiniMagick::Image.read(input_buffer) # NOTE: some jpeg images get rendered as three different versions of themselves per output if the format isn't # converted. @@ -35,9 +34,9 @@ def self.attach_image_as_new_file(input_buffer, format: 'jpg') # @param [Integer] page_id ID of the Page to extract from. # @param [Array>, Array] polygons List of coordinates # to extract. - # @return [Array] Extracted Images. + # @return [Array] Extracted Images. def self.extract_multiple_images_from_source(input_source, page_id, polygons) - new_stream = load_input_source_pdf_page_as_image(input_source, page_id) + new_stream = load_input_source_pdf_page_as_stringio(input_source, page_id) new_stream.seek(0) extract_images_from_polygons(input_source, new_stream, page_id, polygons) @@ -49,13 +48,13 @@ def self.extract_multiple_images_from_source(input_source, page_id, polygons) # @param [StringIO] pdf_stream Buffer of the PDF. # @param [Integer] page_id Page ID. # @param [Array] polygons - # @return [Array] Extracted Images. + # @return [Array] Extracted Images. def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygons) extracted_elements = [] polygons.each_with_index do |polygon, element_id| - polygon = normalize_polygon(polygon) - page_content = read_page_content(pdf_stream) + polygon = ImageUtils.normalize_polygon(polygon) + page_content = ImageUtils.read_page_content(pdf_stream) min_max_x = Geometry.get_min_max_x([ polygon.top_left, @@ -69,16 +68,16 @@ def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygon polygon.top_right, polygon.bottom_left, ]) - file_extension = determine_file_extension(input_source) - cropped_image = crop_image(page_content, min_max_x, min_max_y) + file_extension = ImageUtils.determine_file_extension(input_source) + cropped_image = ImageUtils.crop_image(page_content, min_max_x, min_max_y) if file_extension == 'pdf' cropped_image.format('jpg') else - cropped_image.format(file_extension) + cropped_image.format(file_extension.to_s) end buffer = StringIO.new - write_image_to_buffer(cropped_image, buffer) + ImageUtils.write_image_to_buffer(cropped_image, buffer) file_name = "#{input_source.filename}_page#{page_id}-#{element_id}.#{file_extension}" extracted_elements << create_extracted_image(buffer, file_name, page_id, element_id) @@ -87,73 +86,16 @@ def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygon extracted_elements end - # Retrieves the bounding box of a polygon. - # - # @param [Array, Mindee::Geometry::Polygon] polygon - def self.normalize_polygon(polygon) - if polygon.is_a?(Mindee::Geometry::Polygon) - Mindee::Geometry.get_bounding_box(polygon) - else - polygon - end - end - - # Loads a buffer into a MiniMagick Image. - # - # @param [StringIO] pdf_stream Buffer containg the PDF - # @return [MiniMagick::Image] a valid MiniMagick image handle. - def self.read_page_content(pdf_stream) - pdf_stream.rewind - MiniMagick::Image.read(pdf_stream) - end - - # Crops a MiniMagick Image from a the given bounding box. - # - # @param [MiniMagick::Image] image Input Image. - # @param [Mindee::Geometry::MinMax] min_max_x minimum & maximum values for the x coordinates. - # @param [Mindee::Geometry::MinMax] min_max_y minimum & maximum values for the y coordinates. - def self.crop_image(image, min_max_x, min_max_y) - width = image[:width].to_i - height = image[:height].to_i - - image.format('jpg') - new_width = (min_max_x.max - min_max_x.min) * width - new_height = (min_max_y.max - min_max_y.min) * height - image.crop("#{new_width}x#{new_height}+#{min_max_x.min * width}+#{min_max_y.min * height}") - - image - end - - # Writes a MiniMagick::Image to a buffer. - # - # @param [MiniMagick::Image] image a valid MiniMagick image. - # @param [StringIO] buffer - def self.write_image_to_buffer(image, buffer) - image.write(buffer) - end - - # Retrieves the file extension from the main file to apply it to the extracted images. Note: coerces pdf as jpg. - # - # @param [Mindee::Input::Source::LocalInputSource] input_source Local input source. - # @return [String] A valid file extension. - def self.determine_file_extension(input_source) - if input_source.pdf? || input_source.filename.downcase.end_with?('pdf') - 'jpg' - else - File.extname(input_source.filename).strip.downcase[1..] - end - end - # Generates an ExtractedImage. # # @param [StringIO] buffer Buffer containing the image. # @param [String] file_name Name for the file. - # @param [Object] page_id ID of the page the file was generated from. + # @param [Object] page_id ID of the page the file was universal from. # @param [Object] element_id ID of the element of a given page. def self.create_extracted_image(buffer, file_name, page_id, element_id) buffer.rewind ExtractedImage.new( - Mindee::Input::Source::BytesInputSource.new(buffer.read, file_name), + Mindee::Input::Source::BytesInputSource.new(buffer.read.to_s, file_name), page_id, element_id ) @@ -163,11 +105,11 @@ def self.create_extracted_image(buffer, file_name, page_id, element_id) # # @param input_file [LocalInputSource] Local input. # @param [Integer] page_id Page ID. - # @return [MiniMagick::Image] A valid PdfDocument handle. - def self.load_input_source_pdf_page_as_image(input_file, page_id) + # @return [StringIO] A valid PdfDocument handle. + def self.load_input_source_pdf_page_as_stringio(input_file, page_id) input_file.io_stream.rewind if input_file.pdf? - Mindee::PDF::PdfProcessor.get_page(Origami::PDF.read(input_file.io_stream), page_id) + Mindee::PDF::PDFProcessor.get_page(Origami::PDF.read(input_file.io_stream), page_id) else input_file.io_stream end diff --git a/lib/mindee/image/image_utils.rb b/lib/mindee/image/image_utils.rb index d839cdf5..5accd8f1 100644 --- a/lib/mindee/image/image_utils.rb +++ b/lib/mindee/image/image_utils.rb @@ -30,13 +30,14 @@ def self.compress_image_quality(image, quality) # @param [MiniMagick::Image, StringIO, File, Tempfile] image The input image # @return [MiniMagick::Image] def self.to_image(image) - if image.respond_to?(:read) && image.respond_to?(:rewind) + if image.is_a?(MiniMagick::Image) + image + elsif image.is_a?(StringIO) || image.is_a?(IO) || image.is_a?(File) || image.is_a?(Tempfile) image.rewind MiniMagick::Image.read(image) - elsif image.is_a?(MiniMagick::Image) - image else - raise "Expected an I/O object or a MiniMagick::Image. '#{image.class}' given instead." + img_class = image.class ? image.class.to_s : 'unknown format' + raise Errors::MindeeImageError, "Expected an I/O object or a MiniMagick::Image. '#{img_class}' given instead." end end @@ -59,7 +60,7 @@ def self.image_to_stringio(image, format = 'JPEG') # @param max_width [Integer] Maximum width. If not specified, the horizontal ratio will remain the same. # @param max_height [Integer] Maximum height. If not specified, the vertical ratio will remain the same. def self.calculate_new_dimensions(original, max_width: nil, max_height: nil) - raise 'Provided image could not be processed for resizing.' if original.nil? + raise Errors::MindeeImageError, 'Provided image could not be processed for resizing.' if original.nil? return [original.width, original.height] if max_width.nil? && max_height.nil? @@ -68,8 +69,8 @@ def self.calculate_new_dimensions(original, max_width: nil, max_height: nil) scale_factor = [width_ratio, height_ratio].min - new_width = (original.width * scale_factor).to_i - new_height = (original.height * scale_factor).to_i + new_width = (original.width.to_f * scale_factor).to_i + new_height = (original.height.to_f * scale_factor).to_i [new_width, new_height] end @@ -99,6 +100,66 @@ def self.pdf_to_magick_image(pdf_stream, image_quality) compressed_image.quality image_quality.to_s compressed_image end + + # Retrieves the bounding box of a polygon. + # + # @param [Array, Mindee::Geometry::Polygon] polygon + def self.normalize_polygon(polygon) + if polygon.is_a?(Mindee::Geometry::Polygon) || + (polygon.is_a?(Array) && polygon[0].is_a?(Mindee::Geometry::Point)) + Mindee::Geometry.get_bounding_box(polygon) + elsif polygon.is_a?(Mindee::Geometry::Quadrilateral) + polygon + else + raise Errors::MindeeGeometryError, 'Provided polygon has an invalid type.' + end + end + + # Loads a buffer into a MiniMagick Image. + # + # @param [StringIO] pdf_stream Buffer containg the PDF + # @return [MiniMagick::Image] a valid MiniMagick image handle. + def self.read_page_content(pdf_stream) + pdf_stream.rewind + MiniMagick::Image.read(pdf_stream) + end + + # Crops a MiniMagick Image from a the given bounding box. + # + # @param [MiniMagick::Image] image Input Image. + # @param [Mindee::Geometry::MinMax] min_max_x minimum & maximum values for the x coordinates. + # @param [Mindee::Geometry::MinMax] min_max_y minimum & maximum values for the y coordinates. + def self.crop_image(image, min_max_x, min_max_y) + width = image[:width].to_i + height = image[:height].to_i + + image.format('jpg') + new_width = (min_max_x.max - min_max_x.min) * width + new_height = (min_max_y.max - min_max_y.min) * height + image.crop("#{new_width}x#{new_height}+#{min_max_x.min * width}+#{min_max_y.min * height}") + + image + end + + # Writes a MiniMagick::Image to a buffer. + # + # @param [MiniMagick::Image] image a valid MiniMagick image. + # @param [StringIO] buffer + def self.write_image_to_buffer(image, buffer) + image.write(buffer) + end + + # Retrieves the file extension from the main file to apply it to the extracted images. Note: coerces pdf as jpg. + # + # @param [Mindee::Input::Source::LocalInputSource] input_source Local input source. + # @return [String, nil] A valid file extension. + def self.determine_file_extension(input_source) + if input_source.pdf? || input_source.filename.downcase.end_with?('pdf') + 'jpg' + else + File.extname(input_source.filename.to_s).strip.downcase[1..].to_s + end + end end end end diff --git a/lib/mindee/input/local_response.rb b/lib/mindee/input/local_response.rb index 88736f97..e4b4df29 100644 --- a/lib/mindee/input/local_response.rb +++ b/lib/mindee/input/local_response.rb @@ -16,18 +16,18 @@ class LocalResponse def initialize(input_file) case input_file when IO, StringIO, File, Tempfile - str_stripped = input_file.read.gsub(%r{[\r\n]}, '') + str_stripped = input_file.read.to_s.gsub(%r{[\r\n]}, '') @file = StringIO.new(str_stripped) @file.rewind when Pathname, String - @file = if Pathname(input_file).exist? - StringIO.new(File.read(input_file, encoding: 'utf-8').gsub(%r{[\r\n]}, '')) + @file = if Pathname(input_file.to_s).exist? + StringIO.new(File.read(input_file.to_s, encoding: 'utf-8').gsub(%r{[\r\n]}, '')) else - StringIO.new(input_file.gsub(%r{[\r\n]}, '')) + StringIO.new(input_file.to_s.gsub(%r{[\r\n]}, '')) end @file.rewind else - raise "Incompatible type for input '#{input_file.class}'." + raise Errors::MindeeInputError, "Incompatible type for input '#{input_file.class}'." end end @@ -38,7 +38,7 @@ def as_hash file_str = @file.read JSON.parse(file_str, object_class: Hash) rescue JSON::ParserError - raise "File is not a valid dict. #{file_str}" + raise Errors::MindeeInputError, "File is not a valid dict. #{file_str}" end # Processes the secret key @@ -56,14 +56,14 @@ def get_hmac_signature(secret_key) @file.rewind mac = OpenSSL::HMAC.hexdigest(algorithm, self.class.process_secret_key(secret_key), @file.read) rescue StandardError - raise 'Could not get HMAC signature from payload.' + raise Errors::MindeeInputError, 'Could not get HMAC signature from payload.' end mac end # @param secret_key [String] Secret key, either a string or a byte/byte array. # @param signature [String] - # @return [Boolean] + # @return [bool] def valid_hmac_signature?(secret_key, signature) signature == get_hmac_signature(secret_key) end diff --git a/lib/mindee/input/sources/base64_input_source.rb b/lib/mindee/input/sources/base64_input_source.rb index 2cee59aa..f3cd2a82 100644 --- a/lib/mindee/input/sources/base64_input_source.rb +++ b/lib/mindee/input/sources/base64_input_source.rb @@ -9,17 +9,17 @@ module Source class Base64InputSource < LocalInputSource # @param base64_string [String] # @param filename [String] - # @param fix_pdf [Boolean] - def initialize(base64_string, filename, fix_pdf: false) - io_stream = StringIO.new(base64_string.unpack1('m*')) + # @param repair_pdf [bool] + def initialize(base64_string, filename, repair_pdf: false) + io_stream = StringIO.new(base64_string.unpack1('m*').to_s) io_stream.set_encoding Encoding::BINARY - super(io_stream, filename, fix_pdf: fix_pdf) + super(io_stream, filename, repair_pdf: repair_pdf) end # Overload of the same function to prevent a base64 from being re-encoded. - # @param close [Boolean] + # @param close [bool] # @return [Array] - def read_document(close: true) + def read_contents(close: true) @io_stream.seek(0) data = @io_stream.read @io_stream.close if close diff --git a/lib/mindee/input/sources/bytes_input_source.rb b/lib/mindee/input/sources/bytes_input_source.rb index 601a6f12..b51ae987 100644 --- a/lib/mindee/input/sources/bytes_input_source.rb +++ b/lib/mindee/input/sources/bytes_input_source.rb @@ -9,11 +9,11 @@ module Source class BytesInputSource < LocalInputSource # @param raw_bytes [String] # @param filename [String] - # @param fix_pdf [Boolean] - def initialize(raw_bytes, filename, fix_pdf: false) + # @param repair_pdf [bool] + def initialize(raw_bytes, filename, repair_pdf: false) io_stream = StringIO.new(raw_bytes) io_stream.set_encoding Encoding::BINARY - super(io_stream, filename, fix_pdf: fix_pdf) + super(io_stream, filename, repair_pdf: repair_pdf) end end end diff --git a/lib/mindee/input/sources/file_input_source.rb b/lib/mindee/input/sources/file_input_source.rb index 3705fd57..ee5f676f 100644 --- a/lib/mindee/input/sources/file_input_source.rb +++ b/lib/mindee/input/sources/file_input_source.rb @@ -9,10 +9,10 @@ module Source class FileInputSource < LocalInputSource # @param input_file [File] # @param filename [String] - # @param fix_pdf [Boolean] - def initialize(input_file, filename, fix_pdf: false) + # @param repair_pdf [bool] + def initialize(input_file, filename, repair_pdf: false) io_stream = input_file - super(io_stream, filename, fix_pdf: fix_pdf) + super(io_stream, filename, repair_pdf: repair_pdf) end end end diff --git a/lib/mindee/input/sources/local_input_source.rb b/lib/mindee/input/sources/local_input_source.rb index 1d2dadea..7cef27c9 100644 --- a/lib/mindee/input/sources/local_input_source.rb +++ b/lib/mindee/input/sources/local_input_source.rb @@ -2,6 +2,7 @@ require 'stringio' require 'marcel' +require 'fileutils' require_relative '../../pdf' require_relative '../../image' @@ -20,29 +21,6 @@ module Source 'image/webp', ].freeze - # Standard error for invalid mime types - class MimeTypeError < StandardError - end - - # Error sent if the file's mimetype isn't allowed - class InvalidMimeTypeError < MimeTypeError - # @return [String] - attr_reader :invalid_mimetype - - # @param mime_type [String] - def initialize(mime_type) - @invalid_mimetype = mime_type - super("'#{@invalid_mimetype}' mime type not allowed, must be one of #{ALLOWED_MIME_TYPES.join(', ')}") - end - end - - # Error sent if a pdf file couldn't be fixed - class UnfixablePDFError < MimeTypeError - def initialize - super("Corrupted PDF couldn't be repaired.") - end - end - # Base class for loading documents. class LocalInputSource # @return [String] @@ -52,27 +30,31 @@ class LocalInputSource # @return [StringIO] attr_reader :io_stream - # @param io_stream [StringIO] + # @param io_stream [StringIO, File] # @param filename [String] - # @param fix_pdf [Boolean] - def initialize(io_stream, filename, fix_pdf: false) + # @param repair_pdf [bool] + def initialize(io_stream, filename, repair_pdf: false) @io_stream = io_stream @filename = filename - @file_mimetype = if fix_pdf + @file_mimetype = if repair_pdf Marcel::MimeType.for @io_stream else Marcel::MimeType.for @io_stream, name: @filename end - return if ALLOWED_MIME_TYPES.include? @file_mimetype + if ALLOWED_MIME_TYPES.include? @file_mimetype + logger.debug("Loaded new input #{@filename} from #{self.class}") + return + end - if filename.end_with?('.pdf') && fix_pdf + if filename.end_with?('.pdf') && repair_pdf rescue_broken_pdf(@io_stream) @file_mimetype = Marcel::MimeType.for @io_stream + logger.debug("Loaded new input #{@filename} from #{self.class}") return if ALLOWED_MIME_TYPES.include? @file_mimetype end - raise InvalidMimeTypeError, @file_mimetype.to_s + raise Errors::MindeeMimeTypeError, @file_mimetype.to_s end # Attempts to fix pdf files if mimetype is rejected. @@ -81,7 +63,7 @@ def initialize(io_stream, filename, fix_pdf: false) # @param stream [StringIO] def rescue_broken_pdf(stream) stream.gets('%PDF-') - raise UnfixablePDFError if stream.eof? || stream.pos > 500 + raise Errors::MindeePDFError if stream.eof? || stream.pos > 500 stream.pos = stream.pos - 5 data = stream.read @@ -97,7 +79,7 @@ def pdf? end # Parses a PDF file according to provided options. - # @param options [Hash, nil] Page cutting/merge options: + # @param options [PageOptions, nil] Page cutting/merge options: # # * `:page_indexes` Zero-based list of page indexes. # * `:operation` Operation to apply on the document, given the `page_indexes specified: @@ -106,25 +88,45 @@ def pdf? # * `:on_min_pages` Apply the operation only if document has at least this many pages. def process_pdf(options) @io_stream.seek(0) - @io_stream = PdfProcessor.parse(@io_stream, options) + @io_stream = PDF::PDFProcessor.parse(@io_stream, options) end # Reads a document. - # @param close [Boolean] + # @param close [bool] # @return [Array] - def read_document(close: true) + def read_contents(close: true) + logger.debug("Reading data from: #{@filename}") @io_stream.seek(0) # Avoids needlessly re-packing some files data = @io_stream.read + @io_stream.rewind @io_stream.close if close ['document', data, { filename: Mindee::Input::Source.convert_to_unicode_escape(@filename) }] end - def count_pdf_pages + # Write the file to a given path. Uses the initial file name by default. + # @param path [String] Path to write the file to. + def write_to_file(path) + full_path = if File.directory?(path) || path.end_with?('/') + File.join(path, @filename) + else + path + end + FileUtils.mkdir_p(File.dirname(full_path)) + @io_stream.rewind + File.binwrite(full_path, @io_stream.read) + logger.debug("Wrote file successfully to #{full_path}") + @io_stream.rewind + end + + # Returns the page count for a document. + # Defaults to one for images. + # @return [Integer] + def count_pages return 1 unless pdf? @io_stream.seek(0) - pdf_processor = Mindee::PDF::PdfProcessor.open_pdf(@io_stream) + pdf_processor = Mindee::PDF::PDFProcessor.open_pdf(@io_stream) pdf_processor.pages.size end @@ -132,10 +134,10 @@ def count_pdf_pages # @param [Integer] quality Quality of the output file. # @param [Integer, nil] max_width Maximum width (Ignored for PDFs). # @param [Integer, nil] max_height Maximum height (Ignored for PDFs). - # @param [Boolean] force_source_text Whether to force the operation on PDFs with source text. + # @param [bool] force_source_text Whether to force the operation on PDFs with source text. # This will attempt to re-render PDF text over the rasterized original. If disabled, ignored the operation. # WARNING: this operation is strongly discouraged. - # @param [Boolean] disable_source_text If the PDF has source text, whether to re-apply it to the original or + # @param [bool] disable_source_text If the PDF has source text, whether to re-apply it to the original or # not. Needs force_source_text to work. def compress!(quality: 85, max_width: nil, max_height: nil, force_source_text: false, disable_source_text: true) buffer = if pdf? @@ -158,7 +160,7 @@ def compress!(quality: 85, max_width: nil, max_height: nil, force_source_text: f end # Checks whether the file has source text if it is a pdf. False otherwise - # @return [Boolean] True if the file is a PDF and has source text. + # @return [bool] True if the file is a PDF and has source text. def source_text? Mindee::PDF::PDFTools.source_text?(@io_stream) end @@ -171,7 +173,7 @@ def self.convert_to_unicode_escape(string) unicode_escape_string = ''.dup string.each_char do |char| unicode_escape_string << if char.bytesize > 1 - "\\u#{char.unpack1('U').to_s(16).rjust(4, '0')}" + "\\u#{format('%04x', char.unpack1('U'))}" else char end diff --git a/lib/mindee/input/sources/path_input_source.rb b/lib/mindee/input/sources/path_input_source.rb index 18438b9a..2902de7e 100644 --- a/lib/mindee/input/sources/path_input_source.rb +++ b/lib/mindee/input/sources/path_input_source.rb @@ -9,10 +9,10 @@ module Source # Load a document from a path. class PathInputSource < LocalInputSource # @param filepath [String] - # @param fix_pdf [Boolean] - def initialize(filepath, fix_pdf: false) + # @param repair_pdf [bool] + def initialize(filepath, repair_pdf: false) io_stream = File.open(filepath, 'rb') - super(io_stream, File.basename(filepath), fix_pdf: fix_pdf) + super(io_stream, File.basename(filepath), repair_pdf: repair_pdf) end end end diff --git a/lib/mindee/input/sources/url_input_source.rb b/lib/mindee/input/sources/url_input_source.rb index 5b4a9b13..e344fe5b 100644 --- a/lib/mindee/input/sources/url_input_source.rb +++ b/lib/mindee/input/sources/url_input_source.rb @@ -3,17 +3,20 @@ require 'net/http' require 'uri' require 'fileutils' +require_relative '../../logging' module Mindee module Input module Source # Load a remote document from a file url. - class UrlInputSource + class URLInputSource # @return [String] attr_reader :url def initialize(url) - raise 'URL must be HTTPS' unless url.start_with? 'https://' + raise Errors::MindeeInputError, 'URL must be HTTPS' unless url.start_with? 'https://' + + logger.debug("URL input: #{url}") @url = url end @@ -27,7 +30,7 @@ def initialize(url) # @param token [String, nil] Optional token for JWT-based authentication. # @param max_redirects [Integer] Maximum amount of redirects to follow. # @return [String] The full path of the saved file. - def save_to_file(path, filename: nil, username: nil, password: nil, token: nil, max_redirects: 3) + def write_to_file(path, filename: nil, username: nil, password: nil, token: nil, max_redirects: 3) response_body = fetch_file_content(username: username, password: password, token: token, max_redirects: max_redirects) @@ -53,7 +56,7 @@ def as_local_input_source(filename: nil, username: nil, password: nil, token: ni max_redirects: max_redirects) bytes = StringIO.new(response_body) - BytesInputSource.new(bytes.read, filename) + BytesInputSource.new(bytes.read || '', filename || '') end # Fetches the file content from the URL. @@ -72,9 +75,9 @@ def fetch_file_content(username: nil, password: nil, token: nil, max_redirects: response = make_request(uri, request, max_redirects) if response.code.to_i > 299 - raise "Failed to download file: HTTP status code #{response.code}" + raise Errors::MindeeAPIError, "Failed to download file: HTTP status code #{response.code}" elsif response.code.to_i < 200 - raise "Failed to download file: Invalid response code #{response.code}." + raise Errors::MindeeAPIError, "Failed to download file: Invalid response code #{response.code}." end response.body @@ -83,7 +86,7 @@ def fetch_file_content(username: nil, password: nil, token: nil, max_redirects: private def extract_filename_from_url(uri) - filename = File.basename(uri.path) + filename = File.basename(uri.path.to_s) filename.empty? ? '' : filename end @@ -100,7 +103,7 @@ def make_request(uri, request, max_redirects) response = http.request(request) if response.is_a?(Net::HTTPRedirection) && max_redirects.positive? location = response['location'] - raise 'No location in redirection header.' if location.nil? + raise Errors::MindeeInputError, 'No location in redirection header.' if location.nil? new_uri = URI.parse(location) request = Net::HTTP::Get.new(new_uri) diff --git a/lib/mindee/logging.rb b/lib/mindee/logging.rb new file mode 100644 index 00000000..72a5cf0f --- /dev/null +++ b/lib/mindee/logging.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require_relative 'logging/logger' diff --git a/lib/mindee/logging/logger.rb b/lib/mindee/logging/logger.rb new file mode 100644 index 00000000..ec60b5eb --- /dev/null +++ b/lib/mindee/logging/logger.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'logger' + +module Mindee + # Mindee logging module. + module Logging + @logger = Logger.new($stdout) + log_level = ENV.fetch('MINDEE_LOG_LEVEL', 'WARN') + @logger.level = Logger.const_get(log_level) + + class << self + attr_accessor :logger + end + end +end diff --git a/lib/mindee/parsing.rb b/lib/mindee/parsing.rb index 53fe85ff..02bc8c24 100644 --- a/lib/mindee/parsing.rb +++ b/lib/mindee/parsing.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true require_relative 'parsing/standard' -require_relative 'parsing/custom' require_relative 'parsing/common' -require_relative 'parsing/generated' +require_relative 'parsing/universal' diff --git a/lib/mindee/parsing/common.rb b/lib/mindee/parsing/common.rb index d08452cb..50d727ac 100644 --- a/lib/mindee/parsing/common.rb +++ b/lib/mindee/parsing/common.rb @@ -1,12 +1,15 @@ # frozen_string_literal: true +require_relative 'common/api_request' require_relative 'common/api_response' require_relative 'common/document' require_relative 'common/execution' require_relative 'common/execution_file' require_relative 'common/execution_priority' require_relative 'common/inference' +require_relative 'common/job' require_relative 'common/ocr' require_relative 'common/prediction' require_relative 'common/orientation' require_relative 'common/page' +require_relative 'common/workflow_response' diff --git a/lib/mindee/parsing/common/api_request.rb b/lib/mindee/parsing/common/api_request.rb new file mode 100644 index 00000000..c9e8876e --- /dev/null +++ b/lib/mindee/parsing/common/api_request.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module Common + # HTTP request response. + class ApiRequest + # @return [Hash] + attr_reader :error + # @return [Array] + attr_reader :ressources + # @return [RequestStatus, Symbol] + attr_reader :status + # @return [Integer] + attr_reader :status_code + # @return [String] + attr_reader :url + + def initialize(server_response) + @error = server_response['error'] + @ressources = server_response['ressources'] + + @status = if server_response['status'] == 'failure' + RequestStatus::FAILURE + elsif server_response['status'] == 'success' + RequestStatus::SUCCESS + else + server_response['status']&.to_sym + end + @status_code = server_response['status_code'] + @url = server_response['url'] + end + end + end + end +end diff --git a/lib/mindee/parsing/common/api_response.rb b/lib/mindee/parsing/common/api_response.rb index 3a01184a..9456badb 100644 --- a/lib/mindee/parsing/common/api_response.rb +++ b/lib/mindee/parsing/common/api_response.rb @@ -1,21 +1,17 @@ # frozen_string_literal: true require_relative 'document' -require 'time' +require_relative '../../logging' module Mindee module Parsing module Common # Potential values for queue in asynchronous calls. module JobStatus - # Document is waiting to be processed. - WAITING = :waiting - # Document is currently being parsed. + WAITING = :waiting PROCESSING = :processing - # Document parsing is complete. - COMPLETED = :completed - # Job failed - FAILURE = :failed + COMPLETED = :completed + FAILURE = :failed end # Potential values for requests. @@ -26,72 +22,6 @@ module RequestStatus SUCCESS = :success end - # Job (queue) information on async parsing. - class Job - # @return [String] Mindee ID of the document - attr_reader :id - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :issued_at - # @return [Time, nil] - attr_reader :available_at - # @return [JobStatus, Symbol] - attr_reader :status - # @return [Integer, nil] - attr_reader :millisecs_taken - # @return [Hash, nil] - attr_reader :error - - # @param http_response [Hash] - def initialize(http_response) - @id = http_response['id'] - @error = http_response['error'] - @issued_at = Time.iso8601(http_response['issued_at']) - if http_response.key?('available_at') && !http_response['available_at'].nil? - @available_at = Time.iso8601(http_response['available_at']) - @millisecs_taken = (1000 * (@available_at.to_time - @issued_at.to_time).to_f).to_i - end - @status = case http_response['status'] - when 'waiting' - JobStatus::WAITING - when 'processing' - JobStatus::PROCESSING - when 'completed' - JobStatus::COMPLETED - else - http_response['status']&.to_sym - end - end - end - - # HTTP request response. - class ApiRequest - # @return [Hash] - attr_reader :error - # @return [Array] - attr_reader :ressources - # @return [RequestStatus, Symbol] - attr_reader :status - # @return [Integer] - attr_reader :status_code - # @return [String] - attr_reader :url - - def initialize(server_response) - @error = server_response['error'] - @ressources = server_response['ressources'] - - @status = if server_response['status'] == 'failure' - RequestStatus::FAILURE - elsif server_response['status'] == 'success' - RequestStatus::SUCCESS - else - server_response['status']&.to_sym - end - @status_code = server_response['status_code'] - @url = server_response['url'] - end - end - # Wrapper class for all predictions (synchronous and asynchronous) class ApiResponse # @return [Mindee::Parsing::Common::Document, nil] @@ -107,8 +37,9 @@ class ApiResponse # @param http_response [Hash] # @param raw_http [String] def initialize(product_class, http_response, raw_http) + logger.debug('Handling API response') @raw_http = raw_http.to_s - raise 'Invalid response format.' unless http_response.key?('api_request') + raise Errors::MindeeAPIError, 'Invalid response format.' unless http_response.key?('api_request') @api_request = Mindee::Parsing::Common::ApiRequest.new(http_response['api_request']) @@ -121,27 +52,6 @@ def initialize(product_class, http_response, raw_http) @job = Mindee::Parsing::Common::Job.new(http_response['job']) if http_response.key?('job') end end - - # Represents the server response after a document is sent to a workflow. - class WorkflowResponse - # Set the prediction model used to parse the document. - # The response object will be instantiated based on this parameter. - # @return [Mindee::Parsing::Common::Execution] - attr_reader :execution - # @return [Mindee::Parsing::Common::ApiRequest] - attr_reader :api_request - # @return [String] - attr_reader :raw_http - - # @param http_response [Hash] - # @param product_class [Mindee::Inference] - def initialize(product_class, http_response, raw_http) - @raw_http = raw_http.to_s - @api_request = Mindee::Parsing::Common::ApiRequest.new(http_response['api_request']) - product_class = (product_class || Product::Generated::GeneratedV1) - @execution = Mindee::Parsing::Common::Execution.new(product_class, http_response['execution']) - end - end end end end diff --git a/lib/mindee/parsing/common/document.rb b/lib/mindee/parsing/common/document.rb index a5d09fad..ad1d7c1c 100644 --- a/lib/mindee/parsing/common/document.rb +++ b/lib/mindee/parsing/common/document.rb @@ -16,25 +16,29 @@ class Document attr_reader :id # @return [Mindee::Parsing::Common::Extras::Extras] Potential Extras fields sent back along the prediction. attr_reader :extras - # @return [Mindee::Parsing::Common::Ocr::Ocr, nil] OCR text results (limited availability) + # @return [Mindee::Parsing::Common::OCR::OCR, nil] OCR text results (limited availability) attr_reader :ocr # @return [Integer] Amount of pages of the document attr_reader :n_pages - # @param http_response [Hash] - # @return [Mindee::Parsing::Common::Ocr::Ocr] + # Loads the MVision OCR response. + # @param http_response [Hash] Full HTTP contents of the response. + # @return [Mindee::Parsing::Common::OCR::OCR] def self.load_ocr(http_response) ocr_prediction = http_response.fetch('ocr', nil) return nil if ocr_prediction.nil? || ocr_prediction.fetch('mvision-v1', nil).nil? - Ocr::Ocr.new(ocr_prediction) + OCR::OCR.new(ocr_prediction) end - def self.load_extras(http_response) + # Loads extras into the document prediction. + # @param http_response [Hash] Full HTTP contents of the response. + # @return [Mindee::Parsing::Common::OCR::OCR] + def self.extract_extras(http_response) extras_prediction = http_response['inference'].fetch('extras', nil) return nil if extras_prediction.nil? || extras_prediction.fetch('mvision-v1', nil).nil? - Extras::Extras::Extras.new(extras_prediction) + Mindee::Parsing::Common::Extras::Extras.new(extras_prediction) end # @param product_class [Mindee::Inference] @@ -44,7 +48,7 @@ def initialize(product_class, http_response) @name = http_response['name'] @inference = product_class.new(http_response['inference']) @ocr = self.class.load_ocr(http_response) - @extras = self.class.load_extras(http_response) + @extras = self.class.extract_extras(http_response) inject_full_text_ocr(http_response) @n_pages = http_response['n_pages'] end @@ -69,7 +73,7 @@ def inject_full_text_ocr(raw_prediction) end artificial_text_obj = { 'content' => full_text_ocr } if @extras.nil? || @extras.empty? - @extras = Extras::Extras.new({ 'full_text_ocr' => artificial_text_obj }) + @extras = Mindee::Parsing::Common::Extras::Extras.new({ 'full_text_ocr' => artificial_text_obj }) else @extras.add_artificial_extra({ 'full_text_ocr' => artificial_text_obj }) end diff --git a/lib/mindee/parsing/common/execution.rb b/lib/mindee/parsing/common/execution.rb index d0e080e4..906505bf 100644 --- a/lib/mindee/parsing/common/execution.rb +++ b/lib/mindee/parsing/common/execution.rb @@ -30,7 +30,7 @@ class Execution # @return [Time, nil] attr_reader :available_at # Reviewed fields and values. - # @return [Mindee::Product::Generated::GeneratedV1Document] + # @return [Mindee::Product::Universal::UniversalDocument] attr_reader :reviewed_prediction # Execution Status. # @return [String] @@ -59,7 +59,9 @@ def initialize(product_class, http_response) @reviewed_at = Time.iso8601(http_response['reviewed_at']) if http_response['reviewed_at'] @available_at = Time.iso8601(http_response['available_at']) if http_response['available_at'] if http_response['reviewed_prediction'] - @reviewed_prediction = GeneratedV1Document.new(http_response['reviewed_prediction']) + @reviewed_prediction = Mindee::Product::Universal::UniversalDocument.new( + http_response['reviewed_prediction'] + ) end @status = http_response['status'] @type = http_response['type'] diff --git a/lib/mindee/parsing/common/execution_priority.rb b/lib/mindee/parsing/common/execution_priority.rb index da474fd7..5d3876f8 100644 --- a/lib/mindee/parsing/common/execution_priority.rb +++ b/lib/mindee/parsing/common/execution_priority.rb @@ -5,8 +5,14 @@ module Parsing module Common # Execution policy priority values. module ExecutionPriority + # Low priority execution. + # @return [Symbol] :low LOW = :low + # Medium priority execution. + # @return [Symbol] :low MEDIUM = :medium + # High priority execution. + # @return [Symbol] :low HIGH = :high # Sets the priority to one of its possibly values, defaults to nil otherwise. diff --git a/lib/mindee/parsing/common/extras/cropper_extra.rb b/lib/mindee/parsing/common/extras/cropper_extra.rb index cd4cd6bd..1e5c4976 100644 --- a/lib/mindee/parsing/common/extras/cropper_extra.rb +++ b/lib/mindee/parsing/common/extras/cropper_extra.rb @@ -13,12 +13,13 @@ class CropperExtra attr_reader :croppings def initialize(raw_prediction, page_id = nil) - @croppings = [] + @croppings = [] # : Array[Mindee::Parsing::Standard::PositionField] raw_prediction['cropping']&.each do |crop| @croppings.push(Mindee::Parsing::Standard::PositionField.new(crop, page_id)) end end + # @return [String] def to_s @croppings.map(&:to_s).join("\n ") end diff --git a/lib/mindee/parsing/common/extras/extras.rb b/lib/mindee/parsing/common/extras/extras.rb index 4bc3bae2..4298880c 100644 --- a/lib/mindee/parsing/common/extras/extras.rb +++ b/lib/mindee/parsing/common/extras/extras.rb @@ -11,18 +11,23 @@ module Extras class Extras # @return [CropperExtra, nil] attr_reader :cropper - # @return [FullTextOCRExtra, nil] + # @return [Mindee::Parsing::Common::Extras::FullTextOCRExtra, nil] attr_reader :full_text_ocr def initialize(raw_prediction) - @cropper = CropperExtra.new(raw_prediction['cropper']) if raw_prediction['cropper'] - @full_text_ocr = FullTextOCRExtra.new(raw_prediction['full_text_ocr']) if raw_prediction['full_text_ocr'] + if raw_prediction['cropper'] + @cropper = Mindee::Parsing::Common::Extras::CropperExtra.new(raw_prediction['cropper']) + end + if raw_prediction['full_text_ocr'] + @full_text_ocr = Mindee::Parsing::Common::Extras::FullTextOCRExtra.new(raw_prediction['full_text_ocr']) + end raw_prediction.each do |key, value| instance_variable_set("@#{key}", value) unless ['cropper', 'full_text_ocr'].include?(key) end end + # @return [String] def to_s out_str = String.new instance_variables.each do |var| @@ -37,7 +42,7 @@ def to_s def add_artificial_extra(raw_prediction) return unless raw_prediction['full_text_ocr'] - @full_text_ocr << FullTextOCRExtra.new(raw_prediction) + @full_text_ocr << Mindee::Parsing::Common::Extras::FullTextOCRExtra.new(raw_prediction) end end diff --git a/lib/mindee/parsing/common/extras/full_text_ocr_extra.rb b/lib/mindee/parsing/common/extras/full_text_ocr_extra.rb index 45bffa50..55fe243d 100644 --- a/lib/mindee/parsing/common/extras/full_text_ocr_extra.rb +++ b/lib/mindee/parsing/common/extras/full_text_ocr_extra.rb @@ -22,6 +22,7 @@ def initialize(raw_prediction) @language = raw_prediction['language'] end + # @return [String] def to_s @contents || '' end diff --git a/lib/mindee/parsing/common/inference.rb b/lib/mindee/parsing/common/inference.rb index 443a1fa5..7212a6d8 100644 --- a/lib/mindee/parsing/common/inference.rb +++ b/lib/mindee/parsing/common/inference.rb @@ -9,7 +9,7 @@ module Common # Abstract class for prediction Inferences # Holds prediction for a page or entire document. class Inference - # @return [Boolean] + # @return [bool] attr_reader :is_rotation_applied # @return [Array] attr_reader :pages @@ -17,12 +17,29 @@ class Inference attr_reader :prediction # @return [Mindee::Parsing::Common::Product] attr_reader :product + # Name of the endpoint for this product. + # @return [String] + attr_reader :endpoint_name + # Version for this product. + # @return [String] + attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync + + @endpoint_name = nil + @endpoint_version = nil + @has_async = false + @has_sync = false # @param raw_prediction [Hash] def initialize(raw_prediction) @is_rotation_applied = raw_prediction['is_rotation_applied'] @product = Product.new(raw_prediction['product']) - @pages = [] + @pages = [] # : Array[Page] end # @return [String] @@ -34,8 +51,10 @@ def to_s out_str << "\n:Rotation applied: #{is_rotation_applied}" out_str << "\n\nPrediction\n==========" out_str << "\n#{@prediction.to_s.size.positive? ? "#{@prediction}\n" : ''}" - out_str << "\nPage Predictions\n================\n\n" unless @pages.empty? - out_str << @pages.map(&:to_s).join("\n\n") + if @pages.any? { |page| !page.prediction.nil? } + out_str << "\nPage Predictions\n================\n\n" + out_str << @pages.map(&:to_s).join("\n\n") + end out_str.rstrip! out_str end diff --git a/lib/mindee/parsing/common/job.rb b/lib/mindee/parsing/common/job.rb new file mode 100644 index 00000000..a48dad19 --- /dev/null +++ b/lib/mindee/parsing/common/job.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'time' + +module Mindee + module Parsing + module Common + # Job (queue) information on async parsing. + class Job + # @return [String] Mindee ID of the document + attr_reader :id + # @return [Time] + attr_reader :issued_at + # @return [Time, nil] + attr_reader :available_at + # @return [JobStatus, Symbol] + attr_reader :status + # @return [Integer, nil] + attr_reader :millisecs_taken + # @return [Hash, nil] + attr_reader :error + + # @param http_response [Hash] + def initialize(http_response) + @id = http_response['id'] + @error = http_response['error'] + @issued_at = Time.iso8601(http_response['issued_at']) + if http_response.key?('available_at') && !http_response['available_at'].nil? + @available_at = Time.iso8601(http_response['available_at']) + @millisecs_taken = (1000 * (@available_at.to_time - @issued_at.to_time).to_f).to_i + end + @status = case http_response['status'] + when 'waiting' + JobStatus::WAITING + when 'processing' + JobStatus::PROCESSING + when 'completed' + JobStatus::COMPLETED + else + http_response['status']&.to_sym + end + end + end + end + end +end diff --git a/lib/mindee/parsing/common/ocr/mvision_v1.rb b/lib/mindee/parsing/common/ocr/mvision_v1.rb index ff26f0cf..69f05e2b 100644 --- a/lib/mindee/parsing/common/ocr/mvision_v1.rb +++ b/lib/mindee/parsing/common/ocr/mvision_v1.rb @@ -3,18 +3,18 @@ module Mindee module Parsing module Common - module Ocr + module OCR # Mindee Vision V1. class MVisionV1 # List of pages. - # @return [Array] + # @return [Array] attr_reader :pages # @param prediction [Hash] def initialize(prediction) - @pages = [] + @pages = [] # : Array[Mindee::Parsing::Common::OCR::OCRPage] prediction['pages'].each do |page_prediction| - @pages.push(OcrPage.new(page_prediction)) + @pages.push(OCRPage.new(page_prediction)) end end @@ -33,9 +33,9 @@ def to_s # start. # @param page_id [Integer] ID of the page to start at # @param x_margin [Float] Margin of misalignment for the x coordinate. - # @return [Mindee::Parsing::Common::Ocr::OcrLine] + # @return [Mindee::Parsing::Common::OCR::OCRLine] def reconstruct_vertically(coordinates, page_id, x_margin) - line_arr = OcrLine.new([]) + line_arr = OCRLine.new([]) @pages[page_id].all_lines.each do |line| line.each do |word| line_arr.push(word) if Geometry.below?(word.polygon, coordinates, x_margin / 2, x_margin * 2) diff --git a/lib/mindee/parsing/common/ocr/ocr.rb b/lib/mindee/parsing/common/ocr/ocr.rb index b5414d35..8eb9c149 100644 --- a/lib/mindee/parsing/common/ocr/ocr.rb +++ b/lib/mindee/parsing/common/ocr/ocr.rb @@ -6,9 +6,9 @@ module Mindee module Parsing module Common # Ocr-specific parsing fields and options - module Ocr + module OCR # A single word. - class OcrWord + class OCRWord # The confidence score, value will be between 0.0 and 1.0 # @return [Float] attr_accessor :confidence @@ -34,24 +34,24 @@ def to_s end # A list of words which are on the same line. - class OcrLine < Array + class OCRLine < Array # @param prediction [Hash, nil] # @param from_array [Array, nil] def initialize(prediction = nil, from_array = nil) if !prediction.nil? - super(prediction.map { |word_prediction| OcrWord.new(word_prediction) }) + super(prediction.map { |word_prediction| OCRWord.new(word_prediction) }) elsif !from_array.nil? super(from_array) end end # Sort the words on the line from left to right. - # @return [OcrLine] + # @return [OCRLine] def sort_on_x from_array = sort do |word1, word2| Geometry.get_min_max_x(word1.polygon).min <=> Geometry.get_min_max_x(word2.polygon).min end - OcrLine.new(nil, from_array) + OCRLine.new(nil, from_array) end # @return [String] @@ -61,24 +61,24 @@ def to_s end # OCR extraction for a single page. - class OcrPage + class OCRPage # All the words on the page, in semi-random order. - # @return [Array] + # @return [Array] attr_reader :all_words - # @return [Array] + # @return [Array] attr_reader :lines # @param prediction [Hash] def initialize(prediction) - @lines = [] - @all_words = [] + @lines = [] # : Array[Mindee::Parsing::Common::OCR::OCRLine] + @all_words = [] # : Array[Mindee::Parsing::Common::OCR::OCRWord] prediction['all_words'].each do |word_prediction| - @all_words.push(OcrWord.new(word_prediction)) + @all_words.push(OCRWord.new(word_prediction)) end end # All the words on the page, ordered in lines. - # @return [Array] + # @return [Array] def all_lines @lines = to_lines if @lines.empty? @lines @@ -99,19 +99,19 @@ def to_s private # Helper function that iterates through all the words and compares them to a candidate - # @param sorted_words [Array] - # @param current [OcrWord] + # @param sorted_words [Array] + # @param current [OCRWord] # @param indexes [Array] - # @param lines [Array] + # @param lines [Array] def parse_one(sorted_words, current, indexes, lines) - line = OcrLine.new([]) + line = OCRLine.new([]) sorted_words.each_with_index do |word, idx| next if indexes.include?(idx) if current.nil? current = word indexes.push(idx) - line = OcrLine.new([]) + line = OCRLine.new([]) line.push(word) elsif words_on_same_line?(current, word) line.push(word) @@ -122,11 +122,11 @@ def parse_one(sorted_words, current, indexes, lines) end # Order all the words on the page into lines. - # @return [Array] + # @return [Array] def to_lines current = nil - indexes = [] - lines = [] + indexes = [] # : Array[Integer] + lines = [] # : Array[Mindee::Parsing::Common::OCR::OCRLine] # make sure words are sorted from top to bottom all_words = @all_words.sort_by { |word| Geometry.get_min_max_y(word.polygon).min } @@ -138,25 +138,25 @@ def to_lines end # Determine if two words are on the same line. - # @param current_word [Mindee::Parsing::Common::Ocr::OcrWord] - # @param next_word [Mindee::Parsing::Common::Ocr::OcrWord] - # @return [Boolean] + # @param current_word [Mindee::Parsing::Common::OCR::OCRWord] + # @param next_word [Mindee::Parsing::Common::OCR::OCRWord] + # @return [bool] def words_on_same_line?(current_word, next_word) current_in_next = current_word.polygon.point_in_y?(next_word.polygon.centroid) - next_in_current = next_word.polygon.point_in_y?(current_word.polygon.centroid) + next_in_current = next_word.polygon.point_in_y?(current_word.polygon.centroid) unless current_word.nil? current_in_next || next_in_current end end # OCR extraction from the entire document. - class Ocr + class OCR # Mindee Vision v1 results. - # @return [Mindee::Parsing::Common::Ocr::MVisionV1] + # @return [Mindee::Parsing::Common::OCR::MVisionV1] attr_reader :mvision_v1 # @param prediction [Hash] def initialize(prediction) - @mvision_v1 = MVisionV1.new(prediction['mvision-v1']) + @mvision_v1 = Mindee::Parsing::Common::OCR::MVisionV1.new(prediction['mvision-v1']) end # @return [String] @@ -169,7 +169,7 @@ def to_s # start # @param page_id [Integer] ID of the page to start at # @param x_margin [Float] Margin of misalignment for the x coordinate (default 10%) - # @return [Mindee::Parsing::Common::Ocr::OcrLine] + # @return [Mindee::Parsing::Common::OCR::OCRLine] def reconstruct_vertically(coordinates, page_id, x_margin = 0.05) @mvision_v1.reconstruct_vertically(coordinates, page_id, x_margin) end diff --git a/lib/mindee/parsing/common/page.rb b/lib/mindee/parsing/common/page.rb index f784bb5b..a3fc2ae7 100644 --- a/lib/mindee/parsing/common/page.rb +++ b/lib/mindee/parsing/common/page.rb @@ -10,7 +10,7 @@ module Common # Abstract wrapper class for prediction Pages # Holds prediction for a page as well as it's orientation and id. class Page - # Id of the page (as given by the API). + # ID of the page (as given by the API). # @return [Integer] attr_reader :page_id # Orientation of the page. @@ -26,8 +26,10 @@ class Page # @param raw_prediction [Hash] def initialize(raw_prediction) @page_id = raw_prediction['id'] - @orientation = Orientation.new(raw_prediction['orientation'], @page_id) - @extras = Extras::Extras.new(raw_prediction['extras']) unless raw_prediction['extras'].nil? + @orientation = Mindee::Parsing::Common::Orientation.new(raw_prediction['orientation'], @page_id) + return if raw_prediction['extras'].nil? + + @extras = Mindee::Parsing::Common::Extras::Extras.new(raw_prediction['extras']) end # @return [String] diff --git a/lib/mindee/parsing/common/prediction.rb b/lib/mindee/parsing/common/prediction.rb index e478aa5a..3f455ebd 100644 --- a/lib/mindee/parsing/common/prediction.rb +++ b/lib/mindee/parsing/common/prediction.rb @@ -9,6 +9,8 @@ class Prediction def to_s '' end + + def initialize(_ = nil, _ = nil); end end end end diff --git a/lib/mindee/parsing/common/workflow_response.rb b/lib/mindee/parsing/common/workflow_response.rb new file mode 100644 index 00000000..5becd894 --- /dev/null +++ b/lib/mindee/parsing/common/workflow_response.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module Common + # Represents the server response after a document is sent to a workflow. + class WorkflowResponse + # Set the prediction model used to parse the document. + # The response object will be instantiated based on this parameter. + # @return [Mindee::Parsing::Common::Execution] + attr_reader :execution + # @return [Mindee::Parsing::Common::ApiRequest] + attr_reader :api_request + # @return [String] + attr_reader :raw_http + + # @param http_response [Hash] + # @param product_class [Mindee::Inference] + def initialize(product_class, http_response, raw_http) + @raw_http = raw_http.to_s + @api_request = Mindee::Parsing::Common::ApiRequest.new(http_response['api_request']) + product_class ||= Mindee::Product::Universal::Universal + @execution = Mindee::Parsing::Common::Execution.new(product_class, http_response['execution']) + end + end + end + end +end diff --git a/lib/mindee/parsing/custom.rb b/lib/mindee/parsing/custom.rb deleted file mode 100644 index 2d4d3d74..00000000 --- a/lib/mindee/parsing/custom.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -require_relative 'custom/classification_field' -require_relative 'custom/list_field' diff --git a/lib/mindee/parsing/custom/classification_field.rb b/lib/mindee/parsing/custom/classification_field.rb deleted file mode 100644 index b8bfbd01..00000000 --- a/lib/mindee/parsing/custom/classification_field.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module Mindee - module Parsing - module Custom - # Document classification (custom docs) - class ClassificationField - # The classification value - # @return [String] - attr_reader :value - # The confidence score, value will be between 0.0 and 1.0 - # @return [Float] - attr_accessor :confidence - - # @param prediction [Hash] - def initialize(prediction) - @value = prediction['value'] - @confidence = prediction['confidence'] - end - - # @return [String] - def to_s - @value.nil? ? '' : @value - end - end - end - end -end diff --git a/lib/mindee/parsing/custom/list_field.rb b/lib/mindee/parsing/custom/list_field.rb deleted file mode 100644 index 10cff67a..00000000 --- a/lib/mindee/parsing/custom/list_field.rb +++ /dev/null @@ -1,78 +0,0 @@ -# frozen_string_literal: true - -module Mindee - module Parsing - module Custom - # Field in a list. - class ListFieldItem - # The confidence score, value will be between 0.0 and 1.0 - # @return [Float] - attr_accessor :confidence - # @return [Mindee::Geometry::Quadrilateral] - attr_reader :bounding_box - # @return [Mindee::Geometry::Polygon] - attr_reader :polygon - # @return [Array, Hash, String, nil] - attr_reader :content - # @return [Integer, nil] - attr_reader :page_id - - # @param prediction [Hash] - def initialize(prediction, page_id: nil) - @content = prediction['content'] - @confidence = prediction['confidence'] - @polygon = Geometry.polygon_from_prediction(prediction['polygon']) - @bounding_box = Geometry.get_bounding_box(@polygon) unless @polygon.nil? || @polygon.empty? - @page_id = page_id - end - - # @return [String] - def to_s - @content.to_s - end - end - - # Field where actual values are kept in a list (custom docs). - class ListField - # @return [Array] - attr_reader :values - # true if the field was reconstructed or computed using other fields. - # @return [Boolean] - attr_reader :reconstructed - # The confidence score, value will be between 0.0 and 1.0 - # @return [Float] - attr_accessor :confidence - - # @param prediction [Hash] - # @param page_id [Integer, nil] - # @param reconstructed [Boolean] - def initialize(prediction, page_id, reconstructed: false) - @values = [] - @confidence = prediction['confidence'] - page_id = prediction['page_id'] if page_id.nil? && prediction.include?('page_id') - @reconstructed = reconstructed - - prediction['values'].each do |field| - page_id = field['page_id'] if field.include?('page_id') - @values.push(ListFieldItem.new(field, page_id: page_id)) - end - end - - # @return [Array] - def contents_list - @values.map(&:content) - end - - # @return [String] - def contents_str(separator: ' ') - @values.map(&:to_s).join(separator) - end - - # @return [String] - def to_s - contents_str(separator: ' ') - end - end - end - end -end diff --git a/lib/mindee/parsing/generated.rb b/lib/mindee/parsing/generated.rb deleted file mode 100644 index 3d051c77..00000000 --- a/lib/mindee/parsing/generated.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -require_relative 'generated/generated_object_field' -require_relative 'generated/generated_list_field' diff --git a/lib/mindee/parsing/standard.rb b/lib/mindee/parsing/standard.rb index 6fd7aa7a..e8f0406e 100644 --- a/lib/mindee/parsing/standard.rb +++ b/lib/mindee/parsing/standard.rb @@ -6,6 +6,7 @@ require_relative 'standard/classification_field' require_relative 'standard/company_registration_field' require_relative 'standard/date_field' +require_relative 'standard/feature_field' require_relative 'standard/payment_details_field' require_relative 'standard/position_field' require_relative 'standard/tax_field' diff --git a/lib/mindee/parsing/standard/abstract_field.rb b/lib/mindee/parsing/standard/abstract_field.rb new file mode 100644 index 00000000..501825f4 --- /dev/null +++ b/lib/mindee/parsing/standard/abstract_field.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require_relative '../../geometry' + +module Mindee + module Parsing + module Standard + # Base BaseField object, upon which fields and feature fields are built + class AbstractField + # @return [Mindee::Geometry::Quadrilateral, nil] + attr_reader :bounding_box + # @return [Mindee::Geometry::Polygon, nil] + attr_reader :polygon + # @return [Integer, nil] + attr_reader :page_id + # The confidence score, value will be between 0.0 and 1.0 + # @return [Float, nil] + attr_accessor :confidence + + # @param prediction [Hash] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + @confidence = prediction['confidence'] if prediction.key?('confidence') + @polygon = Geometry.polygon_from_prediction(prediction['polygon']) if prediction.key?('polygon') + @bounding_box = Geometry.get_bounding_box(@polygon) unless @polygon.nil? || @polygon.empty? + @page_id = page_id || prediction['page_id'] + end + + # @return [String] + def to_s + @value ? @value.to_s : '' + end + + # Multiply all the Mindee::Parsing::Standard::BaseField confidences in the array. + # @return [Float] + def self.array_confidence(field_array) + product = 1 + field_array.each do |field| + return 0.0 if field.confidence.nil? + + product *= field.confidence + end + product.to_f + end + + # Add all the Mindee::Parsing::Standard::BaseField values in the array. + # @return [Float] + def self.array_sum(field_array) + arr_sum = 0 + field_array.each do |field| + return 0.0 if field.value.nil? + + arr_sum += field.value + end + arr_sum.to_f + end + + # @param value [Float] + # @param min_precision [Integer] + # @return [String] + def self.float_to_string(value, min_precision = 2) + return String.new if value.nil? + + precision = value.to_f.to_s.split('.')[1].size + precision = [precision, min_precision].max + format_string = "%.#{precision}f" + format(format_string, value) + end + end + end + end +end diff --git a/lib/mindee/parsing/standard/amount_field.rb b/lib/mindee/parsing/standard/amount_field.rb index b0f723ed..63074bbd 100644 --- a/lib/mindee/parsing/standard/amount_field.rb +++ b/lib/mindee/parsing/standard/amount_field.rb @@ -6,7 +6,7 @@ module Mindee module Parsing module Standard # Represents tax information. - class AmountField < Field + class AmountField < BaseField # Amount value as 3 decimal float # @return [Float, nil] attr_reader :value @@ -18,7 +18,7 @@ def initialize(prediction, page_id, reconstructed: false) # @return [String] def to_s - Field.float_to_string(@value) + BaseField.float_to_string(@value) end end end diff --git a/lib/mindee/parsing/standard/base_field.rb b/lib/mindee/parsing/standard/base_field.rb index a0020344..caf01aa6 100644 --- a/lib/mindee/parsing/standard/base_field.rb +++ b/lib/mindee/parsing/standard/base_field.rb @@ -1,107 +1,28 @@ # frozen_string_literal: true require_relative '../../geometry' +require_relative 'abstract_field' module Mindee module Parsing module Standard - # Base Field object, upon which fields and feature fields are built - class AbstractField - # @return [Mindee::Geometry::Quadrilateral, nil] - attr_reader :bounding_box - # @return [Mindee::Geometry::Polygon, nil] - attr_reader :polygon - # @return [Integer, nil] - attr_reader :page_id - # The confidence score, value will be between 0.0 and 1.0 - # @return [Float, nil] - attr_accessor :confidence - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - @confidence = prediction['confidence'] if prediction.key?('confidence') - @polygon = Geometry.polygon_from_prediction(prediction['polygon']) if prediction.key?('polygon') - @bounding_box = Geometry.get_bounding_box(@polygon) unless @polygon.nil? || @polygon.empty? - @page_id = page_id || prediction['page_id'] - end - - # @return [String] - def to_s - @value ? @value.to_s : '' - end - - # Multiply all the Mindee::Parsing::Standard::Field confidences in the array. - # @return [Float] - def self.array_confidence(field_array) - product = 1 - field_array.each do |field| - return 0.0 if field.confidence.nil? - - product *= field.confidence - end - product.to_f - end - - # Add all the Mindee::Parsing::Standard::Field values in the array. - # @return [Float] - def self.array_sum(field_array) - arr_sum = 0 - field_array.each do |field| - return 0.0 if field.value.nil? - - arr_sum += field.value - end - arr_sum.to_f - end - - # @param value [Float] - # @param min_precision [Integer] - # @return [String] - def self.float_to_string(value, min_precision = 2) - return String.new if value.nil? - - precision = value.to_f.to_s.split('.')[1].size - precision = [precision, min_precision].max - format_string = "%.#{precision}f" - format(format_string, value) - end - end - # Base field object. - class Field < AbstractField - # @return [String, Float, Integer, Boolean] + class BaseField < Mindee::Parsing::Standard::AbstractField + # @return [String, Float, Integer, bool] attr_reader :value # true if the field was reconstructed or computed using other fields. - # @return [Boolean] + # @return [bool] attr_reader :reconstructed # @param prediction [Hash] # @param page_id [Integer, nil] - # @param reconstructed [Boolean] + # @param reconstructed [bool] def initialize(prediction, page_id, reconstructed: false) super(prediction, page_id) @value = prediction['value'] @reconstructed = reconstructed end end - - # Feature field object wrapper for specialized methods. - class FeatureField < AbstractField - # Format strings for display by shortening long strings and assigning empty ones. - # @param in_str [String, Boolean, nil] - # @param max_col_size [int, nil] - # @return [String] - def format_for_display(in_str, max_col_size = nil) - return 'True' if in_str == true - return 'False' if in_str == false - return '' if in_str.nil? - return in_str if max_col_size.nil? - - in_str = in_str.gsub(%r{[\n\r\t]}, "\n" => '\\n', "\r" => '\\r', "\t" => '\\t') - in_str.length <= max_col_size ? in_str : "#{in_str[0..max_col_size - 4]}..." - end - end end end end diff --git a/lib/mindee/parsing/standard/boolean_field.rb b/lib/mindee/parsing/standard/boolean_field.rb index 32bcc35b..28e368e2 100644 --- a/lib/mindee/parsing/standard/boolean_field.rb +++ b/lib/mindee/parsing/standard/boolean_field.rb @@ -6,15 +6,16 @@ module Mindee module Parsing module Standard # Represents basic text information. - class BooleanField < Field - # Value as Boolean - # @return [Boolean, nil] + class BooleanField < BaseField + # Value as bool + # @return [bool, nil] attr_reader :value def initialize(prediction, page_id = nil, reconstructed: false) super end + # @return [String] def to_s return '' if value.nil? diff --git a/lib/mindee/parsing/standard/classification_field.rb b/lib/mindee/parsing/standard/classification_field.rb index e8976fc0..5cacac82 100644 --- a/lib/mindee/parsing/standard/classification_field.rb +++ b/lib/mindee/parsing/standard/classification_field.rb @@ -6,7 +6,7 @@ module Mindee module Parsing module Standard # Represents a classifier value. - class ClassificationField < Field + class ClassificationField < BaseField # Value as String # @return [String] attr_reader :value diff --git a/lib/mindee/parsing/standard/company_registration_field.rb b/lib/mindee/parsing/standard/company_registration_field.rb index c262e8f1..e08983de 100644 --- a/lib/mindee/parsing/standard/company_registration_field.rb +++ b/lib/mindee/parsing/standard/company_registration_field.rb @@ -4,28 +4,33 @@ module Mindee module Parsing module Standard # Company registration number or code, and its type. - class CompanyRegistrationField < Field + class CompanyRegistrationField < BaseField # @return [String] attr_reader :type # @param prediction [Hash] # @param page_id [Integer, nil] - # @param reconstructed [Boolean] + # @param reconstructed [bool] def initialize(prediction, page_id, reconstructed: false) super @type = prediction['type'] end + # Table line representation of the values. + # @return [String] The formatted table line, as a string. def to_table_line printable = printable_values format('| %-15s | %-20s ', type: printable['type'], value: printable['value']) end + # @return [String] def to_s printable = printable_values format('Type: %s, Value: %s', type: printable['type'], value: printable['value']) end + # Hashed representation of the values. + # @return [Hash] Hash of the values. def printable_values printable = {} printable['type'] = type diff --git a/lib/mindee/parsing/standard/date_field.rb b/lib/mindee/parsing/standard/date_field.rb index a0fe738c..73e0a5c7 100644 --- a/lib/mindee/parsing/standard/date_field.rb +++ b/lib/mindee/parsing/standard/date_field.rb @@ -8,7 +8,7 @@ module Mindee module Parsing module Standard # Represents a date. - class DateField < Field + class DateField < BaseField # The date as a standard Ruby `Date` object. # @return [Date, nil] attr_reader :date_object @@ -19,7 +19,7 @@ class DateField < Field # @return [String, nil] attr_reader :raw # Whether the field was computed or retrieved directly from the document. - # @return [Boolean, nil] + # @return [bool, nil] attr_reader :is_computed # @param prediction [Hash] diff --git a/lib/mindee/parsing/standard/feature_field.rb b/lib/mindee/parsing/standard/feature_field.rb new file mode 100644 index 00000000..4280104b --- /dev/null +++ b/lib/mindee/parsing/standard/feature_field.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module Standard + # Feature field object wrapper for specialized methods. + class FeatureField < AbstractField + # Format strings for display by shortening long strings and assigning empty ones. + # @param in_str [String, bool, nil] + # @param max_col_size [int, nil] + # @return [String] + def format_for_display(in_str, max_col_size = nil) + return 'True' if in_str == true + return 'False' if in_str == false + return '' if in_str.nil? + return in_str.to_s if max_col_size.nil? + + in_str = in_str.to_s.gsub(%r{[\n\r\t]}, "\n" => '\\n', "\r" => '\\r', "\t" => '\\t') + in_str.to_s.length <= max_col_size.to_i ? in_str.to_s : "#{in_str[0..max_col_size.to_i - 4]}..." + end + end + end + end +end diff --git a/lib/mindee/parsing/standard/payment_details_field.rb b/lib/mindee/parsing/standard/payment_details_field.rb index ec8b4818..772e50a4 100644 --- a/lib/mindee/parsing/standard/payment_details_field.rb +++ b/lib/mindee/parsing/standard/payment_details_field.rb @@ -6,7 +6,7 @@ module Mindee module Parsing module Standard # Represents payment details for invoices and receipts - class PaymentDetailsField < Field + class PaymentDetailsField < BaseField # @return [String, nil] attr_reader :account_number # @return [String, nil] @@ -18,7 +18,7 @@ class PaymentDetailsField < Field # @param prediction [Hash] # @param page_id [Integer, nil] - # @param reconstructed [Boolean] + # @param reconstructed [bool] def initialize(prediction, page_id, reconstructed: false) super @account_number = prediction['account_number'] diff --git a/lib/mindee/parsing/standard/position_field.rb b/lib/mindee/parsing/standard/position_field.rb index ba9d002e..84d6c7a5 100644 --- a/lib/mindee/parsing/standard/position_field.rb +++ b/lib/mindee/parsing/standard/position_field.rb @@ -49,7 +49,9 @@ def to_s private def to_quadrilateral(prediction, key) - Geometry.quadrilateral_from_prediction(prediction[key]) unless prediction[key].nil? || prediction[key].empty? + return if prediction[key].nil? || prediction[key].empty? + + Mindee::Geometry.quadrilateral_from_prediction(prediction[key]) end end end diff --git a/lib/mindee/parsing/standard/string_field.rb b/lib/mindee/parsing/standard/string_field.rb index a7450305..af575ba0 100644 --- a/lib/mindee/parsing/standard/string_field.rb +++ b/lib/mindee/parsing/standard/string_field.rb @@ -6,7 +6,7 @@ module Mindee module Parsing module Standard # Represents basic text information. - class StringField < Field + class StringField < Mindee::Parsing::Standard::BaseField # Value as String # @return [String, nil] attr_reader :value diff --git a/lib/mindee/parsing/standard/tax_field.rb b/lib/mindee/parsing/standard/tax_field.rb index 94e08574..60b23d0e 100644 --- a/lib/mindee/parsing/standard/tax_field.rb +++ b/lib/mindee/parsing/standard/tax_field.rb @@ -6,7 +6,7 @@ module Mindee module Parsing module Standard # Represents tax information. - class TaxField < Field + class TaxField < BaseField # Tax value as 3 decimal float # @return [Float, nil] attr_reader :value diff --git a/lib/mindee/parsing/universal.rb b/lib/mindee/parsing/universal.rb new file mode 100644 index 00000000..86f0408f --- /dev/null +++ b/lib/mindee/parsing/universal.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +require_relative 'universal/universal_object_field' +require_relative 'universal/universal_list_field' diff --git a/lib/mindee/parsing/generated/generated_list_field.rb b/lib/mindee/parsing/universal/universal_list_field.rb similarity index 61% rename from lib/mindee/parsing/generated/generated_list_field.rb rename to lib/mindee/parsing/universal/universal_list_field.rb index 430e2da4..54837d58 100644 --- a/lib/mindee/parsing/generated/generated_list_field.rb +++ b/lib/mindee/parsing/universal/universal_list_field.rb @@ -1,38 +1,38 @@ # frozen_string_literal: true -require_relative 'generated_object_field' +require_relative 'universal_object_field' module Mindee module Parsing - module Generated - # A list of values or objects, used in generated APIs. - class GeneratedListField + module Universal + # A list of values or objects, used in universal APIs. + class UniversalListField include Mindee::Parsing::Standard - include Mindee::Parsing::Generated + include Mindee::Parsing::Universal - # Id of the page (as given by the API). + # ID of the page (as given by the API). # @return [Integer] attr_accessor :page_id # List of word values - # @return [Array] + # @return [Array] attr_accessor :values - # Id of the page the object was found on. + # ID of the page the object was found on. # List of word values. def initialize(raw_prediction, page_id = nil) - @values = [] + @values = [] # : Array[UniversalObjectField | Parsing::Standard::StringField] raw_prediction.each do |value| page_id = value['page_id'] if value.key?('page_id') && !value['page_id'].nil? - if Generated.generated_object?(value) - @values.push(GeneratedObjectField.new(value, page_id)) + if Universal.universal_object?(value) + @values.push(Mindee::Parsing::Universal::UniversalObjectField.new(value, page_id)) else value_str = value.dup value_str['value'] = value_str['value'].to_s if value_str.key?('value') && !value_str['value'].nil? - @values.push(StringField.new(value_str, page_id)) + @values.push(Mindee::Parsing::Standard::StringField.new(value_str, page_id)) end end end diff --git a/lib/mindee/parsing/generated/generated_object_field.rb b/lib/mindee/parsing/universal/universal_object_field.rb similarity index 75% rename from lib/mindee/parsing/generated/generated_object_field.rb rename to lib/mindee/parsing/universal/universal_object_field.rb index 1388a309..c5bbd4c4 100644 --- a/lib/mindee/parsing/generated/generated_object_field.rb +++ b/lib/mindee/parsing/universal/universal_object_field.rb @@ -4,19 +4,26 @@ module Mindee module Parsing - # Generated fields and functions. - module Generated + # Universal fields and functions. + module Universal # A JSON-like object, with miscellaneous values. - class GeneratedObjectField - include Mindee::Parsing::Standard - attr_accessor :page_id, :confidence, :raw_value + class UniversalObjectField + # ID of the page (as given by the API). + # @return [Integer] + attr_reader :page_id + # The confidence score, value will be between 0.0 and 1.0 + # @return [Float] + attr_reader :confidence + # Value as String + # @return [Hash, nil] + attr_accessor :raw_value - # Id of the page the object was found on. + # ID of the page the object was found on. # Confidence with which the value was assessed. # Raw unprocessed value, as it was sent by the server. def initialize(raw_prediction, page_id = nil) - @all_values = {} + @all_values = {} # : Hash[Symbol | String, untyped] item_page_id = nil raw_prediction.each do |name, value| case name @@ -47,7 +54,7 @@ def str_level(level = 0) end # Necessary overload of the method_missing method to allow for direct access to dynamic attributes without - # complicating usage too much + # changing the user usage too much. # Returns the corresponding attribute when asked. # # Otherwise, raises a NoMethodError. @@ -61,14 +68,14 @@ def method_missing(method_name, *_args) end # Necessary overload of the respond_to_missing? method to allow for direct access to dynamic attributes without - # complicating usage too much + # changing the user usage too much. # Returns true if the method name exists as a key in @all_values, # indicating that the object can respond to the method. # Otherwise, calls super to fallback to the default behavior. # # @param method_name [Symbol] The name of the method being checked. - # @param include_private [Boolean] Whether to include private methods in the check. - # @return [Boolean] True if the method can be responded to, false otherwise. + # @param include_private [bool] Whether to include private methods in the check. + # @return [bool] True if the method can be responded to, false otherwise. def respond_to_missing?(method_name, include_private = false) @all_values.key?(method_name.to_s) || super end @@ -82,7 +89,9 @@ def to_s def handle_position_field(name, value, item_page_id) @all_values[name.to_s] = - PositionField.new({ name.to_s => value }, value_key: name.to_s, page_id: item_page_id) + Mindee::Parsing::Standard::PositionField.new( + { name.to_s => value }, item_page_id + ) end def handle_default_field(name, value) @@ -90,7 +99,7 @@ def handle_default_field(name, value) end end - def self.generated_object?(str_dict) + def self.universal_object?(str_dict) common_keys = [ 'value', 'polygon', @@ -101,7 +110,7 @@ def self.generated_object?(str_dict) 'values', 'raw_value', ] - str_dict.each_key { |key| return true unless common_keys.include?(key) } + str_dict.each_key { |key| return true unless common_keys.include?(key.to_s) } false end end diff --git a/lib/mindee/pdf.rb b/lib/mindee/pdf.rb index ab262fd7..48b05d99 100644 --- a/lib/mindee/pdf.rb +++ b/lib/mindee/pdf.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative 'pdf/extracted_pdf' require_relative 'pdf/pdf_compressor' +require_relative 'pdf/pdf_extractor' require_relative 'pdf/pdf_processor' require_relative 'pdf/pdf_tools' diff --git a/lib/mindee/extraction/pdf_extractor/extracted_pdf.rb b/lib/mindee/pdf/extracted_pdf.rb similarity index 62% rename from lib/mindee/extraction/pdf_extractor/extracted_pdf.rb rename to lib/mindee/pdf/extracted_pdf.rb index e8ade1e8..d70f9e55 100644 --- a/lib/mindee/extraction/pdf_extractor/extracted_pdf.rb +++ b/lib/mindee/pdf/extracted_pdf.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true module Mindee - # Pdf Extraction Module. - module Extraction - module PdfExtractor + # PDF Extraction Module. + module PDF + module PDFExtractor # An extracted sub-Pdf. - class ExtractedPdf + class ExtractedPDF # Byte contents of the pdf # @return [StreamIO] attr_reader :pdf_bytes @@ -24,19 +24,22 @@ def initialize(pdf_bytes, filename) # Retrieves the page count for a given pdf. # @return [Integer] def page_count - current_pdf = Mindee::PDF::PdfProcessor.open_pdf(pdf_bytes) + current_pdf = Mindee::PDF::PDFProcessor.open_pdf(pdf_bytes) current_pdf.pages.size - rescue TypeError - raise 'Could not retrieve page count from Extracted PDF object.' + rescue TypeError, Origami::InvalidPDFError + raise Errors::MindeePDFError, 'Could not retrieve page count from Extracted PDF object.' end # Writes the contents of the current PDF object to a file. # @param output_path [String] Path to write to. - def write_to_file(output_path) - raise 'Provided path is not a file' if File.directory?(destination) - raise 'Invalid save path provided' unless File.exist?(File.expand_path('..', output_path)) - - if File.extname(output_path).downcase == '.pdf' + # @param override [bool] Whether to override the destination file. + def write_to_file(output_path, override: false) + raise Errors::MindeePDFError, 'Provided path is not a file' if File.directory?(output_path) + raise Errors::MindeePDFError, 'Invalid save path provided' unless File.exist?( + File.expand_path('..', output_path) + ) && !override + + if File.extname(output_path).downcase == 'pdf' base_path = File.expand_path('..', output_path) output_path = File.expand_path("#{File.basename(output_path)}.pdf", base_path) end diff --git a/lib/mindee/pdf/pdf_compressor.rb b/lib/mindee/pdf/pdf_compressor.rb index f33cc504..33a105e0 100644 --- a/lib/mindee/pdf/pdf_compressor.rb +++ b/lib/mindee/pdf/pdf_compressor.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'pdf-reader' +# Shorthand for pdf-reader's PDF namespace, to avoid mixups with the local Origami fork. PDFReader = PDF module Mindee @@ -8,20 +9,21 @@ module PDF # Image compressor module to handle PDF compression. module PDFCompressor # Compresses each page of a provided PDF stream. Skips if force_source_text isn't set and source text is detected. + # @param pdf_data [StringIO] StringIO handle of the file. # @param quality [Integer] Compression quality (70-100 for most JPG images in the test dataset). - # @param force_source_text_compression [Boolean] If true, attempts to re-write detected text. - # @param disable_source_text [Boolean] If true, doesn't re-apply source text to the original PDF. + # @param force_source_text_compression [bool] If true, attempts to re-write detected text. + # @param disable_source_text [bool] If true, doesn't re-apply source text to the original PDF. def self.compress_pdf(pdf_data, quality: 85, force_source_text_compression: false, disable_source_text: true) if PDFTools.source_text?(pdf_data) if force_source_text_compression if disable_source_text - puts "\e[33m[WARNING] Re-writing PDF source-text is an EXPERIMENTAL feature.\e[0m" + logger.warn('Re-writing PDF source-text is an EXPERIMENTAL feature.') else - puts "\e[33m[WARNING] Source-file contains text, but disable_source_text flag is ignored. " \ - "Resulting file will not contain any embedded text.\e[0m" + logger.warn('Source-file contains text, but disable_source_text flag is ignored. ' \ + 'Resulting file will not contain any embedded text.') end else - puts "\e[33m[WARNING] Source-text detected in input PDF. Aborting operation.\e[0m" + logger.warn('Source-text detected in input PDF. Aborting operation.') return pdf_data end end @@ -43,18 +45,18 @@ def self.compress_pdf(pdf_data, quality: 85, force_source_text_compression: fals # @return [Array] Processed pages. def self.process_pdf_pages(pdf, quality) pdf.pages.map.with_index do |page, index| - process_pdf_page(Mindee::PDF::PdfProcessor.get_page(pdf, index), index, quality, page[:MediaBox]) + retrieved_page = Mindee::PDF::PDFProcessor.get_page(pdf, index) + process_pdf_page(retrieved_page, index, quality, page[:MediaBox]) end end # Creates the output PDF with processed pages. - # @param pages [Array] Processed pages. - # @param disable_source_text [Boolean] Whether to disable source text. + # @param pages [Array] Processed pages. + # @param disable_source_text [bool] Whether to disable source text. # @param pdf_data [StringIO] Original PDF data. # @return [Origami::PDF] Output PDF object. def self.create_output_pdf(pages, disable_source_text, pdf_data) output_pdf = Origami::PDF.new - # NOTE: Page order and XObject handling require adjustment due to origami adding the last page first. pages.rotate!(1) if pages.count >= 2 inject_text(pdf_data, pages) unless disable_source_text diff --git a/lib/mindee/extraction/pdf_extractor/pdf_extractor.rb b/lib/mindee/pdf/pdf_extractor.rb similarity index 76% rename from lib/mindee/extraction/pdf_extractor/pdf_extractor.rb rename to lib/mindee/pdf/pdf_extractor.rb index 14b429bb..e1560dbb 100644 --- a/lib/mindee/extraction/pdf_extractor/pdf_extractor.rb +++ b/lib/mindee/pdf/pdf_extractor.rb @@ -2,18 +2,18 @@ module Mindee # Pdf Extraction Module. - module Extraction + module PDF # Pdf Extraction class. - module PdfExtractor + module PDFExtractor # Pdf extraction class. - class PdfExtractor + class PDFExtractor # @param local_input [Mindee::Input::Source::LocalInputSource] def initialize(local_input) @filename = local_input.filename if local_input.pdf? @source_pdf = local_input.io_stream else - pdf_image = Extraction::ImageExtractor.attach_image_as_new_file(local_input.io_stream) + pdf_image = Image::ImageExtractor.attach_image_as_new_file(local_input.io_stream) io_buffer = StringIO.new pdf_image.save(io_buffer) @@ -24,40 +24,43 @@ def initialize(local_input) # Retrieves the page count for the Pdf object. # @return [Integer] def page_count - Mindee::PDF::PdfProcessor.open_pdf(@source_pdf).pages.size + Mindee::PDF::PDFProcessor.open_pdf(@source_pdf).pages.size end # Creates a new Pdf from pages and save it into a buffer. # @param page_indexes [Array] List of page number to use for merging in the original Pdf. # @return [StreamIO] The buffer containing the new Pdf. def cut_pages(page_indexes) - options = { - page_indexes: page_indexes, - } + options = PageOptions.new(params: { + page_indexes: page_indexes, + }) - Mindee::PDF::PdfProcessor.parse(@source_pdf, options) + Mindee::PDF::PDFProcessor.parse(@source_pdf, options) end # Extract the sub-documents from the main pdf, based on the given list of page indexes. # @param page_indexes [Array>] List of page number to use for merging in the original Pdf. - # @return [Array] The buffer containing the new Pdf. + # @return [Array] The buffer containing the new Pdf. def extract_sub_documents(page_indexes) extracted_pdfs = [] extension = File.extname(@filename) basename = File.basename(@filename, extension) page_indexes.each do |page_index_list| if page_index_list.empty? || page_index_list.nil? - raise "Empty indexes aren't allowed for extraction #{page_index_list}" + raise Errors::MindeePDFError, "Empty indexes aren't allowed for extraction #{page_index_list}" end page_index_list.each do |page_index| - raise "Index #{page_index} is out of range." if (page_index > page_count) || page_index.negative? + if (page_index > page_count) || page_index.negative? + raise Errors::MindeePDFError, + "Index #{page_index} is out of range." + end end formatted_max_index = format('%03d', page_index_list[page_index_list.length - 1] + 1).to_s field_filename = "#{basename}_#{format('%03d', (page_index_list[0] + 1))}-#{formatted_max_index}#{extension}" - extracted_pdf = Mindee::Extraction::PdfExtractor::ExtractedPdf.new(cut_pages(page_index_list), - field_filename) + extracted_pdf = Mindee::PDF::PDFExtractor::ExtractedPDF.new(cut_pages(page_index_list), + field_filename) extracted_pdfs << extracted_pdf end extracted_pdfs @@ -68,10 +71,10 @@ def extract_sub_documents(page_indexes) # Extracts invoices as complete PDFs from the document. # @param page_indexes [Array, InvoiceSplitterV1PageGroup>] - # @param strict [Boolean] - # @return [Array] + # @param strict [bool] + # @return [Array] def extract_invoices(page_indexes, strict: false) - raise 'No indexes provided.' if page_indexes.empty? + raise Errors::MindeePDFError, 'No indexes provided.' if page_indexes.empty? unless page_indexes[0].is_a?(Mindee::Product::InvoiceSplitter::InvoiceSplitterV1PageGroup) return extract_sub_documents(page_indexes) end diff --git a/lib/mindee/pdf/pdf_processor.rb b/lib/mindee/pdf/pdf_processor.rb index 1e7e981a..1d7e38eb 100644 --- a/lib/mindee/pdf/pdf_processor.rb +++ b/lib/mindee/pdf/pdf_processor.rb @@ -7,34 +7,24 @@ module Mindee module PDF # PDF document processing - module PdfProcessor + module PDFProcessor Origami::PDF.class_eval { include PDFTools } - # Default options for pdf documents processing. - DEFAULT_OPTIONS = { - page_indexes: [0], - operation: :KEEP_ONLY, - on_min_pages: 0, - }.freeze - # @param io_stream [StreamIO] - # @param options [Hash] + # @param options [PageOptions, Hash] # @return [StringIO] def self.parse(io_stream, options) - options = DEFAULT_OPTIONS.merge(options) - current_pdf = open_pdf(io_stream) pages_count = current_pdf.pages.size - return if options[:on_min_pages] > pages_count + return current_pdf.to_io_stream if options.on_min_pages.to_i > pages_count all_pages = (0..pages_count - 1).to_a - case options[:operation] - when :KEEP_ONLY - pages_to_remove = indexes_from_keep(options[:page_indexes], all_pages) - when :REMOVE - pages_to_remove = indexes_from_remove(options[:page_indexes], all_pages) + if options.operation == :KEEP_ONLY + pages_to_remove = indexes_from_keep(options.page_indexes, all_pages) + elsif options.operation == :REMOVE + pages_to_remove = indexes_from_remove(options.page_indexes, all_pages) else - raise "operation must be one of :KEEP_ONLY or :REMOVE, sent '#{behavior}'" + raise ArgumentError, "operation must be one of :KEEP_ONLY or :REMOVE, sent '#{options.operation}'" end current_pdf.delete_pages_at(pages_to_remove) if pages_to_remove.to_a != all_pages.to_a @@ -55,7 +45,7 @@ def self.indexes_from_keep(page_indexes, all_pages) all_pages.to_set - pages_to_keep end - # @param page_indexes [Array] + # @param page_indexes [Array[Integer]] # @param all_pages [Array] def self.indexes_from_remove(page_indexes, all_pages) pages_to_remove = Set.new @@ -85,9 +75,9 @@ def self.get_page(pdf_doc, page_id) stream = StringIO.new pdf_doc.save(stream) - options = { - page_indexes: [page_id - 1], - } + options = PageOptions.new(params: { + page_indexes: [page_id - 1], + }) parse(stream, options) end diff --git a/lib/mindee/pdf/pdf_tools.rb b/lib/mindee/pdf/pdf_tools.rb index 8aac547d..d11f745b 100644 --- a/lib/mindee/pdf/pdf_tools.rb +++ b/lib/mindee/pdf/pdf_tools.rb @@ -2,14 +2,23 @@ module Mindee module PDF - # Monkey-patching for Origami + # Collection of miscellaneous PDF operations,as well as some monkey-patching for Origami. module PDFTools - # @return [StringIO] + # Converts the current PDF document into a binary-encoded StringIO stream. + # + # @param [Hash] params Optional settings to override default processing flags. + # - :delinearize [bool] (default: true) Whether to convert a linearized PDF to its full form. + # - :recompile [bool] (default: true) Whether to recompile the PDF after processing. + # - :decrypt [bool] (default: false) Whether to attempt to decrypt the PDF. + # - Other keys such as :intent, :rebuild_xrefs, :noindent, and :obfuscate may be modified automatically. + # + # @return [StringIO] A binary-encoded stream representing the processed PDF. def to_io_stream(params = {}) options = { delinearize: true, recompile: true, decrypt: false, + noindent: nil, } options.update(params) @@ -21,7 +30,7 @@ def to_io_stream(params = {}) end load_all_objects unless @loaded - intents_as_pdfa1 if options[:intent] =~ %r{pdf[/-]?A1?/i} + intents_as_pdfa1 if options[:intent].to_s =~ %r{pdf[/-]?A1?/i} delinearize! if options[:delinearize] && linearized? compile(options) if options[:recompile] @@ -33,7 +42,7 @@ def to_io_stream(params = {}) # Checks a PDFs stream content for text operators # See https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf page 243-251. # @param [StringIO] stream Stream object from a PDFs page. - # @return [Boolean] True if a text operator is found in the stream. + # @return [bool] True if a text operator is found in the stream. def self.stream_has_text?(stream) data = stream.data return false if data.nil? || data.empty? @@ -43,8 +52,8 @@ def self.stream_has_text?(stream) end # Checks whether the file has source_text. Sends false if the file isn't a PDF. - # @param [StringIO] pdf_data - # @return [Boolean] True if the pdf has source text, false otherwise. + # @param [StringIO] pdf_data Abinary-encoded stream representing the PDF file. + # @return [bool] True if the pdf has source text, false otherwise. def self.source_text?(pdf_data) begin pdf_data.rewind @@ -70,11 +79,22 @@ def self.source_text?(pdf_data) false end + # Creates an image XObject from the provided image. + # + # Converts the given image to a binary stream using Mindee's image utilities, then creates + # an Origami::Graphics::ImageXObject with a JPEG filter. + # + # @param [Minimagick::Image] image An image object with the necessary data and structure. + # @return [Origami::Graphics::ImageXObject] The created image XObject. def self.create_xobject(image) image_io = Mindee::Image::ImageUtils.image_to_stringio(image) Origami::Graphics::ImageXObject.from_image_file(image_io, 'jpg') end + # Sets properties on the provided image XObject based on image metadata. + # + # @param [Origami::Graphics::ImageXObject] xobject The image XObject to update. + # @param [Hash] image A hash containing image metadata (such as width, height, properties, etc.). def self.set_xobject_properties(xobject, image) xobject.dictionary[:BitsPerComponent] = 8 xobject.dictionary[:Filter] = determine_filter(image) @@ -83,6 +103,10 @@ def self.set_xobject_properties(xobject, image) xobject.dictionary[:ColorSpace] = determine_colorspace(image) end + # Determines the appropriate filter for an image based on its properties. + # + # @param [Hash] image The image data hash containing properties. + # @return [Symbol] One of :FlateDecode, :LZWDecode or :DCTDecode. def self.determine_filter(image) filter = image.data['properties']['filter'] case filter @@ -92,6 +116,10 @@ def self.determine_filter(image) end end + # Determines the colorspace for an image based on its metadata. + # + # @param [Hash] image The image data hash. + # @return [Symbol] One of :DeviceCMYK, :DeviceGray or :DeviceRGB. def self.determine_colorspace(image) colorspace = image.data['colorspace'] case colorspace @@ -101,17 +129,35 @@ def self.determine_colorspace(image) end end + # Adds a content stream to the specified PDF page to display an image XObject. + # + # @param [Origami::Page] page The PDF page to which content will be added. + # @param [String] xobject_name The name identifying the XObject. + # @param [Integer] width The width for the transformation matrix. + # @param [Integer] height The height for the transformation matrix. def self.add_content_to_page(page, xobject_name, width, height) content = "q\n#{width} 0 0 #{height} 0 0 cm\n/#{xobject_name} Do\nQ\n" content_stream = Origami::Stream.new(content) page.Contents = content_stream end + # Sets the dimensions for the specified PDF page. + # + # @param [Origami::Page] page The PDF page whose dimensions are being set. + # @param [Numeric] width The target width of the page. + # @param [Numeric] height The target height of the page. def self.set_page_dimensions(page, width, height) page[:MediaBox] = [0, 0, width, height] page[:CropBox] = [0, 0, width, height] end + # Processes an image into an image XObject for PDF embedding. + # + # @param [Hash] image_data The raw image data. + # @param [Integer] image_quality The quality setting for image compression. + # @param [Numeric] width The desired width of the output image. + # @param [Numeric] height The desired height of the output image. + # @return [Origami::Graphics::ImageXObject] The resulting image XObject. def self.process_image_xobject(image_data, image_quality, width, height) compressed_data = Image::ImageCompressor.compress_image( image_data, diff --git a/lib/mindee/product.rb b/lib/mindee/product.rb index 788d8518..51106cc2 100644 --- a/lib/mindee/product.rb +++ b/lib/mindee/product.rb @@ -3,15 +3,12 @@ require_relative 'product/barcode_reader/barcode_reader_v1' require_relative 'product/bill_of_lading/bill_of_lading_v1' require_relative 'product/business_card/business_card_v1' -require_relative 'product/custom/custom_v1' require_relative 'product/cropper/cropper_v1' require_relative 'product/delivery_note/delivery_note_v1' require_relative 'product/driver_license/driver_license_v1' require_relative 'product/eu/license_plate/license_plate_v1' -require_relative 'product/eu/driver_license/driver_license_v1' require_relative 'product/fr/bank_account_details/bank_account_details_v1' require_relative 'product/fr/bank_account_details/bank_account_details_v2' -require_relative 'product/fr/bank_statement/bank_statement_v1' require_relative 'product/fr/bank_statement/bank_statement_v2' require_relative 'product/fr/carte_grise/carte_grise_v1' require_relative 'product/fr/id_card/id_card_v1' @@ -21,7 +18,6 @@ require_relative 'product/fr/payslip/payslip_v2' require_relative 'product/fr/payslip/payslip_v3' require_relative 'product/financial_document/financial_document_v1' -require_relative 'product/generated/generated_v1' require_relative 'product/ind/indian_passport/indian_passport_v1' require_relative 'product/invoice/invoice_v4' require_relative 'product/invoice_splitter/invoice_splitter_v1' @@ -29,13 +25,10 @@ require_relative 'product/multi_receipts_detector/multi_receipts_detector_v1' require_relative 'product/nutrition_facts_label/nutrition_facts_label_v1' require_relative 'product/passport/passport_v1' -require_relative 'product/proof_of_address/proof_of_address_v1' -require_relative 'product/receipt/receipt_v4' require_relative 'product/receipt/receipt_v5' require_relative 'product/resume/resume_v1' +require_relative 'product/universal/universal' require_relative 'product/us/bank_check/bank_check_v1' -require_relative 'product/us/driver_license/driver_license_v1' require_relative 'product/us/healthcare_card/healthcare_card_v1' -require_relative 'product/us/us_mail/us_mail_v2' require_relative 'product/us/us_mail/us_mail_v3' require_relative 'product/us/w9/w9_v1' diff --git a/lib/mindee/product/.rubocop.yml b/lib/mindee/product/.rubocop.yml index 0d759610..8b0217de 100644 --- a/lib/mindee/product/.rubocop.yml +++ b/lib/mindee/product/.rubocop.yml @@ -8,3 +8,6 @@ Metrics/CyclomaticComplexity: Enabled: false Metrics/PerceivedComplexity: Enabled: false +Metrics/MethodLength: + Enabled: false + diff --git a/lib/mindee/product/barcode_reader/barcode_reader_v1.rb b/lib/mindee/product/barcode_reader/barcode_reader_v1.rb index 4aed66a3..dc2e0ed2 100644 --- a/lib/mindee/product/barcode_reader/barcode_reader_v1.rb +++ b/lib/mindee/product/barcode_reader/barcode_reader_v1.rb @@ -12,6 +12,8 @@ module BarcodeReader class BarcodeReaderV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'barcode_reader' @endpoint_version = '1' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = BarcodeReaderV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(BarcodeReaderV1Page.new(page)) - end + @pages.push(BarcodeReaderV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/barcode_reader/barcode_reader_v1_document.rb b/lib/mindee/product/barcode_reader/barcode_reader_v1_document.rb index efb8da41..3f82168e 100644 --- a/lib/mindee/product/barcode_reader/barcode_reader_v1_document.rb +++ b/lib/mindee/product/barcode_reader/barcode_reader_v1_document.rb @@ -18,14 +18,14 @@ class BarcodeReaderV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @codes_1d = [] + super + @codes_1d = [] # : Array[Parsing::Standard::StringField] prediction['codes_1d'].each do |item| - @codes_1d.push(StringField.new(item, page_id)) + @codes_1d.push(Parsing::Standard::StringField.new(item, page_id)) end - @codes_2d = [] + @codes_2d = [] # : Array[Parsing::Standard::StringField] prediction['codes_2d'].each do |item| - @codes_2d.push(StringField.new(item, page_id)) + @codes_2d.push(Parsing::Standard::StringField.new(item, page_id)) end end diff --git a/lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb b/lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb index f99983dc..9eec7859 100644 --- a/lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb +++ b/lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb @@ -10,11 +10,15 @@ module BarcodeReader class BarcodeReaderV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = BarcodeReaderV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + BarcodeReaderV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/bill_of_lading/bill_of_lading_v1.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1.rb index 8a2eb2e6..620f6806 100644 --- a/lib/mindee/product/bill_of_lading/bill_of_lading_v1.rb +++ b/lib/mindee/product/bill_of_lading/bill_of_lading_v1.rb @@ -12,6 +12,8 @@ module BillOfLading class BillOfLadingV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'bill_of_lading' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = BillOfLadingV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(BillOfLadingV1Page.new(page)) - end + @pages.push(BillOfLadingV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rb index e8f66bfc..5e2db186 100644 --- a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rb +++ b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rb @@ -21,7 +21,7 @@ class BillOfLadingV1Carrier < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @name = prediction['name'] @professional_number = prediction['professional_number'] @scac = prediction['scac'] diff --git a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rb index 7a232c61..a68f03ba 100644 --- a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rb +++ b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rb @@ -30,7 +30,7 @@ class BillOfLadingV1CarrierItem < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @description = prediction['description'] @gross_weight = prediction['gross_weight'] @measurement = prediction['measurement'] @@ -44,10 +44,13 @@ def initialize(prediction, page_id) def printable_values printable = {} printable[:description] = format_for_display(@description) - printable[:gross_weight] = @gross_weight.nil? ? '' : Field.float_to_string(@gross_weight) - printable[:measurement] = @measurement.nil? ? '' : Field.float_to_string(@measurement) + printable[:gross_weight] = + @gross_weight.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@gross_weight) + printable[:measurement] = + @measurement.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@measurement) printable[:measurement_unit] = format_for_display(@measurement_unit) - printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity) + printable[:quantity] = + @quantity.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@quantity) printable[:weight_unit] = format_for_display(@weight_unit) printable end @@ -56,10 +59,13 @@ def printable_values def table_printable_values printable = {} printable[:description] = format_for_display(@description, 36) - printable[:gross_weight] = @gross_weight.nil? ? '' : Field.float_to_string(@gross_weight) - printable[:measurement] = @measurement.nil? ? '' : Field.float_to_string(@measurement) + printable[:gross_weight] = + @gross_weight.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@gross_weight) + printable[:measurement] = + @measurement.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@measurement) printable[:measurement_unit] = format_for_display(@measurement_unit, nil) - printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity) + printable[:quantity] = + @quantity.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@quantity) printable[:weight_unit] = format_for_display(@weight_unit, nil) printable end diff --git a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_items.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_items.rb new file mode 100644 index 00000000..056e433a --- /dev/null +++ b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_items.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require_relative 'bill_of_lading_v1_shipper' +require_relative 'bill_of_lading_v1_consignee' +require_relative 'bill_of_lading_v1_notify_party' +require_relative 'bill_of_lading_v1_carrier' +require_relative 'bill_of_lading_v1_carrier_item' + +module Mindee + module Product + module BillOfLading + # The goods being shipped. + class BillOfLadingV1CarrierItems < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + BillOfLading::BillOfLadingV1CarrierItem.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 38}" + out_str << "+#{char * 14}" + out_str << "+#{char * 13}" + out_str << "+#{char * 18}" + out_str << "+#{char * 10}" + out_str << "+#{char * 13}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Description ' + out_str << ' | Gross Weight' + out_str << ' | Measurement' + out_str << ' | Measurement Unit' + out_str << ' | Quantity' + out_str << ' | Weight Unit' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end +end diff --git a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rb index aacb0ef0..d81dd0dd 100644 --- a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rb +++ b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rb @@ -24,7 +24,7 @@ class BillOfLadingV1Consignee < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @address = prediction['address'] @email = prediction['email'] @name = prediction['name'] diff --git a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_document.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_document.rb index 2e355219..4e7fb064 100644 --- a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_document.rb +++ b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_document.rb @@ -5,7 +5,7 @@ require_relative 'bill_of_lading_v1_consignee' require_relative 'bill_of_lading_v1_notify_party' require_relative 'bill_of_lading_v1_carrier' -require_relative 'bill_of_lading_v1_carrier_item' +require_relative 'bill_of_lading_v1_carrier_items' module Mindee module Product @@ -20,7 +20,7 @@ class BillOfLadingV1Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Product::BillOfLading::BillOfLadingV1Carrier] attr_reader :carrier # The goods being shipped. - # @return [Array] + # @return [Mindee::Product::BillOfLading::BillOfLadingV1CarrierItems] attr_reader :carrier_items # The party to whom the goods are being shipped. # @return [Mindee::Product::BillOfLading::BillOfLadingV1Consignee] @@ -50,21 +50,48 @@ class BillOfLadingV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @bill_of_lading_number = StringField.new(prediction['bill_of_lading_number'], page_id) - @carrier = BillOfLadingV1Carrier.new(prediction['carrier'], page_id) - @carrier_items = [] - prediction['carrier_items'].each do |item| - @carrier_items.push(BillOfLadingV1CarrierItem.new(item, page_id)) - end - @consignee = BillOfLadingV1Consignee.new(prediction['consignee'], page_id) - @date_of_issue = DateField.new(prediction['date_of_issue'], page_id) - @departure_date = DateField.new(prediction['departure_date'], page_id) - @notify_party = BillOfLadingV1NotifyParty.new(prediction['notify_party'], page_id) - @place_of_delivery = StringField.new(prediction['place_of_delivery'], page_id) - @port_of_discharge = StringField.new(prediction['port_of_discharge'], page_id) - @port_of_loading = StringField.new(prediction['port_of_loading'], page_id) - @shipper = BillOfLadingV1Shipper.new(prediction['shipper'], page_id) + super + @bill_of_lading_number = Parsing::Standard::StringField.new( + prediction['bill_of_lading_number'], + page_id + ) + @carrier = Product::BillOfLading::BillOfLadingV1Carrier.new( + prediction['carrier'], + page_id + ) + @carrier_items = Product::BillOfLading::BillOfLadingV1CarrierItems.new(prediction['carrier_items'], page_id) + @consignee = Product::BillOfLading::BillOfLadingV1Consignee.new( + prediction['consignee'], + page_id + ) + @date_of_issue = Parsing::Standard::DateField.new( + prediction['date_of_issue'], + page_id + ) + @departure_date = Parsing::Standard::DateField.new( + prediction['departure_date'], + page_id + ) + @notify_party = Product::BillOfLading::BillOfLadingV1NotifyParty.new( + prediction['notify_party'], + page_id + ) + @place_of_delivery = Parsing::Standard::StringField.new( + prediction['place_of_delivery'], + page_id + ) + @port_of_discharge = Parsing::Standard::StringField.new( + prediction['port_of_discharge'], + page_id + ) + @port_of_loading = Parsing::Standard::StringField.new( + prediction['port_of_loading'], + page_id + ) + @shipper = Product::BillOfLading::BillOfLadingV1Shipper.new( + prediction['shipper'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rb index 754e8b21..b2cc144f 100644 --- a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rb +++ b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rb @@ -24,7 +24,7 @@ class BillOfLadingV1NotifyParty < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @address = prediction['address'] @email = prediction['email'] @name = prediction['name'] diff --git a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_page.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_page.rb index 932bb3b5..4a7093c8 100644 --- a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_page.rb +++ b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_page.rb @@ -10,11 +10,15 @@ module BillOfLading class BillOfLadingV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = BillOfLadingV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + BillOfLadingV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rb index 0e26e371..5ad40f7d 100644 --- a/lib/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rb +++ b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rb @@ -24,7 +24,7 @@ class BillOfLadingV1Shipper < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @address = prediction['address'] @email = prediction['email'] @name = prediction['name'] diff --git a/lib/mindee/product/business_card/business_card_v1.rb b/lib/mindee/product/business_card/business_card_v1.rb index fbd6cffc..79e9b7e4 100644 --- a/lib/mindee/product/business_card/business_card_v1.rb +++ b/lib/mindee/product/business_card/business_card_v1.rb @@ -12,6 +12,8 @@ module BusinessCard class BusinessCardV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'business_card' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = BusinessCardV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(BusinessCardV1Page.new(page)) - end + @pages.push(BusinessCardV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/business_card/business_card_v1_document.rb b/lib/mindee/product/business_card/business_card_v1_document.rb index cbef93ce..3a0d7082 100644 --- a/lib/mindee/product/business_card/business_card_v1_document.rb +++ b/lib/mindee/product/business_card/business_card_v1_document.rb @@ -45,21 +45,48 @@ class BusinessCardV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @address = StringField.new(prediction['address'], page_id) - @company = StringField.new(prediction['company'], page_id) - @email = StringField.new(prediction['email'], page_id) - @fax_number = StringField.new(prediction['fax_number'], page_id) - @firstname = StringField.new(prediction['firstname'], page_id) - @job_title = StringField.new(prediction['job_title'], page_id) - @lastname = StringField.new(prediction['lastname'], page_id) - @mobile_number = StringField.new(prediction['mobile_number'], page_id) - @phone_number = StringField.new(prediction['phone_number'], page_id) - @social_media = [] + super + @address = Parsing::Standard::StringField.new( + prediction['address'], + page_id + ) + @company = Parsing::Standard::StringField.new( + prediction['company'], + page_id + ) + @email = Parsing::Standard::StringField.new(prediction['email'], page_id) + @fax_number = Parsing::Standard::StringField.new( + prediction['fax_number'], + page_id + ) + @firstname = Parsing::Standard::StringField.new( + prediction['firstname'], + page_id + ) + @job_title = Parsing::Standard::StringField.new( + prediction['job_title'], + page_id + ) + @lastname = Parsing::Standard::StringField.new( + prediction['lastname'], + page_id + ) + @mobile_number = Parsing::Standard::StringField.new( + prediction['mobile_number'], + page_id + ) + @phone_number = Parsing::Standard::StringField.new( + prediction['phone_number'], + page_id + ) + @social_media = [] # : Array[Parsing::Standard::StringField] prediction['social_media'].each do |item| - @social_media.push(StringField.new(item, page_id)) + @social_media.push(Parsing::Standard::StringField.new(item, page_id)) end - @website = StringField.new(prediction['website'], page_id) + @website = Parsing::Standard::StringField.new( + prediction['website'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/business_card/business_card_v1_page.rb b/lib/mindee/product/business_card/business_card_v1_page.rb index 1e169dec..48813699 100644 --- a/lib/mindee/product/business_card/business_card_v1_page.rb +++ b/lib/mindee/product/business_card/business_card_v1_page.rb @@ -10,11 +10,15 @@ module BusinessCard class BusinessCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = BusinessCardV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + BusinessCardV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/cropper/cropper_v1.rb b/lib/mindee/product/cropper/cropper_v1.rb index 5451733f..83f312ab 100644 --- a/lib/mindee/product/cropper/cropper_v1.rb +++ b/lib/mindee/product/cropper/cropper_v1.rb @@ -12,16 +12,16 @@ module Cropper class CropperV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'cropper' @endpoint_version = '1' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) super - @prediction = CropperV1Document.new + @prediction = CropperV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(CropperV1Page.new(page)) - end + @pages.push(CropperV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/cropper/cropper_v1_page.rb b/lib/mindee/product/cropper/cropper_v1_page.rb index 28410be3..bff5ebe4 100644 --- a/lib/mindee/product/cropper/cropper_v1_page.rb +++ b/lib/mindee/product/cropper/cropper_v1_page.rb @@ -10,11 +10,15 @@ module Cropper class CropperV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = CropperV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + CropperV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end @@ -31,9 +35,9 @@ class CropperV1PagePrediction < CropperV1Document def initialize(prediction, page_id) @cropping = [] prediction['cropping'].each do |item| - @cropping.push(PositionField.new(item, page_id)) + @cropping.push(Parsing::Standard::PositionField.new(item, page_id)) end - super() + super end # @return [String] diff --git a/lib/mindee/product/custom/custom_v1.rb b/lib/mindee/product/custom/custom_v1.rb deleted file mode 100644 index fc20b790..00000000 --- a/lib/mindee/product/custom/custom_v1.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -require_relative 'custom_v1_document' -require_relative 'custom_v1_page' - -module Mindee - module Product - # Custom product module. - module Custom - # Custom Document V1 prediction inference. - class CustomV1 < Mindee::Parsing::Common::Inference - @endpoint_name = '' - @endpoint_version = '' - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = CustomV1Document.new(prediction['prediction'], nil) - @pages = [] - prediction['pages'].each do |page| - @pages.push(CustomV1Page.new(page)) - end - end - - class << self - # Name of the endpoint for this product. - # @return [String] - attr_reader :endpoint_name - # Version for this product. - # @return [String] - attr_reader :endpoint_version - end - end - end - end -end diff --git a/lib/mindee/product/custom/custom_v1_document.rb b/lib/mindee/product/custom/custom_v1_document.rb deleted file mode 100644 index cf269cf1..00000000 --- a/lib/mindee/product/custom/custom_v1_document.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../parsing' - -module Mindee - module Product - module Custom - # Custom Document V1 prediction - class CustomV1Document < Mindee::Parsing::Common::Prediction - # All value fields in the document - # @return [Hash] - attr_reader :fields - # All classifications in the document - # @return [Hash] - attr_reader :classifications - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - super() - @fields = {} - @classifications = {} - prediction.each do |field_name, field_prediction| - field_sym = field_name.to_sym - set_field(field_sym, field_prediction, page_id) - end - end - - # @return [String] - def to_s - out_str = String.new - @classifications.each do |name, info| - out_str << "\n:#{name}: #{info}".rstrip - end - @fields.each do |name, info| - out_str << "\n:#{name}: #{info}".rstrip - end - out_str[1..].to_s - end - - private - - # @param field_prediction [Hash] - def set_field(field_sym, field_prediction, page_id) - # Currently two types of fields possible in a custom API response: - # fields having a list of values, and classification fields. - # Here we use the fact that only value lists have the 'values' attribute. - - if field_prediction.key? 'values' - @fields[field_sym] = Parsing::Custom::ListField.new(field_prediction, page_id) - elsif field_prediction.key? 'value' - @classifications[field_sym] = Parsing::Custom::ClassificationField.new(field_prediction) - else - throw 'Unknown API field type' - end - end - end - end - end -end diff --git a/lib/mindee/product/custom/custom_v1_page.rb b/lib/mindee/product/custom/custom_v1_page.rb deleted file mode 100644 index 90fac855..00000000 --- a/lib/mindee/product/custom/custom_v1_page.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../parsing' -require_relative 'custom_v1_document' - -module Mindee - module Product - module Custom - # Custom Document V1 page. - class CustomV1Page < Mindee::Parsing::Common::Page - # @param prediction [Hash] - def initialize(prediction) - super(prediction) - @prediction = CustomV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) - end - end - - # Custom Document V1 page prediction. - class CustomV1PagePrediction < CustomV1Document - # @return [String] - def to_s - out_str = String.new - out_str << "\n#{super}" - out_str - end - end - end - end -end diff --git a/lib/mindee/product/delivery_note/delivery_note_v1.rb b/lib/mindee/product/delivery_note/delivery_note_v1.rb index 625df4da..f0e561d2 100644 --- a/lib/mindee/product/delivery_note/delivery_note_v1.rb +++ b/lib/mindee/product/delivery_note/delivery_note_v1.rb @@ -12,6 +12,8 @@ module DeliveryNote class DeliveryNoteV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'delivery_notes' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = DeliveryNoteV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(DeliveryNoteV1Page.new(page)) - end + @pages.push(DeliveryNoteV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/delivery_note/delivery_note_v1_document.rb b/lib/mindee/product/delivery_note/delivery_note_v1_document.rb index fa6bd474..20e7cbc8 100644 --- a/lib/mindee/product/delivery_note/delivery_note_v1_document.rb +++ b/lib/mindee/product/delivery_note/delivery_note_v1_document.rb @@ -33,14 +33,35 @@ class DeliveryNoteV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @customer_address = StringField.new(prediction['customer_address'], page_id) - @customer_name = StringField.new(prediction['customer_name'], page_id) - @delivery_date = DateField.new(prediction['delivery_date'], page_id) - @delivery_number = StringField.new(prediction['delivery_number'], page_id) - @supplier_address = StringField.new(prediction['supplier_address'], page_id) - @supplier_name = StringField.new(prediction['supplier_name'], page_id) - @total_amount = AmountField.new(prediction['total_amount'], page_id) + super + @customer_address = Parsing::Standard::StringField.new( + prediction['customer_address'], + page_id + ) + @customer_name = Parsing::Standard::StringField.new( + prediction['customer_name'], + page_id + ) + @delivery_date = Parsing::Standard::DateField.new( + prediction['delivery_date'], + page_id + ) + @delivery_number = Parsing::Standard::StringField.new( + prediction['delivery_number'], + page_id + ) + @supplier_address = Parsing::Standard::StringField.new( + prediction['supplier_address'], + page_id + ) + @supplier_name = Parsing::Standard::StringField.new( + prediction['supplier_name'], + page_id + ) + @total_amount = Parsing::Standard::AmountField.new( + prediction['total_amount'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/delivery_note/delivery_note_v1_page.rb b/lib/mindee/product/delivery_note/delivery_note_v1_page.rb index 68385150..b7aaa8e1 100644 --- a/lib/mindee/product/delivery_note/delivery_note_v1_page.rb +++ b/lib/mindee/product/delivery_note/delivery_note_v1_page.rb @@ -10,11 +10,15 @@ module DeliveryNote class DeliveryNoteV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = DeliveryNoteV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + DeliveryNoteV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/driver_license/driver_license_v1.rb b/lib/mindee/product/driver_license/driver_license_v1.rb index d9ee3bb8..6c1c016d 100644 --- a/lib/mindee/product/driver_license/driver_license_v1.rb +++ b/lib/mindee/product/driver_license/driver_license_v1.rb @@ -12,6 +12,8 @@ module DriverLicense class DriverLicenseV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'driver_license' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = DriverLicenseV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(DriverLicenseV1Page.new(page)) - end + @pages.push(DriverLicenseV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/driver_license/driver_license_v1_document.rb b/lib/mindee/product/driver_license/driver_license_v1_document.rb index 060f6315..1ecdf8af 100644 --- a/lib/mindee/product/driver_license/driver_license_v1_document.rb +++ b/lib/mindee/product/driver_license/driver_license_v1_document.rb @@ -51,20 +51,50 @@ class DriverLicenseV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @category = StringField.new(prediction['category'], page_id) - @country_code = StringField.new(prediction['country_code'], page_id) - @date_of_birth = DateField.new(prediction['date_of_birth'], page_id) - @dd_number = StringField.new(prediction['dd_number'], page_id) - @expiry_date = DateField.new(prediction['expiry_date'], page_id) - @first_name = StringField.new(prediction['first_name'], page_id) - @id = StringField.new(prediction['id'], page_id) - @issued_date = DateField.new(prediction['issued_date'], page_id) - @issuing_authority = StringField.new(prediction['issuing_authority'], page_id) - @last_name = StringField.new(prediction['last_name'], page_id) - @mrz = StringField.new(prediction['mrz'], page_id) - @place_of_birth = StringField.new(prediction['place_of_birth'], page_id) - @state = StringField.new(prediction['state'], page_id) + super + @category = Parsing::Standard::StringField.new( + prediction['category'], + page_id + ) + @country_code = Parsing::Standard::StringField.new( + prediction['country_code'], + page_id + ) + @date_of_birth = Parsing::Standard::DateField.new( + prediction['date_of_birth'], + page_id + ) + @dd_number = Parsing::Standard::StringField.new( + prediction['dd_number'], + page_id + ) + @expiry_date = Parsing::Standard::DateField.new( + prediction['expiry_date'], + page_id + ) + @first_name = Parsing::Standard::StringField.new( + prediction['first_name'], + page_id + ) + @id = Parsing::Standard::StringField.new(prediction['id'], page_id) + @issued_date = Parsing::Standard::DateField.new( + prediction['issued_date'], + page_id + ) + @issuing_authority = Parsing::Standard::StringField.new( + prediction['issuing_authority'], + page_id + ) + @last_name = Parsing::Standard::StringField.new( + prediction['last_name'], + page_id + ) + @mrz = Parsing::Standard::StringField.new(prediction['mrz'], page_id) + @place_of_birth = Parsing::Standard::StringField.new( + prediction['place_of_birth'], + page_id + ) + @state = Parsing::Standard::StringField.new(prediction['state'], page_id) end # @return [String] diff --git a/lib/mindee/product/driver_license/driver_license_v1_page.rb b/lib/mindee/product/driver_license/driver_license_v1_page.rb index f682e93c..3d1a3641 100644 --- a/lib/mindee/product/driver_license/driver_license_v1_page.rb +++ b/lib/mindee/product/driver_license/driver_license_v1_page.rb @@ -10,11 +10,15 @@ module DriverLicense class DriverLicenseV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = DriverLicenseV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + DriverLicenseV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/eu/driver_license/driver_license_v1.rb b/lib/mindee/product/eu/driver_license/driver_license_v1.rb deleted file mode 100644 index a68cd498..00000000 --- a/lib/mindee/product/eu/driver_license/driver_license_v1.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'driver_license_v1_document' -require_relative 'driver_license_v1_page' - -module Mindee - module Product - module EU - # Driver License module. - module DriverLicense - # Driver License API version 1 inference prediction. - class DriverLicenseV1 < Mindee::Parsing::Common::Inference - @endpoint_name = 'eu_driver_license' - @endpoint_version = '1' - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = DriverLicenseV1Document.new(prediction['prediction'], nil) - @pages = [] - prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(DriverLicenseV1Page.new(page)) - end - end - end - - class << self - # Name of the endpoint for this product. - # @return [String] - attr_reader :endpoint_name - # Version for this product. - # @return [String] - attr_reader :endpoint_version - end - end - end - end - end -end diff --git a/lib/mindee/product/eu/driver_license/driver_license_v1_document.rb b/lib/mindee/product/eu/driver_license/driver_license_v1_document.rb deleted file mode 100644 index 0cce8a6d..00000000 --- a/lib/mindee/product/eu/driver_license/driver_license_v1_document.rb +++ /dev/null @@ -1,88 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' - -module Mindee - module Product - module EU - module DriverLicense - # Driver License API version 1.0 document data. - class DriverLicenseV1Document < Mindee::Parsing::Common::Prediction - include Mindee::Parsing::Standard - # EU driver license holders address - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :address - # EU driver license holders categories - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :category - # Country code extracted as a string. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :country_code - # The date of birth of the document holder - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :date_of_birth - # ID number of the Document. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :document_id - # Date the document expires - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :expiry_date - # First name(s) of the driver license holder - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :first_name - # Authority that issued the document - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :issue_authority - # Date the document was issued - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :issue_date - # Last name of the driver license holder. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :last_name - # Machine-readable license number - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :mrz - # Place where the driver license holder was born - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :place_of_birth - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - super() - @address = StringField.new(prediction['address'], page_id) - @category = StringField.new(prediction['category'], page_id) - @country_code = StringField.new(prediction['country_code'], page_id) - @date_of_birth = DateField.new(prediction['date_of_birth'], page_id) - @document_id = StringField.new(prediction['document_id'], page_id) - @expiry_date = DateField.new(prediction['expiry_date'], page_id) - @first_name = StringField.new(prediction['first_name'], page_id) - @issue_authority = StringField.new(prediction['issue_authority'], page_id) - @issue_date = DateField.new(prediction['issue_date'], page_id) - @last_name = StringField.new(prediction['last_name'], page_id) - @mrz = StringField.new(prediction['mrz'], page_id) - @place_of_birth = StringField.new(prediction['place_of_birth'], page_id) - end - - # @return [String] - def to_s - out_str = String.new - out_str << "\n:Country Code: #{@country_code}".rstrip - out_str << "\n:Document ID: #{@document_id}".rstrip - out_str << "\n:Driver License Category: #{@category}".rstrip - out_str << "\n:Last Name: #{@last_name}".rstrip - out_str << "\n:First Name: #{@first_name}".rstrip - out_str << "\n:Date Of Birth: #{@date_of_birth}".rstrip - out_str << "\n:Place Of Birth: #{@place_of_birth}".rstrip - out_str << "\n:Expiry Date: #{@expiry_date}".rstrip - out_str << "\n:Issue Date: #{@issue_date}".rstrip - out_str << "\n:Issue Authority: #{@issue_authority}".rstrip - out_str << "\n:MRZ: #{@mrz}".rstrip - out_str << "\n:Address: #{@address}".rstrip - out_str[1..].to_s - end - end - end - end - end -end diff --git a/lib/mindee/product/eu/driver_license/driver_license_v1_page.rb b/lib/mindee/product/eu/driver_license/driver_license_v1_page.rb deleted file mode 100644 index a9ee6b49..00000000 --- a/lib/mindee/product/eu/driver_license/driver_license_v1_page.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'driver_license_v1_document' - -module Mindee - module Product - module EU - module DriverLicense - # Driver License API version 1.0 page data. - class DriverLicenseV1Page < Mindee::Parsing::Common::Page - # @param prediction [Hash] - def initialize(prediction) - super(prediction) - @prediction = DriverLicenseV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) - end - end - - # Driver License V1 page prediction. - class DriverLicenseV1PagePrediction < DriverLicenseV1Document - include Mindee::Parsing::Standard - - # Has a photo of the EU driver license holder - # @return [Mindee::Parsing::Standard::PositionField] - attr_reader :photo - # Has a signature of the EU driver license holder - # @return [Mindee::Parsing::Standard::PositionField] - attr_reader :signature - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - @photo = PositionField.new(prediction['photo'], page_id) - @signature = PositionField.new(prediction['signature'], page_id) - super(prediction, page_id) - end - - # @return [String] - def to_s - out_str = String.new - out_str << "\n:Photo: #{@photo}".rstrip - out_str << "\n:Signature: #{@signature}".rstrip - out_str << "\n#{super}" - out_str - end - end - end - end - end -end diff --git a/lib/mindee/product/eu/license_plate/license_plate_v1.rb b/lib/mindee/product/eu/license_plate/license_plate_v1.rb index d26e6996..b3c3b510 100644 --- a/lib/mindee/product/eu/license_plate/license_plate_v1.rb +++ b/lib/mindee/product/eu/license_plate/license_plate_v1.rb @@ -13,6 +13,8 @@ module LicensePlate class LicensePlateV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'license_plates' @endpoint_version = '1' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = LicensePlateV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(LicensePlateV1Page.new(page)) - end + @pages.push(LicensePlateV1Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb b/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb index 2def9620..ac4fa14e 100644 --- a/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb +++ b/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb @@ -16,10 +16,10 @@ class LicensePlateV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @license_plates = [] + super + @license_plates = [] # : Array[Parsing::Standard::StringField] prediction['license_plates'].each do |item| - @license_plates.push(StringField.new(item, page_id)) + @license_plates.push(Parsing::Standard::StringField.new(item, page_id)) end end diff --git a/lib/mindee/product/eu/license_plate/license_plate_v1_page.rb b/lib/mindee/product/eu/license_plate/license_plate_v1_page.rb index ad5c585e..48051ee9 100644 --- a/lib/mindee/product/eu/license_plate/license_plate_v1_page.rb +++ b/lib/mindee/product/eu/license_plate/license_plate_v1_page.rb @@ -11,11 +11,15 @@ module LicensePlate class LicensePlateV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = LicensePlateV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + LicensePlateV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/financial_document/financial_document_v1.rb b/lib/mindee/product/financial_document/financial_document_v1.rb index 80235198..4b8fc8c9 100644 --- a/lib/mindee/product/financial_document/financial_document_v1.rb +++ b/lib/mindee/product/financial_document/financial_document_v1.rb @@ -12,6 +12,8 @@ module FinancialDocument class FinancialDocumentV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'financial_document' @endpoint_version = '1' + @has_async = true + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = FinancialDocumentV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(FinancialDocumentV1Page.new(page)) - end + @pages.push(FinancialDocumentV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/financial_document/financial_document_v1_document.rb b/lib/mindee/product/financial_document/financial_document_v1_document.rb index be764785..89fe7e2d 100644 --- a/lib/mindee/product/financial_document/financial_document_v1_document.rb +++ b/lib/mindee/product/financial_document/financial_document_v1_document.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../../parsing' -require_relative 'financial_document_v1_line_item' +require_relative 'financial_document_v1_line_items' module Mindee module Product @@ -43,7 +43,7 @@ class FinancialDocumentV1Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Parsing::Standard::StringField] attr_reader :invoice_number # List of line item details. - # @return [Array] + # @return [Mindee::Product::FinancialDocument::FinancialDocumentV1LineItems] attr_reader :line_items # The locale detected on the document. # @return [Mindee::Parsing::Standard::LocaleField] @@ -109,54 +109,122 @@ class FinancialDocumentV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @billing_address = StringField.new(prediction['billing_address'], page_id) - @category = ClassificationField.new(prediction['category'], page_id) - @customer_address = StringField.new(prediction['customer_address'], page_id) - @customer_company_registrations = [] + super + @billing_address = Parsing::Standard::StringField.new( + prediction['billing_address'], + page_id + ) + @category = Parsing::Standard::ClassificationField.new( + prediction['category'], + page_id + ) + @customer_address = Parsing::Standard::StringField.new( + prediction['customer_address'], + page_id + ) + @customer_company_registrations = [] # : Array[Parsing::Standard::CompanyRegistrationField] prediction['customer_company_registrations'].each do |item| - @customer_company_registrations.push(CompanyRegistrationField.new(item, page_id)) + @customer_company_registrations.push(Parsing::Standard::CompanyRegistrationField.new(item, page_id)) end - @customer_id = StringField.new(prediction['customer_id'], page_id) - @customer_name = StringField.new(prediction['customer_name'], page_id) - @date = DateField.new(prediction['date'], page_id) - @document_number = StringField.new(prediction['document_number'], page_id) - @document_type = ClassificationField.new(prediction['document_type'], page_id) - @due_date = DateField.new(prediction['due_date'], page_id) - @invoice_number = StringField.new(prediction['invoice_number'], page_id) - @line_items = [] - prediction['line_items'].each do |item| - @line_items.push(FinancialDocumentV1LineItem.new(item, page_id)) - end - @locale = LocaleField.new(prediction['locale'], page_id) - @payment_date = DateField.new(prediction['payment_date'], page_id) - @po_number = StringField.new(prediction['po_number'], page_id) - @receipt_number = StringField.new(prediction['receipt_number'], page_id) - @reference_numbers = [] + @customer_id = Parsing::Standard::StringField.new( + prediction['customer_id'], + page_id + ) + @customer_name = Parsing::Standard::StringField.new( + prediction['customer_name'], + page_id + ) + @date = Parsing::Standard::DateField.new(prediction['date'], page_id) + @document_number = Parsing::Standard::StringField.new( + prediction['document_number'], + page_id + ) + @document_type = Parsing::Standard::ClassificationField.new( + prediction['document_type'], + page_id + ) + @due_date = Parsing::Standard::DateField.new( + prediction['due_date'], + page_id + ) + @invoice_number = Parsing::Standard::StringField.new( + prediction['invoice_number'], + page_id + ) + @line_items = Product::FinancialDocument::FinancialDocumentV1LineItems.new( + prediction['line_items'], page_id + ) + @locale = Parsing::Standard::LocaleField.new( + prediction['locale'], + page_id + ) + @payment_date = Parsing::Standard::DateField.new( + prediction['payment_date'], + page_id + ) + @po_number = Parsing::Standard::StringField.new( + prediction['po_number'], + page_id + ) + @receipt_number = Parsing::Standard::StringField.new( + prediction['receipt_number'], + page_id + ) + @reference_numbers = [] # : Array[Parsing::Standard::StringField] prediction['reference_numbers'].each do |item| - @reference_numbers.push(StringField.new(item, page_id)) + @reference_numbers.push(Parsing::Standard::StringField.new(item, page_id)) end - @shipping_address = StringField.new(prediction['shipping_address'], page_id) - @subcategory = ClassificationField.new(prediction['subcategory'], page_id) - @supplier_address = StringField.new(prediction['supplier_address'], page_id) - @supplier_company_registrations = [] + @shipping_address = Parsing::Standard::StringField.new( + prediction['shipping_address'], + page_id + ) + @subcategory = Parsing::Standard::ClassificationField.new( + prediction['subcategory'], + page_id + ) + @supplier_address = Parsing::Standard::StringField.new( + prediction['supplier_address'], + page_id + ) + @supplier_company_registrations = [] # : Array[Parsing::Standard::CompanyRegistrationField] prediction['supplier_company_registrations'].each do |item| - @supplier_company_registrations.push(CompanyRegistrationField.new(item, page_id)) + @supplier_company_registrations.push(Parsing::Standard::CompanyRegistrationField.new(item, page_id)) end - @supplier_email = StringField.new(prediction['supplier_email'], page_id) - @supplier_name = StringField.new(prediction['supplier_name'], page_id) - @supplier_payment_details = [] + @supplier_email = Parsing::Standard::StringField.new( + prediction['supplier_email'], + page_id + ) + @supplier_name = Parsing::Standard::StringField.new( + prediction['supplier_name'], + page_id + ) + @supplier_payment_details = [] # : Array[Parsing::Standard::PaymentDetailsField] prediction['supplier_payment_details'].each do |item| - @supplier_payment_details.push(PaymentDetailsField.new(item, page_id)) + @supplier_payment_details.push(Parsing::Standard::PaymentDetailsField.new(item, page_id)) end - @supplier_phone_number = StringField.new(prediction['supplier_phone_number'], page_id) - @supplier_website = StringField.new(prediction['supplier_website'], page_id) - @taxes = Taxes.new(prediction['taxes'], page_id) - @time = StringField.new(prediction['time'], page_id) - @tip = AmountField.new(prediction['tip'], page_id) - @total_amount = AmountField.new(prediction['total_amount'], page_id) - @total_net = AmountField.new(prediction['total_net'], page_id) - @total_tax = AmountField.new(prediction['total_tax'], page_id) + @supplier_phone_number = Parsing::Standard::StringField.new( + prediction['supplier_phone_number'], + page_id + ) + @supplier_website = Parsing::Standard::StringField.new( + prediction['supplier_website'], + page_id + ) + @taxes = Parsing::Standard::Taxes.new(prediction['taxes'], page_id) + @time = Parsing::Standard::StringField.new(prediction['time'], page_id) + @tip = Parsing::Standard::AmountField.new(prediction['tip'], page_id) + @total_amount = Parsing::Standard::AmountField.new( + prediction['total_amount'], + page_id + ) + @total_net = Parsing::Standard::AmountField.new( + prediction['total_net'], + page_id + ) + @total_tax = Parsing::Standard::AmountField.new( + prediction['total_tax'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/financial_document/financial_document_v1_line_item.rb b/lib/mindee/product/financial_document/financial_document_v1_line_item.rb index dffc5af8..9a726502 100644 --- a/lib/mindee/product/financial_document/financial_document_v1_line_item.rb +++ b/lib/mindee/product/financial_document/financial_document_v1_line_item.rb @@ -36,7 +36,7 @@ class FinancialDocumentV1LineItem < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @description = prediction['description'] @product_code = prediction['product_code'] @quantity = prediction['quantity'] @@ -53,12 +53,17 @@ def printable_values printable = {} printable[:description] = format_for_display(@description) printable[:product_code] = format_for_display(@product_code) - printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity) - printable[:tax_amount] = @tax_amount.nil? ? '' : Field.float_to_string(@tax_amount) - printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate) - printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount) + printable[:quantity] = + @quantity.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@quantity) + printable[:tax_amount] = + @tax_amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_amount) + printable[:tax_rate] = + @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate) + printable[:total_amount] = + @total_amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total_amount) printable[:unit_measure] = format_for_display(@unit_measure) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end @@ -67,12 +72,17 @@ def table_printable_values printable = {} printable[:description] = format_for_display(@description, 36) printable[:product_code] = format_for_display(@product_code, nil) - printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity) - printable[:tax_amount] = @tax_amount.nil? ? '' : Field.float_to_string(@tax_amount) - printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate) - printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount) + printable[:quantity] = + @quantity.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@quantity) + printable[:tax_amount] = + @tax_amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_amount) + printable[:tax_rate] = + @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate) + printable[:total_amount] = + @total_amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total_amount) printable[:unit_measure] = format_for_display(@unit_measure, nil) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end diff --git a/lib/mindee/product/financial_document/financial_document_v1_line_items.rb b/lib/mindee/product/financial_document/financial_document_v1_line_items.rb new file mode 100644 index 00000000..2c43c3b8 --- /dev/null +++ b/lib/mindee/product/financial_document/financial_document_v1_line_items.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require_relative 'financial_document_v1_line_item' + +module Mindee + module Product + module FinancialDocument + # List of line item details. + class FinancialDocumentV1LineItems < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + FinancialDocument::FinancialDocumentV1LineItem.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 38}" + out_str << "+#{char * 14}" + out_str << "+#{char * 10}" + out_str << "+#{char * 12}" + out_str << "+#{char * 14}" + out_str << "+#{char * 14}" + out_str << "+#{char * 17}" + out_str << "+#{char * 12}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Description ' + out_str << ' | Product code' + out_str << ' | Quantity' + out_str << ' | Tax Amount' + out_str << ' | Tax Rate (%)' + out_str << ' | Total Amount' + out_str << ' | Unit of measure' + out_str << ' | Unit Price' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end +end diff --git a/lib/mindee/product/financial_document/financial_document_v1_page.rb b/lib/mindee/product/financial_document/financial_document_v1_page.rb index d9c2ddaf..5917e3e9 100644 --- a/lib/mindee/product/financial_document/financial_document_v1_page.rb +++ b/lib/mindee/product/financial_document/financial_document_v1_page.rb @@ -10,11 +10,15 @@ module FinancialDocument class FinancialDocumentV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = FinancialDocumentV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + FinancialDocumentV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb b/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb index 5d5d9f87..edb3ada1 100644 --- a/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb +++ b/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb @@ -13,6 +13,8 @@ module BankAccountDetails class BankAccountDetailsV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'bank_account_details' @endpoint_version = '1' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = BankAccountDetailsV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(BankAccountDetailsV1Page.new(page)) - end + @pages.push(BankAccountDetailsV1Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb b/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb index 607200d4..d2675020 100644 --- a/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb +++ b/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb @@ -22,10 +22,13 @@ class BankAccountDetailsV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @account_holder_name = StringField.new(prediction['account_holder_name'], page_id) - @iban = StringField.new(prediction['iban'], page_id) - @swift = StringField.new(prediction['swift'], page_id) + super + @account_holder_name = Parsing::Standard::StringField.new( + prediction['account_holder_name'], + page_id + ) + @iban = Parsing::Standard::StringField.new(prediction['iban'], page_id) + @swift = Parsing::Standard::StringField.new(prediction['swift'], page_id) end # @return [String] diff --git a/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rb b/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rb index 88ea7d29..93c5571e 100644 --- a/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rb +++ b/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rb @@ -11,11 +11,15 @@ module BankAccountDetails class BankAccountDetailsV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = BankAccountDetailsV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + BankAccountDetailsV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb b/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb index 96645436..b2f0465f 100644 --- a/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb +++ b/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb @@ -13,6 +13,8 @@ module BankAccountDetails class BankAccountDetailsV2 < Mindee::Parsing::Common::Inference @endpoint_name = 'bank_account_details' @endpoint_version = '2' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = BankAccountDetailsV2Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(BankAccountDetailsV2Page.new(page)) - end + @pages.push(BankAccountDetailsV2Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb b/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb index abd3b854..387fd306 100644 --- a/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb +++ b/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb @@ -25,7 +25,7 @@ class BankAccountDetailsV2Bban < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @bban_bank_code = prediction['bban_bank_code'] @bban_branch_code = prediction['bban_branch_code'] @bban_key = prediction['bban_key'] diff --git a/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb b/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb index c5356750..aee8f850 100644 --- a/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb +++ b/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb @@ -26,11 +26,17 @@ class BankAccountDetailsV2Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @account_holders_names = StringField.new(prediction['account_holders_names'], page_id) - @bban = BankAccountDetailsV2Bban.new(prediction['bban'], page_id) - @iban = StringField.new(prediction['iban'], page_id) - @swift_code = StringField.new(prediction['swift_code'], page_id) + super + @account_holders_names = Parsing::Standard::StringField.new( + prediction['account_holders_names'], + page_id + ) + @bban = Product::FR::BankAccountDetails::BankAccountDetailsV2Bban.new(prediction['bban'], page_id) + @iban = Parsing::Standard::StringField.new(prediction['iban'], page_id) + @swift_code = Parsing::Standard::StringField.new( + prediction['swift_code'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb b/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb index bdc59b9b..7e835e3c 100644 --- a/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb +++ b/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb @@ -11,11 +11,15 @@ module BankAccountDetails class BankAccountDetailsV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = BankAccountDetailsV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + BankAccountDetailsV2PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/fr/bank_statement/bank_statement_v1.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v1.rb deleted file mode 100644 index 5da9f781..00000000 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'bank_statement_v1_document' -require_relative 'bank_statement_v1_page' - -module Mindee - module Product - module FR - # Bank Statement (FR) module. - module BankStatement - # Bank Statement (FR) V1 prediction inference. - class BankStatementV1 < Mindee::Parsing::Common::Inference - @endpoint_name = 'bank_statement_fr' - @endpoint_version = '1' - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = BankStatementV1Document.new(prediction['prediction'], nil) - @pages = [] - prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(BankStatementV1Page.new(page)) - end - end - end - - class << self - # Name of the endpoint for this product. - # @return [String] - attr_reader :endpoint_name - # Version for this product. - # @return [String] - attr_reader :endpoint_version - end - end - end - end - end -end diff --git a/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb deleted file mode 100644 index 540784c4..00000000 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb +++ /dev/null @@ -1,130 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'bank_statement_v1_transaction' - -module Mindee - module Product - module FR - module BankStatement - # Bank Statement (FR) V1 document prediction. - class BankStatementV1Document < Mindee::Parsing::Common::Prediction - include Mindee::Parsing::Standard - # The unique identifier for a customer's account in the bank's system. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :account_number - # The physical location of the bank where the statement was issued. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :bank_address - # The name of the bank that issued the statement. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :bank_name - # The address of the client associated with the bank statement. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :client_address - # The name of the client who owns the bank statement. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :client_name - # The final amount of money in the account at the end of the statement period. - # @return [Mindee::Parsing::Standard::AmountField] - attr_reader :closing_balance - # The initial amount of money in an account at the start of the period. - # @return [Mindee::Parsing::Standard::AmountField] - attr_reader :opening_balance - # The date on which the bank statement was generated. - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :statement_date - # The date when the statement period ends. - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :statement_end_date - # The date when the bank statement period begins. - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :statement_start_date - # The total amount of money deposited into the account. - # @return [Mindee::Parsing::Standard::AmountField] - attr_reader :total_credits - # The total amount of money debited from the account. - # @return [Mindee::Parsing::Standard::AmountField] - attr_reader :total_debits - # The list of values that represent the financial transactions recorded in a bank statement. - # @return [Array] - attr_reader :transactions - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - super() - @account_number = StringField.new(prediction['account_number'], page_id) - @bank_address = StringField.new(prediction['bank_address'], page_id) - @bank_name = StringField.new(prediction['bank_name'], page_id) - @client_address = StringField.new(prediction['client_address'], page_id) - @client_name = StringField.new(prediction['client_name'], page_id) - @closing_balance = AmountField.new(prediction['closing_balance'], page_id) - @opening_balance = AmountField.new(prediction['opening_balance'], page_id) - @statement_date = DateField.new(prediction['statement_date'], page_id) - @statement_end_date = DateField.new(prediction['statement_end_date'], page_id) - @statement_start_date = DateField.new(prediction['statement_start_date'], page_id) - @total_credits = AmountField.new(prediction['total_credits'], page_id) - @total_debits = AmountField.new(prediction['total_debits'], page_id) - @transactions = [] - prediction['transactions'].each do |item| - @transactions.push(BankStatementV1Transaction.new(item, page_id)) - end - end - - # @return [String] - def to_s - transactions = transactions_to_s - out_str = String.new - out_str << "\n:Account Number: #{@account_number}".rstrip - out_str << "\n:Bank Name: #{@bank_name}".rstrip - out_str << "\n:Bank Address: #{@bank_address}".rstrip - out_str << "\n:Client Name: #{@client_name}".rstrip - out_str << "\n:Client Address: #{@client_address}".rstrip - out_str << "\n:Statement Date: #{@statement_date}".rstrip - out_str << "\n:Statement Start Date: #{@statement_start_date}".rstrip - out_str << "\n:Statement End Date: #{@statement_end_date}".rstrip - out_str << "\n:Opening Balance: #{@opening_balance}".rstrip - out_str << "\n:Closing Balance: #{@closing_balance}".rstrip - out_str << "\n:Transactions:" - out_str << transactions - out_str << "\n:Total Debits: #{@total_debits}".rstrip - out_str << "\n:Total Credits: #{@total_credits}".rstrip - out_str[1..].to_s - end - - private - - # @param char [String] - # @return [String] - def transactions_separator(char) - out_str = String.new - out_str << ' ' - out_str << "+#{char * 11}" - out_str << "+#{char * 12}" - out_str << "+#{char * 38}" - out_str << '+' - out_str - end - - # @return [String] - def transactions_to_s - return '' if @transactions.empty? - - line_items = @transactions.map(&:to_table_line).join("\n#{transactions_separator('-')}\n ") - out_str = String.new - out_str << "\n#{transactions_separator('-')}" - out_str << "\n |" - out_str << ' Amount |' - out_str << ' Date |' - out_str << ' Description |' - out_str << "\n#{transactions_separator('=')}" - out_str << "\n #{line_items}" - out_str << "\n#{transactions_separator('-')}" - out_str - end - end - end - end - end -end diff --git a/lib/mindee/product/fr/bank_statement/bank_statement_v1_page.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v1_page.rb deleted file mode 100644 index 85d3cf59..00000000 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_page.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'bank_statement_v1_document' - -module Mindee - module Product - module FR - module BankStatement - # Bank Statement (FR) V1 page. - class BankStatementV1Page < Mindee::Parsing::Common::Page - # @param prediction [Hash] - def initialize(prediction) - super(prediction) - @prediction = BankStatementV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) - end - end - - # Bank Statement (FR) V1 page prediction. - class BankStatementV1PagePrediction < BankStatementV1Document - # @return [String] - def to_s - out_str = String.new - out_str << "\n#{super}" - out_str - end - end - end - end - end -end diff --git a/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb deleted file mode 100644 index 562f734f..00000000 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb +++ /dev/null @@ -1,64 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' - -module Mindee - module Product - module FR - module BankStatement - # The list of values that represent the financial transactions recorded in a bank statement. - class BankStatementV1Transaction < Mindee::Parsing::Standard::FeatureField - include Mindee::Parsing::Standard - # The monetary amount of the transaction. - # @return [Float] - attr_reader :amount - # The date on which the transaction occurred. - # @return [String] - attr_reader :date - # The additional information about the transaction. - # @return [String] - attr_reader :description - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - super(prediction, page_id) - @amount = prediction['amount'] - @date = prediction['date'] - @description = prediction['description'] - @page_id = page_id - end - - # @return [Hash] - def printable_values - printable = {} - printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount) - printable[:date] = format_for_display(@date, nil) - printable[:description] = format_for_display(@description, 36) - printable - end - - # @return [String] - def to_table_line - printable = printable_values - out_str = String.new - out_str << format('| %- 10s', printable[:amount]) - out_str << format('| %- 11s', printable[:date]) - out_str << format('| %- 37s', printable[:description]) - out_str << '|' - end - - # @return [String] - def to_s - printable = printable_values - out_str = String.new - out_str << "\n :Amount: #{printable[:amount]}" - out_str << "\n :Date: #{printable[:date]}" - out_str << "\n :Description: #{printable[:description]}" - out_str - end - end - end - end - end -end diff --git a/lib/mindee/product/fr/bank_statement/bank_statement_v2.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v2.rb index dc0516d4..c119d46f 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v2.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v2.rb @@ -13,6 +13,8 @@ module BankStatement class BankStatementV2 < Mindee::Parsing::Common::Inference @endpoint_name = 'bank_statement_fr' @endpoint_version = '2' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = BankStatementV2Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(BankStatementV2Page.new(page)) - end + @pages.push(BankStatementV2Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/bank_statement/bank_statement_v2_document.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v2_document.rb index 21122a70..21f0490b 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v2_document.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v2_document.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../../../parsing' -require_relative 'bank_statement_v2_transaction' +require_relative 'bank_statement_v2_transactions' module Mindee module Product @@ -47,32 +47,64 @@ class BankStatementV2Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Parsing::Standard::AmountField] attr_reader :total_debits # The list of values that represent the financial transactions recorded in a bank statement. - # @return [Array] + # @return [Mindee::Product::FR::BankStatement::BankStatementV2Transactions] attr_reader :transactions # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @account_number = StringField.new(prediction['account_number'], page_id) - @bank_address = StringField.new(prediction['bank_address'], page_id) - @bank_name = StringField.new(prediction['bank_name'], page_id) - @client_address = StringField.new(prediction['client_address'], page_id) - @client_names = [] + super + @account_number = Parsing::Standard::StringField.new( + prediction['account_number'], + page_id + ) + @bank_address = Parsing::Standard::StringField.new( + prediction['bank_address'], + page_id + ) + @bank_name = Parsing::Standard::StringField.new( + prediction['bank_name'], + page_id + ) + @client_address = Parsing::Standard::StringField.new( + prediction['client_address'], + page_id + ) + @client_names = [] # : Array[Parsing::Standard::StringField] prediction['client_names'].each do |item| - @client_names.push(StringField.new(item, page_id)) - end - @closing_balance = AmountField.new(prediction['closing_balance'], page_id) - @opening_balance = AmountField.new(prediction['opening_balance'], page_id) - @statement_date = DateField.new(prediction['statement_date'], page_id) - @statement_end_date = DateField.new(prediction['statement_end_date'], page_id) - @statement_start_date = DateField.new(prediction['statement_start_date'], page_id) - @total_credits = AmountField.new(prediction['total_credits'], page_id) - @total_debits = AmountField.new(prediction['total_debits'], page_id) - @transactions = [] - prediction['transactions'].each do |item| - @transactions.push(BankStatementV2Transaction.new(item, page_id)) + @client_names.push(Parsing::Standard::StringField.new(item, page_id)) end + @closing_balance = Parsing::Standard::AmountField.new( + prediction['closing_balance'], + page_id + ) + @opening_balance = Parsing::Standard::AmountField.new( + prediction['opening_balance'], + page_id + ) + @statement_date = Parsing::Standard::DateField.new( + prediction['statement_date'], + page_id + ) + @statement_end_date = Parsing::Standard::DateField.new( + prediction['statement_end_date'], + page_id + ) + @statement_start_date = Parsing::Standard::DateField.new( + prediction['statement_start_date'], + page_id + ) + @total_credits = Parsing::Standard::AmountField.new( + prediction['total_credits'], + page_id + ) + @total_debits = Parsing::Standard::AmountField.new( + prediction['total_debits'], + page_id + ) + @transactions = Product::FR::BankStatement::BankStatementV2Transactions.new( + prediction['transactions'], page_id + ) end # @return [String] diff --git a/lib/mindee/product/fr/bank_statement/bank_statement_v2_page.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v2_page.rb index 490ac440..d0e3976c 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v2_page.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v2_page.rb @@ -11,11 +11,15 @@ module BankStatement class BankStatementV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = BankStatementV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + BankStatementV2PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rb index b539d98d..a75bb208 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rb @@ -22,7 +22,7 @@ class BankStatementV2Transaction < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @amount = prediction['amount'] @date = prediction['date'] @description = prediction['description'] @@ -32,7 +32,8 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount) + printable[:amount] = + @amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@amount) printable[:date] = format_for_display(@date) printable[:description] = format_for_display(@description) printable @@ -41,7 +42,8 @@ def printable_values # @return [Hash] def table_printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount) + printable[:amount] = + @amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@amount) printable[:date] = format_for_display(@date, 10) printable[:description] = format_for_display(@description, 36) printable diff --git a/lib/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rb new file mode 100644 index 00000000..b62ca3ff --- /dev/null +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require_relative 'bank_statement_v2_transaction' + +module Mindee + module Product + module FR + module BankStatement + # The list of values that represent the financial transactions recorded in a bank statement. + class BankStatementV2Transactions < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + BankStatement::BankStatementV2Transaction.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 12}" + out_str << "+#{char * 12}" + out_str << "+#{char * 38}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Amount ' + out_str << ' | Date ' + out_str << ' | Description ' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end + end +end diff --git a/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb b/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb index c54f692b..72f9f971 100644 --- a/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb +++ b/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb @@ -13,6 +13,8 @@ module CarteGrise class CarteGriseV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'carte_grise' @endpoint_version = '1' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = CarteGriseV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(CarteGriseV1Page.new(page)) - end + @pages.push(CarteGriseV1Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/carte_grise/carte_grise_v1_document.rb b/lib/mindee/product/fr/carte_grise/carte_grise_v1_document.rb index d3a903d5..20f5c712 100644 --- a/lib/mindee/product/fr/carte_grise/carte_grise_v1_document.rb +++ b/lib/mindee/product/fr/carte_grise/carte_grise_v1_document.rb @@ -136,48 +136,57 @@ class CarteGriseV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @a = StringField.new(prediction['a'], page_id) - @b = DateField.new(prediction['b'], page_id) - @c1 = StringField.new(prediction['c1'], page_id) - @c3 = StringField.new(prediction['c3'], page_id) - @c41 = StringField.new(prediction['c41'], page_id) - @c4a = StringField.new(prediction['c4a'], page_id) - @d1 = StringField.new(prediction['d1'], page_id) - @d3 = StringField.new(prediction['d3'], page_id) - @e = StringField.new(prediction['e'], page_id) - @f1 = StringField.new(prediction['f1'], page_id) - @f2 = StringField.new(prediction['f2'], page_id) - @f3 = StringField.new(prediction['f3'], page_id) - @formula_number = StringField.new(prediction['formula_number'], page_id) - @g = StringField.new(prediction['g'], page_id) - @g1 = StringField.new(prediction['g1'], page_id) - @i = DateField.new(prediction['i'], page_id) - @j = StringField.new(prediction['j'], page_id) - @j1 = StringField.new(prediction['j1'], page_id) - @j2 = StringField.new(prediction['j2'], page_id) - @j3 = StringField.new(prediction['j3'], page_id) - @mrz1 = StringField.new(prediction['mrz1'], page_id) - @mrz2 = StringField.new(prediction['mrz2'], page_id) - @owner_first_name = StringField.new(prediction['owner_first_name'], page_id) - @owner_surname = StringField.new(prediction['owner_surname'], page_id) - @p1 = StringField.new(prediction['p1'], page_id) - @p2 = StringField.new(prediction['p2'], page_id) - @p3 = StringField.new(prediction['p3'], page_id) - @p6 = StringField.new(prediction['p6'], page_id) - @q = StringField.new(prediction['q'], page_id) - @s1 = StringField.new(prediction['s1'], page_id) - @s2 = StringField.new(prediction['s2'], page_id) - @u1 = StringField.new(prediction['u1'], page_id) - @u2 = StringField.new(prediction['u2'], page_id) - @v7 = StringField.new(prediction['v7'], page_id) - @x1 = StringField.new(prediction['x1'], page_id) - @y1 = StringField.new(prediction['y1'], page_id) - @y2 = StringField.new(prediction['y2'], page_id) - @y3 = StringField.new(prediction['y3'], page_id) - @y4 = StringField.new(prediction['y4'], page_id) - @y5 = StringField.new(prediction['y5'], page_id) - @y6 = StringField.new(prediction['y6'], page_id) + super + @a = Parsing::Standard::StringField.new(prediction['a'], page_id) + @b = Parsing::Standard::DateField.new(prediction['b'], page_id) + @c1 = Parsing::Standard::StringField.new(prediction['c1'], page_id) + @c3 = Parsing::Standard::StringField.new(prediction['c3'], page_id) + @c41 = Parsing::Standard::StringField.new(prediction['c41'], page_id) + @c4a = Parsing::Standard::StringField.new(prediction['c4a'], page_id) + @d1 = Parsing::Standard::StringField.new(prediction['d1'], page_id) + @d3 = Parsing::Standard::StringField.new(prediction['d3'], page_id) + @e = Parsing::Standard::StringField.new(prediction['e'], page_id) + @f1 = Parsing::Standard::StringField.new(prediction['f1'], page_id) + @f2 = Parsing::Standard::StringField.new(prediction['f2'], page_id) + @f3 = Parsing::Standard::StringField.new(prediction['f3'], page_id) + @formula_number = Parsing::Standard::StringField.new( + prediction['formula_number'], + page_id + ) + @g = Parsing::Standard::StringField.new(prediction['g'], page_id) + @g1 = Parsing::Standard::StringField.new(prediction['g1'], page_id) + @i = Parsing::Standard::DateField.new(prediction['i'], page_id) + @j = Parsing::Standard::StringField.new(prediction['j'], page_id) + @j1 = Parsing::Standard::StringField.new(prediction['j1'], page_id) + @j2 = Parsing::Standard::StringField.new(prediction['j2'], page_id) + @j3 = Parsing::Standard::StringField.new(prediction['j3'], page_id) + @mrz1 = Parsing::Standard::StringField.new(prediction['mrz1'], page_id) + @mrz2 = Parsing::Standard::StringField.new(prediction['mrz2'], page_id) + @owner_first_name = Parsing::Standard::StringField.new( + prediction['owner_first_name'], + page_id + ) + @owner_surname = Parsing::Standard::StringField.new( + prediction['owner_surname'], + page_id + ) + @p1 = Parsing::Standard::StringField.new(prediction['p1'], page_id) + @p2 = Parsing::Standard::StringField.new(prediction['p2'], page_id) + @p3 = Parsing::Standard::StringField.new(prediction['p3'], page_id) + @p6 = Parsing::Standard::StringField.new(prediction['p6'], page_id) + @q = Parsing::Standard::StringField.new(prediction['q'], page_id) + @s1 = Parsing::Standard::StringField.new(prediction['s1'], page_id) + @s2 = Parsing::Standard::StringField.new(prediction['s2'], page_id) + @u1 = Parsing::Standard::StringField.new(prediction['u1'], page_id) + @u2 = Parsing::Standard::StringField.new(prediction['u2'], page_id) + @v7 = Parsing::Standard::StringField.new(prediction['v7'], page_id) + @x1 = Parsing::Standard::StringField.new(prediction['x1'], page_id) + @y1 = Parsing::Standard::StringField.new(prediction['y1'], page_id) + @y2 = Parsing::Standard::StringField.new(prediction['y2'], page_id) + @y3 = Parsing::Standard::StringField.new(prediction['y3'], page_id) + @y4 = Parsing::Standard::StringField.new(prediction['y4'], page_id) + @y5 = Parsing::Standard::StringField.new(prediction['y5'], page_id) + @y6 = Parsing::Standard::StringField.new(prediction['y6'], page_id) end # @return [String] diff --git a/lib/mindee/product/fr/carte_grise/carte_grise_v1_page.rb b/lib/mindee/product/fr/carte_grise/carte_grise_v1_page.rb index 2d477974..492e459c 100644 --- a/lib/mindee/product/fr/carte_grise/carte_grise_v1_page.rb +++ b/lib/mindee/product/fr/carte_grise/carte_grise_v1_page.rb @@ -11,11 +11,15 @@ module CarteGrise class CarteGriseV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = CarteGriseV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + CarteGriseV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb index 43b51675..6f7ec95f 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb @@ -13,6 +13,8 @@ module EnergyBill class EnergyBillV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'energy_bill_fra' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = EnergyBillV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(EnergyBillV1Page.new(page)) - end + @pages.push(EnergyBillV1Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_document.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_document.rb index 1d51c426..cf9e49c2 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1_document.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_document.rb @@ -3,9 +3,9 @@ require_relative '../../../parsing' require_relative 'energy_bill_v1_energy_supplier' require_relative 'energy_bill_v1_energy_consumer' -require_relative 'energy_bill_v1_subscription' -require_relative 'energy_bill_v1_energy_usage' -require_relative 'energy_bill_v1_taxes_and_contribution' +require_relative 'energy_bill_v1_subscriptions' +require_relative 'energy_bill_v1_energy_usages' +require_relative 'energy_bill_v1_taxes_and_contributions' require_relative 'energy_bill_v1_meter_detail' module Mindee @@ -32,7 +32,7 @@ class EnergyBillV1Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Product::FR::EnergyBill::EnergyBillV1EnergySupplier] attr_reader :energy_supplier # Details of energy consumption. - # @return [Array] + # @return [Mindee::Product::FR::EnergyBill::EnergyBillV1EnergyUsages] attr_reader :energy_usage # The date when the energy invoice was issued. # @return [Mindee::Parsing::Standard::DateField] @@ -44,10 +44,10 @@ class EnergyBillV1Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Product::FR::EnergyBill::EnergyBillV1MeterDetail] attr_reader :meter_details # The subscription details fee for the energy service. - # @return [Array] + # @return [Mindee::Product::FR::EnergyBill::EnergyBillV1Subscriptions] attr_reader :subscription # Details of Taxes and Contributions. - # @return [Array] + # @return [Mindee::Product::FR::EnergyBill::EnergyBillV1TaxesAndContributions] attr_reader :taxes_and_contributions # The total amount to be paid for the energy invoice. # @return [Mindee::Parsing::Standard::AmountField] @@ -62,30 +62,56 @@ class EnergyBillV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @contract_id = StringField.new(prediction['contract_id'], page_id) - @delivery_point = StringField.new(prediction['delivery_point'], page_id) - @due_date = DateField.new(prediction['due_date'], page_id) - @energy_consumer = EnergyBillV1EnergyConsumer.new(prediction['energy_consumer'], page_id) - @energy_supplier = EnergyBillV1EnergySupplier.new(prediction['energy_supplier'], page_id) - @energy_usage = [] - prediction['energy_usage'].each do |item| - @energy_usage.push(EnergyBillV1EnergyUsage.new(item, page_id)) - end - @invoice_date = DateField.new(prediction['invoice_date'], page_id) - @invoice_number = StringField.new(prediction['invoice_number'], page_id) - @meter_details = EnergyBillV1MeterDetail.new(prediction['meter_details'], page_id) - @subscription = [] - prediction['subscription'].each do |item| - @subscription.push(EnergyBillV1Subscription.new(item, page_id)) - end - @taxes_and_contributions = [] - prediction['taxes_and_contributions'].each do |item| - @taxes_and_contributions.push(EnergyBillV1TaxesAndContribution.new(item, page_id)) - end - @total_amount = AmountField.new(prediction['total_amount'], page_id) - @total_before_taxes = AmountField.new(prediction['total_before_taxes'], page_id) - @total_taxes = AmountField.new(prediction['total_taxes'], page_id) + super + @contract_id = Parsing::Standard::StringField.new( + prediction['contract_id'], + page_id + ) + @delivery_point = Parsing::Standard::StringField.new( + prediction['delivery_point'], + page_id + ) + @due_date = Parsing::Standard::DateField.new( + prediction['due_date'], + page_id + ) + @energy_consumer = Product::FR::EnergyBill::EnergyBillV1EnergyConsumer.new( + prediction['energy_consumer'], + page_id + ) + @energy_supplier = Product::FR::EnergyBill::EnergyBillV1EnergySupplier.new( + prediction['energy_supplier'], + page_id + ) + @energy_usage = Product::FR::EnergyBill::EnergyBillV1EnergyUsages.new(prediction['energy_usage'], page_id) + @invoice_date = Parsing::Standard::DateField.new( + prediction['invoice_date'], + page_id + ) + @invoice_number = Parsing::Standard::StringField.new( + prediction['invoice_number'], + page_id + ) + @meter_details = Product::FR::EnergyBill::EnergyBillV1MeterDetail.new( + prediction['meter_details'], + page_id + ) + @subscription = Product::FR::EnergyBill::EnergyBillV1Subscriptions.new(prediction['subscription'], page_id) + @taxes_and_contributions = Product::FR::EnergyBill::EnergyBillV1TaxesAndContributions.new( + prediction['taxes_and_contributions'], page_id + ) + @total_amount = Parsing::Standard::AmountField.new( + prediction['total_amount'], + page_id + ) + @total_before_taxes = Parsing::Standard::AmountField.new( + prediction['total_before_taxes'], + page_id + ) + @total_taxes = Parsing::Standard::AmountField.new( + prediction['total_taxes'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rb index b9ba50d3..6d6ce2f5 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rb @@ -19,7 +19,7 @@ class EnergyBillV1EnergyConsumer < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @address = prediction['address'] @name = prediction['name'] @page_id = page_id diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rb index e787b50e..6bf004f7 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rb @@ -19,7 +19,7 @@ class EnergyBillV1EnergySupplier < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @address = prediction['address'] @name = prediction['name'] @page_id = page_id diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb index 1dc13db7..7efa8404 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb @@ -31,7 +31,7 @@ class EnergyBillV1EnergyUsage < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @description = prediction['description'] @end_date = prediction['end_date'] @start_date = prediction['start_date'] @@ -47,9 +47,12 @@ def printable_values printable[:description] = format_for_display(@description) printable[:end_date] = format_for_display(@end_date) printable[:start_date] = format_for_display(@start_date) - printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : Field.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:tax_rate] = + @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate) + printable[:total] = + @total.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end @@ -59,9 +62,12 @@ def table_printable_values printable[:description] = format_for_display(@description, 36) printable[:end_date] = format_for_display(@end_date, 10) printable[:start_date] = format_for_display(@start_date, nil) - printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : Field.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:tax_rate] = + @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate) + printable[:total] = + @total.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usages.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usages.rb new file mode 100644 index 00000000..e89b5080 --- /dev/null +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usages.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require_relative 'energy_bill_v1_energy_supplier' +require_relative 'energy_bill_v1_energy_consumer' +require_relative 'energy_bill_v1_subscription' +require_relative 'energy_bill_v1_energy_usage' +require_relative 'energy_bill_v1_taxes_and_contribution' +require_relative 'energy_bill_v1_meter_detail' + +module Mindee + module Product + module FR + module EnergyBill + # Details of energy consumption. + class EnergyBillV1EnergyUsages < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + EnergyBill::EnergyBillV1EnergyUsage.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 38}" + out_str << "+#{char * 12}" + out_str << "+#{char * 12}" + out_str << "+#{char * 10}" + out_str << "+#{char * 11}" + out_str << "+#{char * 12}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Description ' + out_str << ' | End Date ' + out_str << ' | Start Date' + out_str << ' | Tax Rate' + out_str << ' | Total ' + out_str << ' | Unit Price' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end + end +end diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rb index 4101839c..deda7226 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rb @@ -22,7 +22,7 @@ class EnergyBillV1MeterDetail < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @meter_number = prediction['meter_number'] @meter_type = prediction['meter_type'] @unit = prediction['unit'] diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_page.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_page.rb index 0c765eac..475f382a 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1_page.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_page.rb @@ -11,11 +11,15 @@ module EnergyBill class EnergyBillV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = EnergyBillV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + EnergyBillV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rb index c3a5a019..f34fe464 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rb @@ -31,7 +31,7 @@ class EnergyBillV1Subscription < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @description = prediction['description'] @end_date = prediction['end_date'] @start_date = prediction['start_date'] @@ -47,9 +47,12 @@ def printable_values printable[:description] = format_for_display(@description) printable[:end_date] = format_for_display(@end_date) printable[:start_date] = format_for_display(@start_date) - printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : Field.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:tax_rate] = + @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate) + printable[:total] = + @total.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end @@ -59,9 +62,12 @@ def table_printable_values printable[:description] = format_for_display(@description, 36) printable[:end_date] = format_for_display(@end_date, 10) printable[:start_date] = format_for_display(@start_date, nil) - printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : Field.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:tax_rate] = + @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate) + printable[:total] = + @total.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscriptions.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscriptions.rb new file mode 100644 index 00000000..e5e062a1 --- /dev/null +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscriptions.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require_relative 'energy_bill_v1_energy_supplier' +require_relative 'energy_bill_v1_energy_consumer' +require_relative 'energy_bill_v1_subscription' +require_relative 'energy_bill_v1_energy_usage' +require_relative 'energy_bill_v1_taxes_and_contribution' +require_relative 'energy_bill_v1_meter_detail' + +module Mindee + module Product + module FR + module EnergyBill + # The subscription details fee for the energy service. + class EnergyBillV1Subscriptions < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + EnergyBill::EnergyBillV1Subscription.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 38}" + out_str << "+#{char * 12}" + out_str << "+#{char * 12}" + out_str << "+#{char * 10}" + out_str << "+#{char * 11}" + out_str << "+#{char * 12}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Description ' + out_str << ' | End Date ' + out_str << ' | Start Date' + out_str << ' | Tax Rate' + out_str << ' | Total ' + out_str << ' | Unit Price' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end + end +end diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rb index 37f7ad1d..64fbe239 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rb @@ -31,7 +31,7 @@ class EnergyBillV1TaxesAndContribution < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @description = prediction['description'] @end_date = prediction['end_date'] @start_date = prediction['start_date'] @@ -47,9 +47,12 @@ def printable_values printable[:description] = format_for_display(@description) printable[:end_date] = format_for_display(@end_date) printable[:start_date] = format_for_display(@start_date) - printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : Field.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:tax_rate] = + @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate) + printable[:total] = + @total.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end @@ -59,9 +62,12 @@ def table_printable_values printable[:description] = format_for_display(@description, 36) printable[:end_date] = format_for_display(@end_date, 10) printable[:start_date] = format_for_display(@start_date, nil) - printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : Field.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:tax_rate] = + @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate) + printable[:total] = + @total.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end diff --git a/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contributions.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contributions.rb new file mode 100644 index 00000000..4d21d279 --- /dev/null +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contributions.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require_relative 'energy_bill_v1_energy_supplier' +require_relative 'energy_bill_v1_energy_consumer' +require_relative 'energy_bill_v1_subscription' +require_relative 'energy_bill_v1_energy_usage' +require_relative 'energy_bill_v1_taxes_and_contribution' +require_relative 'energy_bill_v1_meter_detail' + +module Mindee + module Product + module FR + module EnergyBill + # Details of Taxes and Contributions. + class EnergyBillV1TaxesAndContributions < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + EnergyBill::EnergyBillV1TaxesAndContribution.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 38}" + out_str << "+#{char * 12}" + out_str << "+#{char * 12}" + out_str << "+#{char * 10}" + out_str << "+#{char * 11}" + out_str << "+#{char * 12}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Description ' + out_str << ' | End Date ' + out_str << ' | Start Date' + out_str << ' | Tax Rate' + out_str << ' | Total ' + out_str << ' | Unit Price' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end + end +end diff --git a/lib/mindee/product/fr/health_card/health_card_v1.rb b/lib/mindee/product/fr/health_card/health_card_v1.rb index 4528a722..0869f4d9 100644 --- a/lib/mindee/product/fr/health_card/health_card_v1.rb +++ b/lib/mindee/product/fr/health_card/health_card_v1.rb @@ -13,6 +13,8 @@ module HealthCard class HealthCardV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'french_healthcard' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = HealthCardV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(HealthCardV1Page.new(page)) - end + @pages.push(HealthCardV1Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/health_card/health_card_v1_document.rb b/lib/mindee/product/fr/health_card/health_card_v1_document.rb index 8682199f..96a27dda 100644 --- a/lib/mindee/product/fr/health_card/health_card_v1_document.rb +++ b/lib/mindee/product/fr/health_card/health_card_v1_document.rb @@ -25,14 +25,23 @@ class HealthCardV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @given_names = [] + super + @given_names = [] # : Array[Parsing::Standard::StringField] prediction['given_names'].each do |item| - @given_names.push(StringField.new(item, page_id)) + @given_names.push(Parsing::Standard::StringField.new(item, page_id)) end - @issuance_date = DateField.new(prediction['issuance_date'], page_id) - @social_security = StringField.new(prediction['social_security'], page_id) - @surname = StringField.new(prediction['surname'], page_id) + @issuance_date = Parsing::Standard::DateField.new( + prediction['issuance_date'], + page_id + ) + @social_security = Parsing::Standard::StringField.new( + prediction['social_security'], + page_id + ) + @surname = Parsing::Standard::StringField.new( + prediction['surname'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/fr/health_card/health_card_v1_page.rb b/lib/mindee/product/fr/health_card/health_card_v1_page.rb index 0059eab8..c92dac68 100644 --- a/lib/mindee/product/fr/health_card/health_card_v1_page.rb +++ b/lib/mindee/product/fr/health_card/health_card_v1_page.rb @@ -11,11 +11,15 @@ module HealthCard class HealthCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = HealthCardV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + HealthCardV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/fr/id_card/id_card_v1.rb b/lib/mindee/product/fr/id_card/id_card_v1.rb index e09d7756..63cb3bdc 100644 --- a/lib/mindee/product/fr/id_card/id_card_v1.rb +++ b/lib/mindee/product/fr/id_card/id_card_v1.rb @@ -13,6 +13,8 @@ module IdCard class IdCardV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'idcard_fr' @endpoint_version = '1' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = IdCardV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(IdCardV1Page.new(page)) - end + @pages.push(IdCardV1Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/id_card/id_card_v1_document.rb b/lib/mindee/product/fr/id_card/id_card_v1_document.rb index 9d6feae3..c893d907 100644 --- a/lib/mindee/product/fr/id_card/id_card_v1_document.rb +++ b/lib/mindee/product/fr/id_card/id_card_v1_document.rb @@ -43,20 +43,41 @@ class IdCardV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @authority = StringField.new(prediction['authority'], page_id) - @birth_date = DateField.new(prediction['birth_date'], page_id) - @birth_place = StringField.new(prediction['birth_place'], page_id) - @expiry_date = DateField.new(prediction['expiry_date'], page_id) - @gender = StringField.new(prediction['gender'], page_id) - @given_names = [] + super + @authority = Parsing::Standard::StringField.new( + prediction['authority'], + page_id + ) + @birth_date = Parsing::Standard::DateField.new( + prediction['birth_date'], + page_id + ) + @birth_place = Parsing::Standard::StringField.new( + prediction['birth_place'], + page_id + ) + @expiry_date = Parsing::Standard::DateField.new( + prediction['expiry_date'], + page_id + ) + @gender = Parsing::Standard::StringField.new( + prediction['gender'], + page_id + ) + @given_names = [] # : Array[Parsing::Standard::StringField] prediction['given_names'].each do |item| - @given_names.push(StringField.new(item, page_id)) + @given_names.push(Parsing::Standard::StringField.new(item, page_id)) end - @id_number = StringField.new(prediction['id_number'], page_id) - @mrz1 = StringField.new(prediction['mrz1'], page_id) - @mrz2 = StringField.new(prediction['mrz2'], page_id) - @surname = StringField.new(prediction['surname'], page_id) + @id_number = Parsing::Standard::StringField.new( + prediction['id_number'], + page_id + ) + @mrz1 = Parsing::Standard::StringField.new(prediction['mrz1'], page_id) + @mrz2 = Parsing::Standard::StringField.new(prediction['mrz2'], page_id) + @surname = Parsing::Standard::StringField.new( + prediction['surname'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/fr/id_card/id_card_v1_page.rb b/lib/mindee/product/fr/id_card/id_card_v1_page.rb index fccf3524..3aa026a4 100644 --- a/lib/mindee/product/fr/id_card/id_card_v1_page.rb +++ b/lib/mindee/product/fr/id_card/id_card_v1_page.rb @@ -11,11 +11,15 @@ module IdCard class IdCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = IdCardV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + IdCardV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end @@ -30,8 +34,11 @@ class IdCardV1PagePrediction < IdCardV1Document # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - @document_side = ClassificationField.new(prediction['document_side'], page_id) - super(prediction, page_id) + @document_side = Parsing::Standard::ClassificationField.new( + prediction['document_side'], + page_id + ) + super end # @return [String] diff --git a/lib/mindee/product/fr/id_card/id_card_v2.rb b/lib/mindee/product/fr/id_card/id_card_v2.rb index d8e26c09..9bf5daf7 100644 --- a/lib/mindee/product/fr/id_card/id_card_v2.rb +++ b/lib/mindee/product/fr/id_card/id_card_v2.rb @@ -13,6 +13,8 @@ module IdCard class IdCardV2 < Mindee::Parsing::Common::Inference @endpoint_name = 'idcard_fr' @endpoint_version = '2' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = IdCardV2Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(IdCardV2Page.new(page)) - end + @pages.push(IdCardV2Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/id_card/id_card_v2_document.rb b/lib/mindee/product/fr/id_card/id_card_v2_document.rb index 696cf3fb..e367ad22 100644 --- a/lib/mindee/product/fr/id_card/id_card_v2_document.rb +++ b/lib/mindee/product/fr/id_card/id_card_v2_document.rb @@ -58,25 +58,58 @@ class IdCardV2Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @alternate_name = StringField.new(prediction['alternate_name'], page_id) - @authority = StringField.new(prediction['authority'], page_id) - @birth_date = DateField.new(prediction['birth_date'], page_id) - @birth_place = StringField.new(prediction['birth_place'], page_id) - @card_access_number = StringField.new(prediction['card_access_number'], page_id) - @document_number = StringField.new(prediction['document_number'], page_id) - @expiry_date = DateField.new(prediction['expiry_date'], page_id) - @gender = StringField.new(prediction['gender'], page_id) - @given_names = [] + super + @alternate_name = Parsing::Standard::StringField.new( + prediction['alternate_name'], + page_id + ) + @authority = Parsing::Standard::StringField.new( + prediction['authority'], + page_id + ) + @birth_date = Parsing::Standard::DateField.new( + prediction['birth_date'], + page_id + ) + @birth_place = Parsing::Standard::StringField.new( + prediction['birth_place'], + page_id + ) + @card_access_number = Parsing::Standard::StringField.new( + prediction['card_access_number'], + page_id + ) + @document_number = Parsing::Standard::StringField.new( + prediction['document_number'], + page_id + ) + @expiry_date = Parsing::Standard::DateField.new( + prediction['expiry_date'], + page_id + ) + @gender = Parsing::Standard::StringField.new( + prediction['gender'], + page_id + ) + @given_names = [] # : Array[Parsing::Standard::StringField] prediction['given_names'].each do |item| - @given_names.push(StringField.new(item, page_id)) + @given_names.push(Parsing::Standard::StringField.new(item, page_id)) end - @issue_date = DateField.new(prediction['issue_date'], page_id) - @mrz1 = StringField.new(prediction['mrz1'], page_id) - @mrz2 = StringField.new(prediction['mrz2'], page_id) - @mrz3 = StringField.new(prediction['mrz3'], page_id) - @nationality = StringField.new(prediction['nationality'], page_id) - @surname = StringField.new(prediction['surname'], page_id) + @issue_date = Parsing::Standard::DateField.new( + prediction['issue_date'], + page_id + ) + @mrz1 = Parsing::Standard::StringField.new(prediction['mrz1'], page_id) + @mrz2 = Parsing::Standard::StringField.new(prediction['mrz2'], page_id) + @mrz3 = Parsing::Standard::StringField.new(prediction['mrz3'], page_id) + @nationality = Parsing::Standard::StringField.new( + prediction['nationality'], + page_id + ) + @surname = Parsing::Standard::StringField.new( + prediction['surname'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/fr/id_card/id_card_v2_page.rb b/lib/mindee/product/fr/id_card/id_card_v2_page.rb index 5606df9d..afd8ce3b 100644 --- a/lib/mindee/product/fr/id_card/id_card_v2_page.rb +++ b/lib/mindee/product/fr/id_card/id_card_v2_page.rb @@ -11,11 +11,15 @@ module IdCard class IdCardV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = IdCardV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + IdCardV2PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end @@ -33,9 +37,15 @@ class IdCardV2PagePrediction < IdCardV2Document # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - @document_side = ClassificationField.new(prediction['document_side'], page_id) - @document_type = ClassificationField.new(prediction['document_type'], page_id) - super(prediction, page_id) + @document_side = Parsing::Standard::ClassificationField.new( + prediction['document_side'], + page_id + ) + @document_type = Parsing::Standard::ClassificationField.new( + prediction['document_type'], + page_id + ) + super end # @return [String] diff --git a/lib/mindee/product/fr/payslip/payslip_v2.rb b/lib/mindee/product/fr/payslip/payslip_v2.rb index f6d42859..68eb1239 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2.rb @@ -13,6 +13,8 @@ module Payslip class PayslipV2 < Mindee::Parsing::Common::Inference @endpoint_name = 'payslip_fra' @endpoint_version = '2' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = PayslipV2Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(PayslipV2Page.new(page)) - end + @pages.push(PayslipV2Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rb b/lib/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rb index 5d81f69b..fd43efb9 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rb @@ -22,7 +22,7 @@ class PayslipV2BankAccountDetail < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @bank_name = prediction['bank_name'] @iban = prediction['iban'] @swift = prediction['swift'] diff --git a/lib/mindee/product/fr/payslip/payslip_v2_document.rb b/lib/mindee/product/fr/payslip/payslip_v2_document.rb index 11b62400..1643fde6 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_document.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_document.rb @@ -5,7 +5,7 @@ require_relative 'payslip_v2_employer' require_relative 'payslip_v2_bank_account_detail' require_relative 'payslip_v2_employment' -require_relative 'payslip_v2_salary_detail' +require_relative 'payslip_v2_salary_details' require_relative 'payslip_v2_pay_detail' require_relative 'payslip_v2_pto' require_relative 'payslip_v2_pay_period' @@ -39,24 +39,39 @@ class PayslipV2Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Product::FR::Payslip::PayslipV2Pto] attr_reader :pto # Detailed information about the earnings. - # @return [Array] + # @return [Mindee::Product::FR::Payslip::PayslipV2SalaryDetails] attr_reader :salary_details # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @bank_account_details = PayslipV2BankAccountDetail.new(prediction['bank_account_details'], page_id) - @employee = PayslipV2Employee.new(prediction['employee'], page_id) - @employer = PayslipV2Employer.new(prediction['employer'], page_id) - @employment = PayslipV2Employment.new(prediction['employment'], page_id) - @pay_detail = PayslipV2PayDetail.new(prediction['pay_detail'], page_id) - @pay_period = PayslipV2PayPeriod.new(prediction['pay_period'], page_id) - @pto = PayslipV2Pto.new(prediction['pto'], page_id) - @salary_details = [] - prediction['salary_details'].each do |item| - @salary_details.push(PayslipV2SalaryDetail.new(item, page_id)) - end + super + @bank_account_details = Product::FR::Payslip::PayslipV2BankAccountDetail.new( + prediction['bank_account_details'], + page_id + ) + @employee = Product::FR::Payslip::PayslipV2Employee.new( + prediction['employee'], + page_id + ) + @employer = Product::FR::Payslip::PayslipV2Employer.new( + prediction['employer'], + page_id + ) + @employment = Product::FR::Payslip::PayslipV2Employment.new( + prediction['employment'], + page_id + ) + @pay_detail = Product::FR::Payslip::PayslipV2PayDetail.new( + prediction['pay_detail'], + page_id + ) + @pay_period = Product::FR::Payslip::PayslipV2PayPeriod.new( + prediction['pay_period'], + page_id + ) + @pto = Product::FR::Payslip::PayslipV2Pto.new(prediction['pto'], page_id) + @salary_details = Product::FR::Payslip::PayslipV2SalaryDetails.new(prediction['salary_details'], page_id) end # @return [String] diff --git a/lib/mindee/product/fr/payslip/payslip_v2_employee.rb b/lib/mindee/product/fr/payslip/payslip_v2_employee.rb index 3ae4b220..9dd1d2da 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_employee.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_employee.rb @@ -34,7 +34,7 @@ class PayslipV2Employee < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @address = prediction['address'] @date_of_birth = prediction['date_of_birth'] @first_name = prediction['first_name'] diff --git a/lib/mindee/product/fr/payslip/payslip_v2_employer.rb b/lib/mindee/product/fr/payslip/payslip_v2_employer.rb index bc8dd924..d7452651 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_employer.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_employer.rb @@ -34,7 +34,7 @@ class PayslipV2Employer < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @address = prediction['address'] @company_id = prediction['company_id'] @company_site = prediction['company_site'] diff --git a/lib/mindee/product/fr/payslip/payslip_v2_employment.rb b/lib/mindee/product/fr/payslip/payslip_v2_employment.rb index 3146f623..1221a046 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_employment.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_employment.rb @@ -31,7 +31,7 @@ class PayslipV2Employment < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @category = prediction['category'] @coefficient = prediction['coefficient'] @collective_agreement = prediction['collective_agreement'] @@ -45,7 +45,8 @@ def initialize(prediction, page_id) def printable_values printable = {} printable[:category] = format_for_display(@category) - printable[:coefficient] = @coefficient.nil? ? '' : Field.float_to_string(@coefficient) + printable[:coefficient] = + @coefficient.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@coefficient) printable[:collective_agreement] = format_for_display(@collective_agreement) printable[:job_title] = format_for_display(@job_title) printable[:position_level] = format_for_display(@position_level) diff --git a/lib/mindee/product/fr/payslip/payslip_v2_page.rb b/lib/mindee/product/fr/payslip/payslip_v2_page.rb index 8adcffd6..05e8914b 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_page.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_page.rb @@ -11,11 +11,15 @@ module Payslip class PayslipV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = PayslipV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + PayslipV2PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb b/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb index 6d5aa6e5..8ebe6ca0 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb @@ -43,7 +43,7 @@ class PayslipV2PayDetail < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @gross_salary = prediction['gross_salary'] @gross_salary_ytd = prediction['gross_salary_ytd'] @income_tax_rate = prediction['income_tax_rate'] @@ -60,20 +60,42 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:gross_salary] = @gross_salary.nil? ? '' : Field.float_to_string(@gross_salary) - printable[:gross_salary_ytd] = @gross_salary_ytd.nil? ? '' : Field.float_to_string(@gross_salary_ytd) - printable[:income_tax_rate] = @income_tax_rate.nil? ? '' : Field.float_to_string(@income_tax_rate) + printable[:gross_salary] = + @gross_salary.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@gross_salary) + printable[:gross_salary_ytd] = + @gross_salary_ytd.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@gross_salary_ytd) + printable[:income_tax_rate] = + @income_tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@income_tax_rate) printable[:income_tax_withheld] = - @income_tax_withheld.nil? ? '' : Field.float_to_string(@income_tax_withheld) - printable[:net_paid] = @net_paid.nil? ? '' : Field.float_to_string(@net_paid) + if @income_tax_withheld.nil? + '' + else + Parsing::Standard::BaseField.float_to_string(@income_tax_withheld) + end + printable[:net_paid] = + @net_paid.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@net_paid) printable[:net_paid_before_tax] = - @net_paid_before_tax.nil? ? '' : Field.float_to_string(@net_paid_before_tax) - printable[:net_taxable] = @net_taxable.nil? ? '' : Field.float_to_string(@net_taxable) - printable[:net_taxable_ytd] = @net_taxable_ytd.nil? ? '' : Field.float_to_string(@net_taxable_ytd) + if @net_paid_before_tax.nil? + '' + else + Parsing::Standard::BaseField.float_to_string(@net_paid_before_tax) + end + printable[:net_taxable] = + @net_taxable.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@net_taxable) + printable[:net_taxable_ytd] = + @net_taxable_ytd.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@net_taxable_ytd) printable[:total_cost_employer] = - @total_cost_employer.nil? ? '' : Field.float_to_string(@total_cost_employer) + if @total_cost_employer.nil? + '' + else + Parsing::Standard::BaseField.float_to_string(@total_cost_employer) + end printable[:total_taxes_and_deductions] = - @total_taxes_and_deductions.nil? ? '' : Field.float_to_string(@total_taxes_and_deductions) + if @total_taxes_and_deductions.nil? + '' + else + Parsing::Standard::BaseField.float_to_string(@total_taxes_and_deductions) + end printable end diff --git a/lib/mindee/product/fr/payslip/payslip_v2_pay_period.rb b/lib/mindee/product/fr/payslip/payslip_v2_pay_period.rb index 73301557..6d731f1d 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_pay_period.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_pay_period.rb @@ -28,7 +28,7 @@ class PayslipV2PayPeriod < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @end_date = prediction['end_date'] @month = prediction['month'] @payment_date = prediction['payment_date'] diff --git a/lib/mindee/product/fr/payslip/payslip_v2_pto.rb b/lib/mindee/product/fr/payslip/payslip_v2_pto.rb index 78f30bd3..22387410 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_pto.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_pto.rb @@ -22,7 +22,7 @@ class PayslipV2Pto < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @accrued_this_period = prediction['accrued_this_period'] @balance_end_of_period = prediction['balance_end_of_period'] @used_this_period = prediction['used_this_period'] @@ -33,10 +33,19 @@ def initialize(prediction, page_id) def printable_values printable = {} printable[:accrued_this_period] = - @accrued_this_period.nil? ? '' : Field.float_to_string(@accrued_this_period) + if @accrued_this_period.nil? + '' + else + Parsing::Standard::BaseField.float_to_string(@accrued_this_period) + end printable[:balance_end_of_period] = - @balance_end_of_period.nil? ? '' : Field.float_to_string(@balance_end_of_period) - printable[:used_this_period] = @used_this_period.nil? ? '' : Field.float_to_string(@used_this_period) + if @balance_end_of_period.nil? + '' + else + Parsing::Standard::BaseField.float_to_string(@balance_end_of_period) + end + printable[:used_this_period] = + @used_this_period.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@used_this_period) printable end diff --git a/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb b/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb index c4260402..48328cf1 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb @@ -25,7 +25,7 @@ class PayslipV2SalaryDetail < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @amount = prediction['amount'] @base = prediction['base'] @description = prediction['description'] @@ -36,20 +36,26 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount) - printable[:base] = @base.nil? ? '' : Field.float_to_string(@base) + printable[:amount] = + @amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@amount) + printable[:base] = + @base.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@base) printable[:description] = format_for_display(@description) - printable[:rate] = @rate.nil? ? '' : Field.float_to_string(@rate) + printable[:rate] = + @rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@rate) printable end # @return [Hash] def table_printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount) - printable[:base] = @base.nil? ? '' : Field.float_to_string(@base) + printable[:amount] = + @amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@amount) + printable[:base] = + @base.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@base) printable[:description] = format_for_display(@description, 36) - printable[:rate] = @rate.nil? ? '' : Field.float_to_string(@rate) + printable[:rate] = + @rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@rate) printable end diff --git a/lib/mindee/product/fr/payslip/payslip_v2_salary_details.rb b/lib/mindee/product/fr/payslip/payslip_v2_salary_details.rb new file mode 100644 index 00000000..cd6d0378 --- /dev/null +++ b/lib/mindee/product/fr/payslip/payslip_v2_salary_details.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require_relative 'payslip_v2_employee' +require_relative 'payslip_v2_employer' +require_relative 'payslip_v2_bank_account_detail' +require_relative 'payslip_v2_employment' +require_relative 'payslip_v2_salary_detail' +require_relative 'payslip_v2_pay_detail' +require_relative 'payslip_v2_pto' +require_relative 'payslip_v2_pay_period' + +module Mindee + module Product + module FR + module Payslip + # Detailed information about the earnings. + class PayslipV2SalaryDetails < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + Payslip::PayslipV2SalaryDetail.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 14}" + out_str << "+#{char * 11}" + out_str << "+#{char * 38}" + out_str << "+#{char * 11}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Amount ' + out_str << ' | Base ' + out_str << ' | Description ' + out_str << ' | Rate ' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end + end +end diff --git a/lib/mindee/product/fr/payslip/payslip_v3.rb b/lib/mindee/product/fr/payslip/payslip_v3.rb index a6f5fc74..6eeabe65 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3.rb @@ -13,6 +13,8 @@ module Payslip class PayslipV3 < Mindee::Parsing::Common::Inference @endpoint_name = 'payslip_fra' @endpoint_version = '3' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = PayslipV3Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(PayslipV3Page.new(page)) - end + @pages.push(PayslipV3Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rb b/lib/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rb index e7be7dad..84e411f7 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rb @@ -22,7 +22,7 @@ class PayslipV3BankAccountDetail < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @bank_name = prediction['bank_name'] @iban = prediction['iban'] @swift = prediction['swift'] diff --git a/lib/mindee/product/fr/payslip/payslip_v3_document.rb b/lib/mindee/product/fr/payslip/payslip_v3_document.rb index 721de190..7689f166 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_document.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_document.rb @@ -6,9 +6,9 @@ require_relative 'payslip_v3_employer' require_relative 'payslip_v3_bank_account_detail' require_relative 'payslip_v3_employment' -require_relative 'payslip_v3_salary_detail' +require_relative 'payslip_v3_salary_details' require_relative 'payslip_v3_pay_detail' -require_relative 'payslip_v3_paid_time_off' +require_relative 'payslip_v3_paid_time_offs' module Mindee module Product @@ -30,7 +30,7 @@ class PayslipV3Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Product::FR::Payslip::PayslipV3Employment] attr_reader :employment # Information about paid time off. - # @return [Array] + # @return [Mindee::Product::FR::Payslip::PayslipV3PaidTimeOffs] attr_reader :paid_time_off # Detailed information about the pay. # @return [Mindee::Product::FR::Payslip::PayslipV3PayDetail] @@ -39,27 +39,39 @@ class PayslipV3Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Product::FR::Payslip::PayslipV3PayPeriod] attr_reader :pay_period # Detailed information about the earnings. - # @return [Array] + # @return [Mindee::Product::FR::Payslip::PayslipV3SalaryDetails] attr_reader :salary_details # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @bank_account_details = PayslipV3BankAccountDetail.new(prediction['bank_account_details'], page_id) - @employee = PayslipV3Employee.new(prediction['employee'], page_id) - @employer = PayslipV3Employer.new(prediction['employer'], page_id) - @employment = PayslipV3Employment.new(prediction['employment'], page_id) - @paid_time_off = [] - prediction['paid_time_off'].each do |item| - @paid_time_off.push(PayslipV3PaidTimeOff.new(item, page_id)) - end - @pay_detail = PayslipV3PayDetail.new(prediction['pay_detail'], page_id) - @pay_period = PayslipV3PayPeriod.new(prediction['pay_period'], page_id) - @salary_details = [] - prediction['salary_details'].each do |item| - @salary_details.push(PayslipV3SalaryDetail.new(item, page_id)) - end + super + @bank_account_details = Product::FR::Payslip::PayslipV3BankAccountDetail.new( + prediction['bank_account_details'], + page_id + ) + @employee = Product::FR::Payslip::PayslipV3Employee.new( + prediction['employee'], + page_id + ) + @employer = Product::FR::Payslip::PayslipV3Employer.new( + prediction['employer'], + page_id + ) + @employment = Product::FR::Payslip::PayslipV3Employment.new( + prediction['employment'], + page_id + ) + @paid_time_off = Product::FR::Payslip::PayslipV3PaidTimeOffs.new(prediction['paid_time_off'], page_id) + @pay_detail = Product::FR::Payslip::PayslipV3PayDetail.new( + prediction['pay_detail'], + page_id + ) + @pay_period = Product::FR::Payslip::PayslipV3PayPeriod.new( + prediction['pay_period'], + page_id + ) + @salary_details = Product::FR::Payslip::PayslipV3SalaryDetails.new(prediction['salary_details'], page_id) end # @return [String] diff --git a/lib/mindee/product/fr/payslip/payslip_v3_employee.rb b/lib/mindee/product/fr/payslip/payslip_v3_employee.rb index adf8d44c..698b5077 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_employee.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_employee.rb @@ -34,7 +34,7 @@ class PayslipV3Employee < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @address = prediction['address'] @date_of_birth = prediction['date_of_birth'] @first_name = prediction['first_name'] diff --git a/lib/mindee/product/fr/payslip/payslip_v3_employer.rb b/lib/mindee/product/fr/payslip/payslip_v3_employer.rb index f5f69f5b..62c640cd 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_employer.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_employer.rb @@ -34,7 +34,7 @@ class PayslipV3Employer < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @address = prediction['address'] @company_id = prediction['company_id'] @company_site = prediction['company_site'] diff --git a/lib/mindee/product/fr/payslip/payslip_v3_employment.rb b/lib/mindee/product/fr/payslip/payslip_v3_employment.rb index 53038fe2..e8ad90c8 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_employment.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_employment.rb @@ -34,7 +34,7 @@ class PayslipV3Employment < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @category = prediction['category'] @coefficient = prediction['coefficient'] @collective_agreement = prediction['collective_agreement'] diff --git a/lib/mindee/product/fr/payslip/payslip_v3_page.rb b/lib/mindee/product/fr/payslip/payslip_v3_page.rb index 4e41e9c1..cac295bf 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_page.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_page.rb @@ -11,11 +11,15 @@ module Payslip class PayslipV3Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = PayslipV3PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + PayslipV3PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/fr/payslip/payslip_v3_paid_time_off.rb b/lib/mindee/product/fr/payslip/payslip_v3_paid_time_off.rb index 82c605b7..ef2cfc40 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_paid_time_off.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_paid_time_off.rb @@ -28,7 +28,7 @@ class PayslipV3PaidTimeOff < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @accrued = prediction['accrued'] @period = prediction['period'] @pto_type = prediction['pto_type'] @@ -40,22 +40,28 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:accrued] = @accrued.nil? ? '' : Field.float_to_string(@accrued) + printable[:accrued] = + @accrued.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@accrued) printable[:period] = format_for_display(@period) printable[:pto_type] = format_for_display(@pto_type) - printable[:remaining] = @remaining.nil? ? '' : Field.float_to_string(@remaining) - printable[:used] = @used.nil? ? '' : Field.float_to_string(@used) + printable[:remaining] = + @remaining.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@remaining) + printable[:used] = + @used.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@used) printable end # @return [Hash] def table_printable_values printable = {} - printable[:accrued] = @accrued.nil? ? '' : Field.float_to_string(@accrued) + printable[:accrued] = + @accrued.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@accrued) printable[:period] = format_for_display(@period, 6) printable[:pto_type] = format_for_display(@pto_type, 11) - printable[:remaining] = @remaining.nil? ? '' : Field.float_to_string(@remaining) - printable[:used] = @used.nil? ? '' : Field.float_to_string(@used) + printable[:remaining] = + @remaining.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@remaining) + printable[:used] = + @used.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@used) printable end diff --git a/lib/mindee/product/fr/payslip/payslip_v3_paid_time_offs.rb b/lib/mindee/product/fr/payslip/payslip_v3_paid_time_offs.rb new file mode 100644 index 00000000..7cf36b86 --- /dev/null +++ b/lib/mindee/product/fr/payslip/payslip_v3_paid_time_offs.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require_relative 'payslip_v3_pay_period' +require_relative 'payslip_v3_employee' +require_relative 'payslip_v3_employer' +require_relative 'payslip_v3_bank_account_detail' +require_relative 'payslip_v3_employment' +require_relative 'payslip_v3_salary_detail' +require_relative 'payslip_v3_pay_detail' +require_relative 'payslip_v3_paid_time_off' + +module Mindee + module Product + module FR + module Payslip + # Information about paid time off. + class PayslipV3PaidTimeOffs < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + Payslip::PayslipV3PaidTimeOff.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 11}" + out_str << "+#{char * 8}" + out_str << "+#{char * 13}" + out_str << "+#{char * 11}" + out_str << "+#{char * 11}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Accrued ' + out_str << ' | Period' + out_str << ' | Type ' + out_str << ' | Remaining' + out_str << ' | Used ' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end + end +end diff --git a/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb b/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb index 430ace59..5d706add 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb @@ -43,7 +43,7 @@ class PayslipV3PayDetail < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @gross_salary = prediction['gross_salary'] @gross_salary_ytd = prediction['gross_salary_ytd'] @income_tax_rate = prediction['income_tax_rate'] @@ -60,20 +60,42 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:gross_salary] = @gross_salary.nil? ? '' : Field.float_to_string(@gross_salary) - printable[:gross_salary_ytd] = @gross_salary_ytd.nil? ? '' : Field.float_to_string(@gross_salary_ytd) - printable[:income_tax_rate] = @income_tax_rate.nil? ? '' : Field.float_to_string(@income_tax_rate) + printable[:gross_salary] = + @gross_salary.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@gross_salary) + printable[:gross_salary_ytd] = + @gross_salary_ytd.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@gross_salary_ytd) + printable[:income_tax_rate] = + @income_tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@income_tax_rate) printable[:income_tax_withheld] = - @income_tax_withheld.nil? ? '' : Field.float_to_string(@income_tax_withheld) - printable[:net_paid] = @net_paid.nil? ? '' : Field.float_to_string(@net_paid) + if @income_tax_withheld.nil? + '' + else + Parsing::Standard::BaseField.float_to_string(@income_tax_withheld) + end + printable[:net_paid] = + @net_paid.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@net_paid) printable[:net_paid_before_tax] = - @net_paid_before_tax.nil? ? '' : Field.float_to_string(@net_paid_before_tax) - printable[:net_taxable] = @net_taxable.nil? ? '' : Field.float_to_string(@net_taxable) - printable[:net_taxable_ytd] = @net_taxable_ytd.nil? ? '' : Field.float_to_string(@net_taxable_ytd) + if @net_paid_before_tax.nil? + '' + else + Parsing::Standard::BaseField.float_to_string(@net_paid_before_tax) + end + printable[:net_taxable] = + @net_taxable.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@net_taxable) + printable[:net_taxable_ytd] = + @net_taxable_ytd.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@net_taxable_ytd) printable[:total_cost_employer] = - @total_cost_employer.nil? ? '' : Field.float_to_string(@total_cost_employer) + if @total_cost_employer.nil? + '' + else + Parsing::Standard::BaseField.float_to_string(@total_cost_employer) + end printable[:total_taxes_and_deductions] = - @total_taxes_and_deductions.nil? ? '' : Field.float_to_string(@total_taxes_and_deductions) + if @total_taxes_and_deductions.nil? + '' + else + Parsing::Standard::BaseField.float_to_string(@total_taxes_and_deductions) + end printable end diff --git a/lib/mindee/product/fr/payslip/payslip_v3_pay_period.rb b/lib/mindee/product/fr/payslip/payslip_v3_pay_period.rb index 1665ab27..376fb9ef 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_pay_period.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_pay_period.rb @@ -28,7 +28,7 @@ class PayslipV3PayPeriod < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @end_date = prediction['end_date'] @month = prediction['month'] @payment_date = prediction['payment_date'] diff --git a/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb b/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb index 886b4810..5e4b9b71 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb @@ -28,7 +28,7 @@ class PayslipV3SalaryDetail < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @amount = prediction['amount'] @base = prediction['base'] @description = prediction['description'] @@ -40,22 +40,30 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount) - printable[:base] = @base.nil? ? '' : Field.float_to_string(@base) + printable[:amount] = + @amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@amount) + printable[:base] = + @base.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@base) printable[:description] = format_for_display(@description) - printable[:number] = @number.nil? ? '' : Field.float_to_string(@number) - printable[:rate] = @rate.nil? ? '' : Field.float_to_string(@rate) + printable[:number] = + @number.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@number) + printable[:rate] = + @rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@rate) printable end # @return [Hash] def table_printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount) - printable[:base] = @base.nil? ? '' : Field.float_to_string(@base) + printable[:amount] = + @amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@amount) + printable[:base] = + @base.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@base) printable[:description] = format_for_display(@description, 36) - printable[:number] = @number.nil? ? '' : Field.float_to_string(@number) - printable[:rate] = @rate.nil? ? '' : Field.float_to_string(@rate) + printable[:number] = + @number.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@number) + printable[:rate] = + @rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@rate) printable end diff --git a/lib/mindee/product/fr/payslip/payslip_v3_salary_details.rb b/lib/mindee/product/fr/payslip/payslip_v3_salary_details.rb new file mode 100644 index 00000000..c32d254d --- /dev/null +++ b/lib/mindee/product/fr/payslip/payslip_v3_salary_details.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require_relative 'payslip_v3_pay_period' +require_relative 'payslip_v3_employee' +require_relative 'payslip_v3_employer' +require_relative 'payslip_v3_bank_account_detail' +require_relative 'payslip_v3_employment' +require_relative 'payslip_v3_salary_detail' +require_relative 'payslip_v3_pay_detail' +require_relative 'payslip_v3_paid_time_off' + +module Mindee + module Product + module FR + module Payslip + # Detailed information about the earnings. + class PayslipV3SalaryDetails < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + Payslip::PayslipV3SalaryDetail.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 14}" + out_str << "+#{char * 11}" + out_str << "+#{char * 38}" + out_str << "+#{char * 8}" + out_str << "+#{char * 11}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Amount ' + out_str << ' | Base ' + out_str << ' | Description ' + out_str << ' | Number' + out_str << ' | Rate ' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end + end +end diff --git a/lib/mindee/product/generated/generated_v1.rb b/lib/mindee/product/generated/generated_v1.rb deleted file mode 100644 index fd8bb242..00000000 --- a/lib/mindee/product/generated/generated_v1.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require_relative 'generated_v1_document' -require_relative 'generated_v1_page' - -module Mindee - module Product - # Generated product module. - module Generated - # Generated Document V1 prediction inference. - class GeneratedV1 < Mindee::Parsing::Common::Inference - @endpoint_name = '' - @endpoint_version = '' - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = GeneratedV1Document.new(prediction['prediction']) - @pages = [] - prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(GeneratedV1Page.new(page)) - end - end - end - - class << self - # Name of the endpoint for this product. - # @return [String] - attr_reader :endpoint_name - # Version for this product. - # @return [String] - attr_reader :endpoint_version - end - end - end - end -end diff --git a/lib/mindee/product/generated/generated_v1_document.rb b/lib/mindee/product/generated/generated_v1_document.rb deleted file mode 100644 index 1f4d15af..00000000 --- a/lib/mindee/product/generated/generated_v1_document.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../parsing' -require_relative 'generated_v1_prediction' - -module Mindee - module Product - module Generated - # Generated Document V1 prediction - class GeneratedV1Document < Mindee::Product::Generated::GeneratedV1Prediction - include Mindee::Parsing::Standard - # @param raw_prediction [Hash] - def initialize(raw_prediction) - # Generated document. - - # raw_prediction: Dictionary containing the JSON document response - super() - raw_prediction.each do |field_name, field_contents| - if field_contents.is_a?(Array) - @fields[field_name] = Parsing::Generated::GeneratedListField.new(field_contents) - elsif field_contents.is_a?(Hash) && Parsing::Generated.generated_object?(field_contents) - @fields[field_name] = Parsing::Generated::GeneratedObjectField.new(field_contents) - else - field_contents_str = field_contents.dup - if field_contents_str.key?('value') && field_contents_str['value'].nil? == false - field_contents_str['value'] = field_contents_str['value'].to_s - end - @fields[field_name] = StringField.new(field_contents_str) - end - end - end - end - end - end -end diff --git a/lib/mindee/product/ind/indian_passport/indian_passport_v1.rb b/lib/mindee/product/ind/indian_passport/indian_passport_v1.rb index 3c33bb82..48689564 100644 --- a/lib/mindee/product/ind/indian_passport/indian_passport_v1.rb +++ b/lib/mindee/product/ind/indian_passport/indian_passport_v1.rb @@ -13,6 +13,8 @@ module IndianPassport class IndianPassportV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'ind_passport' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = IndianPassportV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(IndianPassportV1Page.new(page)) - end + @pages.push(IndianPassportV1Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/ind/indian_passport/indian_passport_v1_document.rb b/lib/mindee/product/ind/indian_passport/indian_passport_v1_document.rb index dab3feab..dea40ba1 100644 --- a/lib/mindee/product/ind/indian_passport/indian_passport_v1_document.rb +++ b/lib/mindee/product/ind/indian_passport/indian_passport_v1_document.rb @@ -82,30 +82,93 @@ class IndianPassportV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @address1 = StringField.new(prediction['address1'], page_id) - @address2 = StringField.new(prediction['address2'], page_id) - @address3 = StringField.new(prediction['address3'], page_id) - @birth_date = DateField.new(prediction['birth_date'], page_id) - @birth_place = StringField.new(prediction['birth_place'], page_id) - @country = StringField.new(prediction['country'], page_id) - @expiry_date = DateField.new(prediction['expiry_date'], page_id) - @file_number = StringField.new(prediction['file_number'], page_id) - @gender = ClassificationField.new(prediction['gender'], page_id) - @given_names = StringField.new(prediction['given_names'], page_id) - @id_number = StringField.new(prediction['id_number'], page_id) - @issuance_date = DateField.new(prediction['issuance_date'], page_id) - @issuance_place = StringField.new(prediction['issuance_place'], page_id) - @legal_guardian = StringField.new(prediction['legal_guardian'], page_id) - @mrz1 = StringField.new(prediction['mrz1'], page_id) - @mrz2 = StringField.new(prediction['mrz2'], page_id) - @name_of_mother = StringField.new(prediction['name_of_mother'], page_id) - @name_of_spouse = StringField.new(prediction['name_of_spouse'], page_id) - @old_passport_date_of_issue = DateField.new(prediction['old_passport_date_of_issue'], page_id) - @old_passport_number = StringField.new(prediction['old_passport_number'], page_id) - @old_passport_place_of_issue = StringField.new(prediction['old_passport_place_of_issue'], page_id) - @page_number = ClassificationField.new(prediction['page_number'], page_id) - @surname = StringField.new(prediction['surname'], page_id) + super + @address1 = Parsing::Standard::StringField.new( + prediction['address1'], + page_id + ) + @address2 = Parsing::Standard::StringField.new( + prediction['address2'], + page_id + ) + @address3 = Parsing::Standard::StringField.new( + prediction['address3'], + page_id + ) + @birth_date = Parsing::Standard::DateField.new( + prediction['birth_date'], + page_id + ) + @birth_place = Parsing::Standard::StringField.new( + prediction['birth_place'], + page_id + ) + @country = Parsing::Standard::StringField.new( + prediction['country'], + page_id + ) + @expiry_date = Parsing::Standard::DateField.new( + prediction['expiry_date'], + page_id + ) + @file_number = Parsing::Standard::StringField.new( + prediction['file_number'], + page_id + ) + @gender = Parsing::Standard::ClassificationField.new( + prediction['gender'], + page_id + ) + @given_names = Parsing::Standard::StringField.new( + prediction['given_names'], + page_id + ) + @id_number = Parsing::Standard::StringField.new( + prediction['id_number'], + page_id + ) + @issuance_date = Parsing::Standard::DateField.new( + prediction['issuance_date'], + page_id + ) + @issuance_place = Parsing::Standard::StringField.new( + prediction['issuance_place'], + page_id + ) + @legal_guardian = Parsing::Standard::StringField.new( + prediction['legal_guardian'], + page_id + ) + @mrz1 = Parsing::Standard::StringField.new(prediction['mrz1'], page_id) + @mrz2 = Parsing::Standard::StringField.new(prediction['mrz2'], page_id) + @name_of_mother = Parsing::Standard::StringField.new( + prediction['name_of_mother'], + page_id + ) + @name_of_spouse = Parsing::Standard::StringField.new( + prediction['name_of_spouse'], + page_id + ) + @old_passport_date_of_issue = Parsing::Standard::DateField.new( + prediction['old_passport_date_of_issue'], + page_id + ) + @old_passport_number = Parsing::Standard::StringField.new( + prediction['old_passport_number'], + page_id + ) + @old_passport_place_of_issue = Parsing::Standard::StringField.new( + prediction['old_passport_place_of_issue'], + page_id + ) + @page_number = Parsing::Standard::ClassificationField.new( + prediction['page_number'], + page_id + ) + @surname = Parsing::Standard::StringField.new( + prediction['surname'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/ind/indian_passport/indian_passport_v1_page.rb b/lib/mindee/product/ind/indian_passport/indian_passport_v1_page.rb index adfc05bc..77b1faa6 100644 --- a/lib/mindee/product/ind/indian_passport/indian_passport_v1_page.rb +++ b/lib/mindee/product/ind/indian_passport/indian_passport_v1_page.rb @@ -11,11 +11,15 @@ module IndianPassport class IndianPassportV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = IndianPassportV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + IndianPassportV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/international_id/international_id_v2.rb b/lib/mindee/product/international_id/international_id_v2.rb index 7c0521cf..290b9435 100644 --- a/lib/mindee/product/international_id/international_id_v2.rb +++ b/lib/mindee/product/international_id/international_id_v2.rb @@ -12,6 +12,8 @@ module InternationalId class InternationalIdV2 < Mindee::Parsing::Common::Inference @endpoint_name = 'international_id' @endpoint_version = '2' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = InternationalIdV2Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(InternationalIdV2Page.new(page)) - end + @pages.push(InternationalIdV2Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/international_id/international_id_v2_document.rb b/lib/mindee/product/international_id/international_id_v2_document.rb index 1a4d24fe..d7e56328 100644 --- a/lib/mindee/product/international_id/international_id_v2_document.rb +++ b/lib/mindee/product/international_id/international_id_v2_document.rb @@ -63,29 +63,71 @@ class InternationalIdV2Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @address = StringField.new(prediction['address'], page_id) - @birth_date = DateField.new(prediction['birth_date'], page_id) - @birth_place = StringField.new(prediction['birth_place'], page_id) - @country_of_issue = StringField.new(prediction['country_of_issue'], page_id) - @document_number = StringField.new(prediction['document_number'], page_id) - @document_type = ClassificationField.new(prediction['document_type'], page_id) - @expiry_date = DateField.new(prediction['expiry_date'], page_id) - @given_names = [] + super + @address = Parsing::Standard::StringField.new( + prediction['address'], + page_id + ) + @birth_date = Parsing::Standard::DateField.new( + prediction['birth_date'], + page_id + ) + @birth_place = Parsing::Standard::StringField.new( + prediction['birth_place'], + page_id + ) + @country_of_issue = Parsing::Standard::StringField.new( + prediction['country_of_issue'], + page_id + ) + @document_number = Parsing::Standard::StringField.new( + prediction['document_number'], + page_id + ) + @document_type = Parsing::Standard::ClassificationField.new( + prediction['document_type'], + page_id + ) + @expiry_date = Parsing::Standard::DateField.new( + prediction['expiry_date'], + page_id + ) + @given_names = [] # : Array[Parsing::Standard::StringField] prediction['given_names'].each do |item| - @given_names.push(StringField.new(item, page_id)) + @given_names.push(Parsing::Standard::StringField.new(item, page_id)) end - @issue_date = DateField.new(prediction['issue_date'], page_id) - @mrz_line1 = StringField.new(prediction['mrz_line1'], page_id) - @mrz_line2 = StringField.new(prediction['mrz_line2'], page_id) - @mrz_line3 = StringField.new(prediction['mrz_line3'], page_id) - @nationality = StringField.new(prediction['nationality'], page_id) - @personal_number = StringField.new(prediction['personal_number'], page_id) - @sex = StringField.new(prediction['sex'], page_id) - @state_of_issue = StringField.new(prediction['state_of_issue'], page_id) - @surnames = [] + @issue_date = Parsing::Standard::DateField.new( + prediction['issue_date'], + page_id + ) + @mrz_line1 = Parsing::Standard::StringField.new( + prediction['mrz_line1'], + page_id + ) + @mrz_line2 = Parsing::Standard::StringField.new( + prediction['mrz_line2'], + page_id + ) + @mrz_line3 = Parsing::Standard::StringField.new( + prediction['mrz_line3'], + page_id + ) + @nationality = Parsing::Standard::StringField.new( + prediction['nationality'], + page_id + ) + @personal_number = Parsing::Standard::StringField.new( + prediction['personal_number'], + page_id + ) + @sex = Parsing::Standard::StringField.new(prediction['sex'], page_id) + @state_of_issue = Parsing::Standard::StringField.new( + prediction['state_of_issue'], + page_id + ) + @surnames = [] # : Array[Parsing::Standard::StringField] prediction['surnames'].each do |item| - @surnames.push(StringField.new(item, page_id)) + @surnames.push(Parsing::Standard::StringField.new(item, page_id)) end end diff --git a/lib/mindee/product/international_id/international_id_v2_page.rb b/lib/mindee/product/international_id/international_id_v2_page.rb index 08659cb8..d958db90 100644 --- a/lib/mindee/product/international_id/international_id_v2_page.rb +++ b/lib/mindee/product/international_id/international_id_v2_page.rb @@ -10,11 +10,15 @@ module InternationalId class InternationalIdV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = InternationalIdV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + InternationalIdV2PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/invoice/invoice_v4.rb b/lib/mindee/product/invoice/invoice_v4.rb index 51d36c9b..edf101dd 100644 --- a/lib/mindee/product/invoice/invoice_v4.rb +++ b/lib/mindee/product/invoice/invoice_v4.rb @@ -12,6 +12,8 @@ module Invoice class InvoiceV4 < Mindee::Parsing::Common::Inference @endpoint_name = 'invoices' @endpoint_version = '4' + @has_async = true + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = InvoiceV4Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(InvoiceV4Page.new(page)) - end + @pages.push(InvoiceV4Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/invoice/invoice_v4_document.rb b/lib/mindee/product/invoice/invoice_v4_document.rb index 31b8e0b9..f4f60c46 100644 --- a/lib/mindee/product/invoice/invoice_v4_document.rb +++ b/lib/mindee/product/invoice/invoice_v4_document.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../../parsing' -require_relative 'invoice_v4_line_item' +require_relative 'invoice_v4_line_items' module Mindee module Product @@ -37,7 +37,7 @@ class InvoiceV4Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Parsing::Standard::StringField] attr_reader :invoice_number # List of line item details. - # @return [Array] + # @return [Mindee::Product::Invoice::InvoiceV4LineItems] attr_reader :line_items # The locale detected on the document. # @return [Mindee::Parsing::Standard::LocaleField] @@ -91,48 +91,102 @@ class InvoiceV4Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @billing_address = StringField.new(prediction['billing_address'], page_id) - @customer_address = StringField.new(prediction['customer_address'], page_id) - @customer_company_registrations = [] + super + @billing_address = Parsing::Standard::StringField.new( + prediction['billing_address'], + page_id + ) + @customer_address = Parsing::Standard::StringField.new( + prediction['customer_address'], + page_id + ) + @customer_company_registrations = [] # : Array[Parsing::Standard::CompanyRegistrationField] prediction['customer_company_registrations'].each do |item| - @customer_company_registrations.push(CompanyRegistrationField.new(item, page_id)) + @customer_company_registrations.push(Parsing::Standard::CompanyRegistrationField.new(item, page_id)) end - @customer_id = StringField.new(prediction['customer_id'], page_id) - @customer_name = StringField.new(prediction['customer_name'], page_id) - @date = DateField.new(prediction['date'], page_id) - @document_type = ClassificationField.new(prediction['document_type'], page_id) - @due_date = DateField.new(prediction['due_date'], page_id) - @invoice_number = StringField.new(prediction['invoice_number'], page_id) - @line_items = [] - prediction['line_items'].each do |item| - @line_items.push(InvoiceV4LineItem.new(item, page_id)) - end - @locale = LocaleField.new(prediction['locale'], page_id) - @payment_date = DateField.new(prediction['payment_date'], page_id) - @po_number = StringField.new(prediction['po_number'], page_id) - @reference_numbers = [] + @customer_id = Parsing::Standard::StringField.new( + prediction['customer_id'], + page_id + ) + @customer_name = Parsing::Standard::StringField.new( + prediction['customer_name'], + page_id + ) + @date = Parsing::Standard::DateField.new(prediction['date'], page_id) + @document_type = Parsing::Standard::ClassificationField.new( + prediction['document_type'], + page_id + ) + @due_date = Parsing::Standard::DateField.new( + prediction['due_date'], + page_id + ) + @invoice_number = Parsing::Standard::StringField.new( + prediction['invoice_number'], + page_id + ) + @line_items = Product::Invoice::InvoiceV4LineItems.new(prediction['line_items'], page_id) + @locale = Parsing::Standard::LocaleField.new( + prediction['locale'], + page_id + ) + @payment_date = Parsing::Standard::DateField.new( + prediction['payment_date'], + page_id + ) + @po_number = Parsing::Standard::StringField.new( + prediction['po_number'], + page_id + ) + @reference_numbers = [] # : Array[Parsing::Standard::StringField] prediction['reference_numbers'].each do |item| - @reference_numbers.push(StringField.new(item, page_id)) + @reference_numbers.push(Parsing::Standard::StringField.new(item, page_id)) end - @shipping_address = StringField.new(prediction['shipping_address'], page_id) - @supplier_address = StringField.new(prediction['supplier_address'], page_id) - @supplier_company_registrations = [] + @shipping_address = Parsing::Standard::StringField.new( + prediction['shipping_address'], + page_id + ) + @supplier_address = Parsing::Standard::StringField.new( + prediction['supplier_address'], + page_id + ) + @supplier_company_registrations = [] # : Array[Parsing::Standard::CompanyRegistrationField] prediction['supplier_company_registrations'].each do |item| - @supplier_company_registrations.push(CompanyRegistrationField.new(item, page_id)) + @supplier_company_registrations.push(Parsing::Standard::CompanyRegistrationField.new(item, page_id)) end - @supplier_email = StringField.new(prediction['supplier_email'], page_id) - @supplier_name = StringField.new(prediction['supplier_name'], page_id) - @supplier_payment_details = [] + @supplier_email = Parsing::Standard::StringField.new( + prediction['supplier_email'], + page_id + ) + @supplier_name = Parsing::Standard::StringField.new( + prediction['supplier_name'], + page_id + ) + @supplier_payment_details = [] # : Array[Parsing::Standard::PaymentDetailsField] prediction['supplier_payment_details'].each do |item| - @supplier_payment_details.push(PaymentDetailsField.new(item, page_id)) + @supplier_payment_details.push(Parsing::Standard::PaymentDetailsField.new(item, page_id)) end - @supplier_phone_number = StringField.new(prediction['supplier_phone_number'], page_id) - @supplier_website = StringField.new(prediction['supplier_website'], page_id) - @taxes = Taxes.new(prediction['taxes'], page_id) - @total_amount = AmountField.new(prediction['total_amount'], page_id) - @total_net = AmountField.new(prediction['total_net'], page_id) - @total_tax = AmountField.new(prediction['total_tax'], page_id) + @supplier_phone_number = Parsing::Standard::StringField.new( + prediction['supplier_phone_number'], + page_id + ) + @supplier_website = Parsing::Standard::StringField.new( + prediction['supplier_website'], + page_id + ) + @taxes = Parsing::Standard::Taxes.new(prediction['taxes'], page_id) + @total_amount = Parsing::Standard::AmountField.new( + prediction['total_amount'], + page_id + ) + @total_net = Parsing::Standard::AmountField.new( + prediction['total_net'], + page_id + ) + @total_tax = Parsing::Standard::AmountField.new( + prediction['total_tax'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/invoice/invoice_v4_line_item.rb b/lib/mindee/product/invoice/invoice_v4_line_item.rb index 52870518..5c72964d 100644 --- a/lib/mindee/product/invoice/invoice_v4_line_item.rb +++ b/lib/mindee/product/invoice/invoice_v4_line_item.rb @@ -36,7 +36,7 @@ class InvoiceV4LineItem < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @description = prediction['description'] @product_code = prediction['product_code'] @quantity = prediction['quantity'] @@ -53,12 +53,17 @@ def printable_values printable = {} printable[:description] = format_for_display(@description) printable[:product_code] = format_for_display(@product_code) - printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity) - printable[:tax_amount] = @tax_amount.nil? ? '' : Field.float_to_string(@tax_amount) - printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate) - printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount) + printable[:quantity] = + @quantity.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@quantity) + printable[:tax_amount] = + @tax_amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_amount) + printable[:tax_rate] = + @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate) + printable[:total_amount] = + @total_amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total_amount) printable[:unit_measure] = format_for_display(@unit_measure) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end @@ -67,12 +72,17 @@ def table_printable_values printable = {} printable[:description] = format_for_display(@description, 36) printable[:product_code] = format_for_display(@product_code, nil) - printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity) - printable[:tax_amount] = @tax_amount.nil? ? '' : Field.float_to_string(@tax_amount) - printable[:tax_rate] = @tax_rate.nil? ? '' : Field.float_to_string(@tax_rate) - printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount) + printable[:quantity] = + @quantity.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@quantity) + printable[:tax_amount] = + @tax_amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_amount) + printable[:tax_rate] = + @tax_rate.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@tax_rate) + printable[:total_amount] = + @total_amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total_amount) printable[:unit_measure] = format_for_display(@unit_measure, nil) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end diff --git a/lib/mindee/product/invoice/invoice_v4_line_items.rb b/lib/mindee/product/invoice/invoice_v4_line_items.rb new file mode 100644 index 00000000..9d4ade36 --- /dev/null +++ b/lib/mindee/product/invoice/invoice_v4_line_items.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require_relative 'invoice_v4_line_item' + +module Mindee + module Product + module Invoice + # List of line item details. + class InvoiceV4LineItems < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + Invoice::InvoiceV4LineItem.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 38}" + out_str << "+#{char * 14}" + out_str << "+#{char * 10}" + out_str << "+#{char * 12}" + out_str << "+#{char * 14}" + out_str << "+#{char * 14}" + out_str << "+#{char * 17}" + out_str << "+#{char * 12}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Description ' + out_str << ' | Product code' + out_str << ' | Quantity' + out_str << ' | Tax Amount' + out_str << ' | Tax Rate (%)' + out_str << ' | Total Amount' + out_str << ' | Unit of measure' + out_str << ' | Unit Price' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end +end diff --git a/lib/mindee/product/invoice/invoice_v4_page.rb b/lib/mindee/product/invoice/invoice_v4_page.rb index 438975e3..f8f33616 100644 --- a/lib/mindee/product/invoice/invoice_v4_page.rb +++ b/lib/mindee/product/invoice/invoice_v4_page.rb @@ -10,11 +10,15 @@ module Invoice class InvoiceV4Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = InvoiceV4PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + InvoiceV4PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb b/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb index 1cd3dcff..893e49a1 100644 --- a/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb +++ b/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb @@ -12,6 +12,8 @@ module InvoiceSplitter class InvoiceSplitterV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'invoice_splitter' @endpoint_version = '1' + @has_sync = false + @has_async = true # @param prediction [Hash] def initialize(prediction) @@ -30,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb b/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb index 0d974eae..a7544984 100644 --- a/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +++ b/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb @@ -34,8 +34,8 @@ class InvoiceSplitterV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param _page_id [Integer, nil] - def initialize(prediction, _page_id) - super() + def initialize(prediction, _page_id = nil) + super(prediction, nil) construct_invoice_page_groups_from_prediction(prediction) end diff --git a/lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb b/lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb index 5bd1a1d8..896ec109 100644 --- a/lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb +++ b/lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb @@ -10,7 +10,7 @@ module InvoiceSplitter class InvoiceSplitterV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = InvoiceSplitterV1PagePrediction.new( prediction['prediction'], prediction['id'] diff --git a/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rb b/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rb index 292713ac..46bfce45 100644 --- a/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rb +++ b/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rb @@ -12,6 +12,8 @@ module MultiReceiptsDetector class MultiReceiptsDetectorV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'multi_receipts_detector' @endpoint_version = '1' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = MultiReceiptsDetectorV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(MultiReceiptsDetectorV1Page.new(page)) - end + @pages.push(MultiReceiptsDetectorV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb b/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb index 66437d6d..372b2b71 100644 --- a/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb +++ b/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb @@ -15,10 +15,10 @@ class MultiReceiptsDetectorV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @receipts = [] + super + @receipts = [] # : Array[Parsing::Standard::PositionField] prediction['receipts'].each do |item| - @receipts.push(PositionField.new(item, page_id)) + @receipts.push(Parsing::Standard::PositionField.new(item, page_id)) end end diff --git a/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb b/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb index cc34aac9..cb5d7568 100644 --- a/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb +++ b/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb @@ -10,11 +10,15 @@ module MultiReceiptsDetector class MultiReceiptsDetectorV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = MultiReceiptsDetectorV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + MultiReceiptsDetectorV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rb index 1c1218da..2cdc8cd1 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rb @@ -12,6 +12,8 @@ module NutritionFactsLabel class NutritionFactsLabelV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'nutrition_facts' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = NutritionFactsLabelV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(NutritionFactsLabelV1Page.new(page)) - end + @pages.push(NutritionFactsLabelV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rb index 33648e3b..af705dbc 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rb @@ -21,7 +21,7 @@ class NutritionFactsLabelV1AddedSugar < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rb index 5b0f022b..e956fbe8 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rb @@ -21,7 +21,7 @@ class NutritionFactsLabelV1Calorie < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rb index ff6283ad..b787fbbd 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rb @@ -21,7 +21,7 @@ class NutritionFactsLabelV1Cholesterol < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rb index c1fa5954..5eeaebc1 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rb @@ -21,7 +21,7 @@ class NutritionFactsLabelV1DietaryFiber < Mindee::Parsing::Standard::FeatureFiel # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb index 8a6605ee..07c466d5 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb @@ -13,7 +13,7 @@ require_relative 'nutrition_facts_label_v1_added_sugar' require_relative 'nutrition_facts_label_v1_protein' require_relative 'nutrition_facts_label_v1_sodium' -require_relative 'nutrition_facts_label_v1_nutrient' +require_relative 'nutrition_facts_label_v1_nutrients' module Mindee module Product @@ -34,7 +34,7 @@ class NutritionFactsLabelV1Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1DietaryFiber] attr_reader :dietary_fiber # The amount of nutrients in the product. - # @return [Array] + # @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrients] attr_reader :nutrients # The amount of protein in the product. # @return [Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1Protein] @@ -67,24 +67,62 @@ class NutritionFactsLabelV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @added_sugars = NutritionFactsLabelV1AddedSugar.new(prediction['added_sugars'], page_id) - @calories = NutritionFactsLabelV1Calorie.new(prediction['calories'], page_id) - @cholesterol = NutritionFactsLabelV1Cholesterol.new(prediction['cholesterol'], page_id) - @dietary_fiber = NutritionFactsLabelV1DietaryFiber.new(prediction['dietary_fiber'], page_id) - @nutrients = [] - prediction['nutrients'].each do |item| - @nutrients.push(NutritionFactsLabelV1Nutrient.new(item, page_id)) - end - @protein = NutritionFactsLabelV1Protein.new(prediction['protein'], page_id) - @saturated_fat = NutritionFactsLabelV1SaturatedFat.new(prediction['saturated_fat'], page_id) - @serving_per_box = AmountField.new(prediction['serving_per_box'], page_id) - @serving_size = NutritionFactsLabelV1ServingSize.new(prediction['serving_size'], page_id) - @sodium = NutritionFactsLabelV1Sodium.new(prediction['sodium'], page_id) - @total_carbohydrate = NutritionFactsLabelV1TotalCarbohydrate.new(prediction['total_carbohydrate'], page_id) - @total_fat = NutritionFactsLabelV1TotalFat.new(prediction['total_fat'], page_id) - @total_sugars = NutritionFactsLabelV1TotalSugar.new(prediction['total_sugars'], page_id) - @trans_fat = NutritionFactsLabelV1TransFat.new(prediction['trans_fat'], page_id) + super + @added_sugars = Product::NutritionFactsLabel::NutritionFactsLabelV1AddedSugar.new( + prediction['added_sugars'], + page_id + ) + @calories = Product::NutritionFactsLabel::NutritionFactsLabelV1Calorie.new( + prediction['calories'], + page_id + ) + @cholesterol = Product::NutritionFactsLabel::NutritionFactsLabelV1Cholesterol.new( + prediction['cholesterol'], + page_id + ) + @dietary_fiber = Product::NutritionFactsLabel::NutritionFactsLabelV1DietaryFiber.new( + prediction['dietary_fiber'], + page_id + ) + @nutrients = Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrients.new( + prediction['nutrients'], page_id + ) + @protein = Product::NutritionFactsLabel::NutritionFactsLabelV1Protein.new( + prediction['protein'], + page_id + ) + @saturated_fat = Product::NutritionFactsLabel::NutritionFactsLabelV1SaturatedFat.new( + prediction['saturated_fat'], + page_id + ) + @serving_per_box = Parsing::Standard::AmountField.new( + prediction['serving_per_box'], + page_id + ) + @serving_size = Product::NutritionFactsLabel::NutritionFactsLabelV1ServingSize.new( + prediction['serving_size'], + page_id + ) + @sodium = Product::NutritionFactsLabel::NutritionFactsLabelV1Sodium.new( + prediction['sodium'], + page_id + ) + @total_carbohydrate = Product::NutritionFactsLabel::NutritionFactsLabelV1TotalCarbohydrate.new( + prediction['total_carbohydrate'], + page_id + ) + @total_fat = Product::NutritionFactsLabel::NutritionFactsLabelV1TotalFat.new( + prediction['total_fat'], + page_id + ) + @total_sugars = Product::NutritionFactsLabel::NutritionFactsLabelV1TotalSugar.new( + prediction['total_sugars'], + page_id + ) + @trans_fat = Product::NutritionFactsLabel::NutritionFactsLabelV1TransFat.new( + prediction['trans_fat'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb index 7aaa3801..cadc0aaa 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb @@ -27,7 +27,7 @@ class NutritionFactsLabelV1Nutrient < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @name = prediction['name'] @per_100g = prediction['per_100g'] @@ -39,10 +39,13 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) printable[:name] = format_for_display(@name) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable[:unit] = format_for_display(@unit) printable end @@ -50,10 +53,13 @@ def printable_values # @return [Hash] def table_printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) printable[:name] = format_for_display(@name, 20) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable[:unit] = format_for_display(@unit, nil) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rb new file mode 100644 index 00000000..5479e461 --- /dev/null +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require_relative 'nutrition_facts_label_v1_serving_size' +require_relative 'nutrition_facts_label_v1_calorie' +require_relative 'nutrition_facts_label_v1_total_fat' +require_relative 'nutrition_facts_label_v1_saturated_fat' +require_relative 'nutrition_facts_label_v1_trans_fat' +require_relative 'nutrition_facts_label_v1_cholesterol' +require_relative 'nutrition_facts_label_v1_total_carbohydrate' +require_relative 'nutrition_facts_label_v1_dietary_fiber' +require_relative 'nutrition_facts_label_v1_total_sugar' +require_relative 'nutrition_facts_label_v1_added_sugar' +require_relative 'nutrition_facts_label_v1_protein' +require_relative 'nutrition_facts_label_v1_sodium' +require_relative 'nutrition_facts_label_v1_nutrient' + +module Mindee + module Product + module NutritionFactsLabel + # The amount of nutrients in the product. + class NutritionFactsLabelV1Nutrients < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + NutritionFactsLabel::NutritionFactsLabelV1Nutrient.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 13}" + out_str << "+#{char * 22}" + out_str << "+#{char * 10}" + out_str << "+#{char * 13}" + out_str << "+#{char * 6}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Daily Value' + out_str << ' | Name ' + out_str << ' | Per 100g' + out_str << ' | Per Serving' + out_str << ' | Unit' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end +end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rb index 1a20991f..5253ada9 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rb @@ -10,11 +10,15 @@ module NutritionFactsLabel class NutritionFactsLabelV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = NutritionFactsLabelV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + NutritionFactsLabelV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rb index a09b3634..c6431683 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rb @@ -21,7 +21,7 @@ class NutritionFactsLabelV1Protein < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rb index a569fbe5..d6a5cd3a 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rb @@ -21,7 +21,7 @@ class NutritionFactsLabelV1SaturatedFat < Mindee::Parsing::Standard::FeatureFiel # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb index fd42b461..0796094f 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb @@ -18,7 +18,7 @@ class NutritionFactsLabelV1ServingSize < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @amount = prediction['amount'] @unit = prediction['unit'] @page_id = page_id @@ -27,7 +27,8 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount) + printable[:amount] = + @amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@amount) printable[:unit] = format_for_display(@unit) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rb index 5e1bae93..def207dc 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rb @@ -24,7 +24,7 @@ class NutritionFactsLabelV1Sodium < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -35,9 +35,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable[:unit] = format_for_display(@unit) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rb index dd591941..da21b79b 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rb @@ -21,7 +21,7 @@ class NutritionFactsLabelV1TotalCarbohydrate < Mindee::Parsing::Standard::Featur # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rb index 8fadb7d1..ba9732fc 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rb @@ -21,7 +21,7 @@ class NutritionFactsLabelV1TotalFat < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rb index ea106b88..e7cde52c 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rb @@ -21,7 +21,7 @@ class NutritionFactsLabelV1TotalSugar < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rb index 0eb0700c..9f4d00be 100644 --- a/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rb +++ b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rb @@ -21,7 +21,7 @@ class NutritionFactsLabelV1TransFat < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @daily_value = prediction['daily_value'] @per_100g = prediction['per_100g'] @per_serving = prediction['per_serving'] @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : Field.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : Field.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : Field.float_to_string(@per_serving) + printable[:daily_value] = + @daily_value.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@daily_value) + printable[:per_100g] = + @per_100g.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_100g) + printable[:per_serving] = + @per_serving.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/passport/passport_v1.rb b/lib/mindee/product/passport/passport_v1.rb index e3cc942c..37802934 100644 --- a/lib/mindee/product/passport/passport_v1.rb +++ b/lib/mindee/product/passport/passport_v1.rb @@ -12,6 +12,8 @@ module Passport class PassportV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'passport' @endpoint_version = '1' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = PassportV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(PassportV1Page.new(page)) - end + @pages.push(PassportV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/passport/passport_v1_document.rb b/lib/mindee/product/passport/passport_v1_document.rb index 5de4c473..0d4f2d88 100644 --- a/lib/mindee/product/passport/passport_v1_document.rb +++ b/lib/mindee/product/passport/passport_v1_document.rb @@ -45,21 +45,45 @@ class PassportV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @birth_date = DateField.new(prediction['birth_date'], page_id) - @birth_place = StringField.new(prediction['birth_place'], page_id) - @country = StringField.new(prediction['country'], page_id) - @expiry_date = DateField.new(prediction['expiry_date'], page_id) - @gender = StringField.new(prediction['gender'], page_id) - @given_names = [] + super + @birth_date = Parsing::Standard::DateField.new( + prediction['birth_date'], + page_id + ) + @birth_place = Parsing::Standard::StringField.new( + prediction['birth_place'], + page_id + ) + @country = Parsing::Standard::StringField.new( + prediction['country'], + page_id + ) + @expiry_date = Parsing::Standard::DateField.new( + prediction['expiry_date'], + page_id + ) + @gender = Parsing::Standard::StringField.new( + prediction['gender'], + page_id + ) + @given_names = [] # : Array[Parsing::Standard::StringField] prediction['given_names'].each do |item| - @given_names.push(StringField.new(item, page_id)) + @given_names.push(Parsing::Standard::StringField.new(item, page_id)) end - @id_number = StringField.new(prediction['id_number'], page_id) - @issuance_date = DateField.new(prediction['issuance_date'], page_id) - @mrz1 = StringField.new(prediction['mrz1'], page_id) - @mrz2 = StringField.new(prediction['mrz2'], page_id) - @surname = StringField.new(prediction['surname'], page_id) + @id_number = Parsing::Standard::StringField.new( + prediction['id_number'], + page_id + ) + @issuance_date = Parsing::Standard::DateField.new( + prediction['issuance_date'], + page_id + ) + @mrz1 = Parsing::Standard::StringField.new(prediction['mrz1'], page_id) + @mrz2 = Parsing::Standard::StringField.new(prediction['mrz2'], page_id) + @surname = Parsing::Standard::StringField.new( + prediction['surname'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/passport/passport_v1_page.rb b/lib/mindee/product/passport/passport_v1_page.rb index f42118f6..5816f85b 100644 --- a/lib/mindee/product/passport/passport_v1_page.rb +++ b/lib/mindee/product/passport/passport_v1_page.rb @@ -10,11 +10,15 @@ module Passport class PassportV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = PassportV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + PassportV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/proof_of_address/proof_of_address_v1.rb b/lib/mindee/product/proof_of_address/proof_of_address_v1.rb deleted file mode 100644 index 5f41cd04..00000000 --- a/lib/mindee/product/proof_of_address/proof_of_address_v1.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../parsing' -require_relative 'proof_of_address_v1_document' -require_relative 'proof_of_address_v1_page' - -module Mindee - module Product - # Proof of Address module. - module ProofOfAddress - # Proof of Address API version 1 inference prediction. - class ProofOfAddressV1 < Mindee::Parsing::Common::Inference - @endpoint_name = 'proof_of_address' - @endpoint_version = '1' - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = ProofOfAddressV1Document.new(prediction['prediction'], nil) - @pages = [] - prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(ProofOfAddressV1Page.new(page)) - end - end - end - - class << self - # Name of the endpoint for this product. - # @return [String] - attr_reader :endpoint_name - # Version for this product. - # @return [String] - attr_reader :endpoint_version - end - end - end - end -end diff --git a/lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb b/lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb deleted file mode 100644 index 4726f992..00000000 --- a/lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb +++ /dev/null @@ -1,83 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../parsing' - -module Mindee - module Product - module ProofOfAddress - # Proof of Address API version 1.1 document data. - class ProofOfAddressV1Document < Mindee::Parsing::Common::Prediction - include Mindee::Parsing::Standard - # The date the document was issued. - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :date - # List of dates found on the document. - # @return [Array] - attr_reader :dates - # The address of the document's issuer. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :issuer_address - # List of company registrations found for the issuer. - # @return [Array] - attr_reader :issuer_company_registration - # The name of the person or company issuing the document. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :issuer_name - # The locale detected on the document. - # @return [Mindee::Parsing::Standard::LocaleField] - attr_reader :locale - # The address of the recipient. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :recipient_address - # List of company registrations found for the recipient. - # @return [Array] - attr_reader :recipient_company_registration - # The name of the person or company receiving the document. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :recipient_name - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - super() - @date = DateField.new(prediction['date'], page_id) - @dates = [] - prediction['dates'].each do |item| - @dates.push(DateField.new(item, page_id)) - end - @issuer_address = StringField.new(prediction['issuer_address'], page_id) - @issuer_company_registration = [] - prediction['issuer_company_registration'].each do |item| - @issuer_company_registration.push(CompanyRegistrationField.new(item, page_id)) - end - @issuer_name = StringField.new(prediction['issuer_name'], page_id) - @locale = LocaleField.new(prediction['locale'], page_id) - @recipient_address = StringField.new(prediction['recipient_address'], page_id) - @recipient_company_registration = [] - prediction['recipient_company_registration'].each do |item| - @recipient_company_registration.push(CompanyRegistrationField.new(item, page_id)) - end - @recipient_name = StringField.new(prediction['recipient_name'], page_id) - end - - # @return [String] - def to_s - issuer_company_registration = @issuer_company_registration.join("\n #{' ' * 30}") - recipient_company_registration = @recipient_company_registration.join("\n #{' ' * 33}") - dates = @dates.join("\n #{' ' * 7}") - out_str = String.new - out_str << "\n:Locale: #{@locale}".rstrip - out_str << "\n:Issuer Name: #{@issuer_name}".rstrip - out_str << "\n:Issuer Company Registrations: #{issuer_company_registration}".rstrip - out_str << "\n:Issuer Address: #{@issuer_address}".rstrip - out_str << "\n:Recipient Name: #{@recipient_name}".rstrip - out_str << "\n:Recipient Company Registrations: #{recipient_company_registration}".rstrip - out_str << "\n:Recipient Address: #{@recipient_address}".rstrip - out_str << "\n:Dates: #{dates}".rstrip - out_str << "\n:Date of Issue: #{@date}".rstrip - out_str[1..].to_s - end - end - end - end -end diff --git a/lib/mindee/product/proof_of_address/proof_of_address_v1_page.rb b/lib/mindee/product/proof_of_address/proof_of_address_v1_page.rb deleted file mode 100644 index ebce0c3b..00000000 --- a/lib/mindee/product/proof_of_address/proof_of_address_v1_page.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../parsing' -require_relative 'proof_of_address_v1_document' - -module Mindee - module Product - module ProofOfAddress - # Proof of Address API version 1.1 page data. - class ProofOfAddressV1Page < Mindee::Parsing::Common::Page - # @param prediction [Hash] - def initialize(prediction) - super(prediction) - @prediction = ProofOfAddressV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) - end - end - - # Proof of Address V1 page prediction. - class ProofOfAddressV1PagePrediction < ProofOfAddressV1Document - # @return [String] - def to_s - out_str = String.new - out_str << "\n#{super}" - out_str - end - end - end - end -end diff --git a/lib/mindee/product/receipt/receipt_v4.rb b/lib/mindee/product/receipt/receipt_v4.rb deleted file mode 100644 index 3d801dc3..00000000 --- a/lib/mindee/product/receipt/receipt_v4.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../parsing' -require_relative 'receipt_v4_document' -require_relative 'receipt_v4_page' - -module Mindee - module Product - module Receipt - # Expense Receipt V4 prediction inference. - class ReceiptV4 < Mindee::Parsing::Common::Inference - @endpoint_name = 'expense_receipts' - @endpoint_version = '4' - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = ReceiptV4Document.new(prediction['prediction'], nil) - @pages = [] - prediction['pages'].each do |page| - @pages.push(ReceiptV4Page.new(page)) - end - end - - class << self - # Name of the endpoint for this product. - # @return [String] - attr_reader :endpoint_name - # Version for this product. - # @return [String] - attr_reader :endpoint_version - end - end - end - end -end diff --git a/lib/mindee/product/receipt/receipt_v4_document.rb b/lib/mindee/product/receipt/receipt_v4_document.rb deleted file mode 100644 index 91d30853..00000000 --- a/lib/mindee/product/receipt/receipt_v4_document.rb +++ /dev/null @@ -1,86 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../parsing' - -module Mindee - module Product - module Receipt - # Expense Receipt V4 document prediction. - class ReceiptV4Document < Mindee::Parsing::Common::Prediction - include Mindee::Parsing::Standard - # Where the purchase was made, the language, and the currency. - # @return [Mindee::Parsing::Standard::LocaleField] - attr_reader :locale - # Total including taxes - # @return [Mindee::Parsing::Standard::AmountField] - attr_reader :total_amount - # Total amount of the purchase excluding taxes. - # @return [Mindee::Parsing::Standard::AmountField] - attr_reader :total_net - # Total tax amount of the purchase. - # @return [Mindee::Parsing::Standard::AmountField] - attr_reader :total_tax - # The purchase date. - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :date - # The name of the supplier or merchant, as seen on the receipt. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :supplier - # List of taxes detected on the receipt. - # @return [Mindee::Parsing::Standard::Taxes] - attr_reader :taxes - # Time as seen on the receipt in HH:MM format. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :time - # The receipt category among predefined classes. - # @return [Mindee::Parsing::Standard::ClassificationField] - attr_reader :category - # The receipt sub-category among predefined classes. - # @return [Mindee::Parsing::Standard::ClassificationField] - attr_reader :subcategory - # Whether the document is an expense receipt or a credit card receipt. - # @return [Mindee::Parsing::Standard::ClassificationField] - attr_reader :document_type - # Total amount of tip and gratuity. Both typed and handwritten characters are supported. - # @return [Mindee::Parsing::Standard::AmountField] - attr_reader :tip - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - super() - @locale = LocaleField.new(prediction['locale']) - @total_amount = AmountField.new(prediction['total_amount'], page_id) - @total_net = AmountField.new(prediction['total_net'], page_id) - @total_tax = AmountField.new(prediction['total_tax'], page_id) - @tip = AmountField.new(prediction['tip'], page_id) - @date = DateField.new(prediction['date'], page_id) - @category = ClassificationField.new(prediction['category'], page_id) - @subcategory = ClassificationField.new(prediction['subcategory'], page_id) - @document_type = ClassificationField.new(prediction['document_type'], page_id) - @supplier = StringField.new(prediction['supplier'], page_id) - @time = StringField.new(prediction['time'], page_id) - @taxes = Taxes.new(prediction['taxes'], page_id) - end - - # @return [String] - def to_s - out_str = String.new - out_str << "\n:Locale: #{@locale}".rstrip - out_str << "\n:Date: #{@date}".rstrip - out_str << "\n:Category: #{@category}".rstrip - out_str << "\n:Subcategory: #{@subcategory}".rstrip - out_str << "\n:Document type: #{@document_type}".rstrip - out_str << "\n:Time: #{@time}".rstrip - out_str << "\n:Supplier name: #{@supplier}".rstrip - out_str << "\n:Taxes:#{@taxes}".rstrip - out_str << "\n:Total net: #{@total_net}".rstrip - out_str << "\n:Total tax: #{@total_tax}".rstrip - out_str << "\n:Tip: #{@tip}".rstrip - out_str << "\n:Total amount: #{@total_amount}".rstrip - out_str[1..].to_s - end - end - end - end -end diff --git a/lib/mindee/product/receipt/receipt_v4_page.rb b/lib/mindee/product/receipt/receipt_v4_page.rb deleted file mode 100644 index 180b3998..00000000 --- a/lib/mindee/product/receipt/receipt_v4_page.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../parsing' -require_relative 'receipt_v4_document' - -module Mindee - module Product - module Receipt - # Expense Receipt V4 page. - class ReceiptV4Page < Mindee::Parsing::Common::Page - # @param prediction [Hash] - def initialize(prediction) - super(prediction) - @prediction = ReceiptV4PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) - end - end - - # Expense Receipt V4 page prediction. - class ReceiptV4PagePrediction < ReceiptV4Document - # @return [String] - def to_s - out_str = String.new - out_str << "\n#{super}" - out_str - end - end - end - end -end diff --git a/lib/mindee/product/receipt/receipt_v5.rb b/lib/mindee/product/receipt/receipt_v5.rb index 8097a1b3..ce1b3c48 100644 --- a/lib/mindee/product/receipt/receipt_v5.rb +++ b/lib/mindee/product/receipt/receipt_v5.rb @@ -12,6 +12,8 @@ module Receipt class ReceiptV5 < Mindee::Parsing::Common::Inference @endpoint_name = 'expense_receipts' @endpoint_version = '5' + @has_async = true + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = ReceiptV5Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(ReceiptV5Page.new(page)) - end + @pages.push(ReceiptV5Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/receipt/receipt_v5_document.rb b/lib/mindee/product/receipt/receipt_v5_document.rb index 9dad48c0..37d159a4 100644 --- a/lib/mindee/product/receipt/receipt_v5_document.rb +++ b/lib/mindee/product/receipt/receipt_v5_document.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../../parsing' -require_relative 'receipt_v5_line_item' +require_relative 'receipt_v5_line_items' module Mindee module Product @@ -19,7 +19,7 @@ class ReceiptV5Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Parsing::Standard::ClassificationField] attr_reader :document_type # List of line item details. - # @return [Array] + # @return [Mindee::Product::Receipt::ReceiptV5LineItems] attr_reader :line_items # The locale detected on the document. # @return [Mindee::Parsing::Standard::LocaleField] @@ -64,30 +64,60 @@ class ReceiptV5Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @category = ClassificationField.new(prediction['category'], page_id) - @date = DateField.new(prediction['date'], page_id) - @document_type = ClassificationField.new(prediction['document_type'], page_id) - @line_items = [] - prediction['line_items'].each do |item| - @line_items.push(ReceiptV5LineItem.new(item, page_id)) - end - @locale = LocaleField.new(prediction['locale'], page_id) - @receipt_number = StringField.new(prediction['receipt_number'], page_id) - @subcategory = ClassificationField.new(prediction['subcategory'], page_id) - @supplier_address = StringField.new(prediction['supplier_address'], page_id) - @supplier_company_registrations = [] + super + @category = Parsing::Standard::ClassificationField.new( + prediction['category'], + page_id + ) + @date = Parsing::Standard::DateField.new(prediction['date'], page_id) + @document_type = Parsing::Standard::ClassificationField.new( + prediction['document_type'], + page_id + ) + @line_items = Product::Receipt::ReceiptV5LineItems.new(prediction['line_items'], page_id) + @locale = Parsing::Standard::LocaleField.new( + prediction['locale'], + page_id + ) + @receipt_number = Parsing::Standard::StringField.new( + prediction['receipt_number'], + page_id + ) + @subcategory = Parsing::Standard::ClassificationField.new( + prediction['subcategory'], + page_id + ) + @supplier_address = Parsing::Standard::StringField.new( + prediction['supplier_address'], + page_id + ) + @supplier_company_registrations = [] # : Array[Parsing::Standard::CompanyRegistrationField] prediction['supplier_company_registrations'].each do |item| - @supplier_company_registrations.push(CompanyRegistrationField.new(item, page_id)) + @supplier_company_registrations.push(Parsing::Standard::CompanyRegistrationField.new(item, page_id)) end - @supplier_name = StringField.new(prediction['supplier_name'], page_id) - @supplier_phone_number = StringField.new(prediction['supplier_phone_number'], page_id) - @taxes = Taxes.new(prediction['taxes'], page_id) - @time = StringField.new(prediction['time'], page_id) - @tip = AmountField.new(prediction['tip'], page_id) - @total_amount = AmountField.new(prediction['total_amount'], page_id) - @total_net = AmountField.new(prediction['total_net'], page_id) - @total_tax = AmountField.new(prediction['total_tax'], page_id) + @supplier_name = Parsing::Standard::StringField.new( + prediction['supplier_name'], + page_id + ) + @supplier_phone_number = Parsing::Standard::StringField.new( + prediction['supplier_phone_number'], + page_id + ) + @taxes = Parsing::Standard::Taxes.new(prediction['taxes'], page_id) + @time = Parsing::Standard::StringField.new(prediction['time'], page_id) + @tip = Parsing::Standard::AmountField.new(prediction['tip'], page_id) + @total_amount = Parsing::Standard::AmountField.new( + prediction['total_amount'], + page_id + ) + @total_net = Parsing::Standard::AmountField.new( + prediction['total_net'], + page_id + ) + @total_tax = Parsing::Standard::AmountField.new( + prediction['total_tax'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/receipt/receipt_v5_line_item.rb b/lib/mindee/product/receipt/receipt_v5_line_item.rb index 3d00d42c..de0f54e3 100644 --- a/lib/mindee/product/receipt/receipt_v5_line_item.rb +++ b/lib/mindee/product/receipt/receipt_v5_line_item.rb @@ -24,7 +24,7 @@ class ReceiptV5LineItem < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @description = prediction['description'] @quantity = prediction['quantity'] @total_amount = prediction['total_amount'] @@ -36,9 +36,12 @@ def initialize(prediction, page_id) def printable_values printable = {} printable[:description] = format_for_display(@description) - printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity) - printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:quantity] = + @quantity.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@quantity) + printable[:total_amount] = + @total_amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total_amount) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end @@ -46,9 +49,12 @@ def printable_values def table_printable_values printable = {} printable[:description] = format_for_display(@description, 36) - printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity) - printable[:total_amount] = @total_amount.nil? ? '' : Field.float_to_string(@total_amount) - printable[:unit_price] = @unit_price.nil? ? '' : Field.float_to_string(@unit_price) + printable[:quantity] = + @quantity.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@quantity) + printable[:total_amount] = + @total_amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@total_amount) + printable[:unit_price] = + @unit_price.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@unit_price) printable end diff --git a/lib/mindee/product/receipt/receipt_v5_line_items.rb b/lib/mindee/product/receipt/receipt_v5_line_items.rb new file mode 100644 index 00000000..678ffa8b --- /dev/null +++ b/lib/mindee/product/receipt/receipt_v5_line_items.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require_relative 'receipt_v5_line_item' + +module Mindee + module Product + module Receipt + # List of line item details. + class ReceiptV5LineItems < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + Receipt::ReceiptV5LineItem.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 38}" + out_str << "+#{char * 10}" + out_str << "+#{char * 14}" + out_str << "+#{char * 12}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Description ' + out_str << ' | Quantity' + out_str << ' | Total Amount' + out_str << ' | Unit Price' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end +end diff --git a/lib/mindee/product/receipt/receipt_v5_page.rb b/lib/mindee/product/receipt/receipt_v5_page.rb index e5c97de1..5b0aaefc 100644 --- a/lib/mindee/product/receipt/receipt_v5_page.rb +++ b/lib/mindee/product/receipt/receipt_v5_page.rb @@ -10,11 +10,15 @@ module Receipt class ReceiptV5Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = ReceiptV5PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + ReceiptV5PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/resume/resume_v1.rb b/lib/mindee/product/resume/resume_v1.rb index 3c08d2fb..3314ab1c 100644 --- a/lib/mindee/product/resume/resume_v1.rb +++ b/lib/mindee/product/resume/resume_v1.rb @@ -12,6 +12,8 @@ module Resume class ResumeV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'resume' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -19,9 +21,7 @@ def initialize(prediction) @prediction = ResumeV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(ResumeV1Page.new(page)) - end + @pages.push(ResumeV1Page.new(page)) end end @@ -32,6 +32,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/resume/resume_v1_certificate.rb b/lib/mindee/product/resume/resume_v1_certificate.rb index e5706e72..c18d2d55 100644 --- a/lib/mindee/product/resume/resume_v1_certificate.rb +++ b/lib/mindee/product/resume/resume_v1_certificate.rb @@ -24,7 +24,7 @@ class ResumeV1Certificate < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @grade = prediction['grade'] @name = prediction['name'] @provider = prediction['provider'] diff --git a/lib/mindee/product/resume/resume_v1_certificates.rb b/lib/mindee/product/resume/resume_v1_certificates.rb new file mode 100644 index 00000000..c11e7658 --- /dev/null +++ b/lib/mindee/product/resume/resume_v1_certificates.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require_relative 'resume_v1_social_networks_url' +require_relative 'resume_v1_language' +require_relative 'resume_v1_education' +require_relative 'resume_v1_professional_experience' +require_relative 'resume_v1_certificate' + +module Mindee + module Product + module Resume + # The list of certificates obtained by the candidate. + class ResumeV1Certificates < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + Resume::ResumeV1Certificate.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 12}" + out_str << "+#{char * 32}" + out_str << "+#{char * 27}" + out_str << "+#{char * 6}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Grade ' + out_str << ' | Name ' + out_str << ' | Provider ' + out_str << ' | Year' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end +end diff --git a/lib/mindee/product/resume/resume_v1_document.rb b/lib/mindee/product/resume/resume_v1_document.rb index afc2e47a..3cd11331 100644 --- a/lib/mindee/product/resume/resume_v1_document.rb +++ b/lib/mindee/product/resume/resume_v1_document.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true require_relative '../../parsing' -require_relative 'resume_v1_social_networks_url' -require_relative 'resume_v1_language' -require_relative 'resume_v1_education' -require_relative 'resume_v1_professional_experience' -require_relative 'resume_v1_certificate' +require_relative 'resume_v1_social_networks_urls' +require_relative 'resume_v1_languages' +require_relative 'resume_v1_educations' +require_relative 'resume_v1_professional_experiences' +require_relative 'resume_v1_certificates' module Mindee module Product @@ -17,7 +17,7 @@ class ResumeV1Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Parsing::Standard::StringField] attr_reader :address # The list of certificates obtained by the candidate. - # @return [Array] + # @return [Mindee::Product::Resume::ResumeV1Certificates] attr_reader :certificates # The ISO 639 code of the language in which the document is written. # @return [Mindee::Parsing::Standard::StringField] @@ -26,7 +26,7 @@ class ResumeV1Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Parsing::Standard::ClassificationField] attr_reader :document_type # The list of the candidate's educational background. - # @return [Array] + # @return [Mindee::Product::Resume::ResumeV1Educations] attr_reader :education # The email address of the candidate. # @return [Mindee::Parsing::Standard::StringField] @@ -41,7 +41,7 @@ class ResumeV1Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Parsing::Standard::StringField] attr_reader :job_applied # The list of languages that the candidate is proficient in. - # @return [Array] + # @return [Mindee::Product::Resume::ResumeV1Languages] attr_reader :languages # The ISO 3166 code for the country of citizenship of the candidate. # @return [Mindee::Parsing::Standard::StringField] @@ -53,10 +53,10 @@ class ResumeV1Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Parsing::Standard::StringField] attr_reader :profession # The list of the candidate's professional experiences. - # @return [Array] + # @return [Mindee::Product::Resume::ResumeV1ProfessionalExperiences] attr_reader :professional_experiences # The list of social network profiles of the candidate. - # @return [Array] + # @return [Mindee::Product::Resume::ResumeV1SocialNetworksUrls] attr_reader :social_networks_urls # The list of the candidate's interpersonal and communication abilities. # @return [Array] @@ -68,50 +68,63 @@ class ResumeV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @address = StringField.new(prediction['address'], page_id) - @certificates = [] - prediction['certificates'].each do |item| - @certificates.push(ResumeV1Certificate.new(item, page_id)) - end - @document_language = StringField.new(prediction['document_language'], page_id) - @document_type = ClassificationField.new(prediction['document_type'], page_id) - @education = [] - prediction['education'].each do |item| - @education.push(ResumeV1Education.new(item, page_id)) - end - @email_address = StringField.new(prediction['email_address'], page_id) - @given_names = [] + super + @address = Parsing::Standard::StringField.new( + prediction['address'], + page_id + ) + @certificates = Product::Resume::ResumeV1Certificates.new(prediction['certificates'], page_id) + @document_language = Parsing::Standard::StringField.new( + prediction['document_language'], + page_id + ) + @document_type = Parsing::Standard::ClassificationField.new( + prediction['document_type'], + page_id + ) + @education = Product::Resume::ResumeV1Educations.new(prediction['education'], page_id) + @email_address = Parsing::Standard::StringField.new( + prediction['email_address'], + page_id + ) + @given_names = [] # : Array[Parsing::Standard::StringField] prediction['given_names'].each do |item| - @given_names.push(StringField.new(item, page_id)) + @given_names.push(Parsing::Standard::StringField.new(item, page_id)) end - @hard_skills = [] + @hard_skills = [] # : Array[Parsing::Standard::StringField] prediction['hard_skills'].each do |item| - @hard_skills.push(StringField.new(item, page_id)) - end - @job_applied = StringField.new(prediction['job_applied'], page_id) - @languages = [] - prediction['languages'].each do |item| - @languages.push(ResumeV1Language.new(item, page_id)) - end - @nationality = StringField.new(prediction['nationality'], page_id) - @phone_number = StringField.new(prediction['phone_number'], page_id) - @profession = StringField.new(prediction['profession'], page_id) - @professional_experiences = [] - prediction['professional_experiences'].each do |item| - @professional_experiences.push(ResumeV1ProfessionalExperience.new(item, page_id)) + @hard_skills.push(Parsing::Standard::StringField.new(item, page_id)) end - @social_networks_urls = [] - prediction['social_networks_urls'].each do |item| - @social_networks_urls.push(ResumeV1SocialNetworksUrl.new(item, page_id)) - end - @soft_skills = [] + @job_applied = Parsing::Standard::StringField.new( + prediction['job_applied'], + page_id + ) + @languages = Product::Resume::ResumeV1Languages.new(prediction['languages'], page_id) + @nationality = Parsing::Standard::StringField.new( + prediction['nationality'], + page_id + ) + @phone_number = Parsing::Standard::StringField.new( + prediction['phone_number'], + page_id + ) + @profession = Parsing::Standard::StringField.new( + prediction['profession'], + page_id + ) + @professional_experiences = Product::Resume::ResumeV1ProfessionalExperiences.new( + prediction['professional_experiences'], page_id + ) + @social_networks_urls = Product::Resume::ResumeV1SocialNetworksUrls.new( + prediction['social_networks_urls'], page_id + ) + @soft_skills = [] # : Array[Parsing::Standard::StringField] prediction['soft_skills'].each do |item| - @soft_skills.push(StringField.new(item, page_id)) + @soft_skills.push(Parsing::Standard::StringField.new(item, page_id)) end - @surnames = [] + @surnames = [] # : Array[Parsing::Standard::StringField] prediction['surnames'].each do |item| - @surnames.push(StringField.new(item, page_id)) + @surnames.push(Parsing::Standard::StringField.new(item, page_id)) end end diff --git a/lib/mindee/product/resume/resume_v1_education.rb b/lib/mindee/product/resume/resume_v1_education.rb index 81c8ab12..97da43d1 100644 --- a/lib/mindee/product/resume/resume_v1_education.rb +++ b/lib/mindee/product/resume/resume_v1_education.rb @@ -33,7 +33,7 @@ class ResumeV1Education < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @degree_domain = prediction['degree_domain'] @degree_type = prediction['degree_type'] @end_month = prediction['end_month'] diff --git a/lib/mindee/product/resume/resume_v1_educations.rb b/lib/mindee/product/resume/resume_v1_educations.rb new file mode 100644 index 00000000..a3530bb7 --- /dev/null +++ b/lib/mindee/product/resume/resume_v1_educations.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require_relative 'resume_v1_social_networks_url' +require_relative 'resume_v1_language' +require_relative 'resume_v1_education' +require_relative 'resume_v1_professional_experience' +require_relative 'resume_v1_certificate' + +module Mindee + module Product + module Resume + # The list of the candidate's educational background. + class ResumeV1Educations < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + Resume::ResumeV1Education.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 17}" + out_str << "+#{char * 27}" + out_str << "+#{char * 11}" + out_str << "+#{char * 10}" + out_str << "+#{char * 27}" + out_str << "+#{char * 13}" + out_str << "+#{char * 12}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Domain ' + out_str << ' | Degree ' + out_str << ' | End Month' + out_str << ' | End Year' + out_str << ' | School ' + out_str << ' | Start Month' + out_str << ' | Start Year' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end +end diff --git a/lib/mindee/product/resume/resume_v1_language.rb b/lib/mindee/product/resume/resume_v1_language.rb index 6557e77d..0e640b75 100644 --- a/lib/mindee/product/resume/resume_v1_language.rb +++ b/lib/mindee/product/resume/resume_v1_language.rb @@ -18,7 +18,7 @@ class ResumeV1Language < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @language = prediction['language'] @level = prediction['level'] @page_id = page_id diff --git a/lib/mindee/product/resume/resume_v1_languages.rb b/lib/mindee/product/resume/resume_v1_languages.rb new file mode 100644 index 00000000..92c52591 --- /dev/null +++ b/lib/mindee/product/resume/resume_v1_languages.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require_relative 'resume_v1_social_networks_url' +require_relative 'resume_v1_language' +require_relative 'resume_v1_education' +require_relative 'resume_v1_professional_experience' +require_relative 'resume_v1_certificate' + +module Mindee + module Product + module Resume + # The list of languages that the candidate is proficient in. + class ResumeV1Languages < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + Resume::ResumeV1Language.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 10}" + out_str << "+#{char * 22}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Language' + out_str << ' | Level ' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end +end diff --git a/lib/mindee/product/resume/resume_v1_page.rb b/lib/mindee/product/resume/resume_v1_page.rb index f5338afb..2032a349 100644 --- a/lib/mindee/product/resume/resume_v1_page.rb +++ b/lib/mindee/product/resume/resume_v1_page.rb @@ -10,11 +10,15 @@ module Resume class ResumeV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = ResumeV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + ResumeV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/resume/resume_v1_professional_experience.rb b/lib/mindee/product/resume/resume_v1_professional_experience.rb index 38ebfe59..23c5aa5f 100644 --- a/lib/mindee/product/resume/resume_v1_professional_experience.rb +++ b/lib/mindee/product/resume/resume_v1_professional_experience.rb @@ -39,7 +39,7 @@ class ResumeV1ProfessionalExperience < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @contract_type = prediction['contract_type'] @department = prediction['department'] @description = prediction['description'] diff --git a/lib/mindee/product/resume/resume_v1_professional_experiences.rb b/lib/mindee/product/resume/resume_v1_professional_experiences.rb new file mode 100644 index 00000000..ac92f2bc --- /dev/null +++ b/lib/mindee/product/resume/resume_v1_professional_experiences.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require_relative 'resume_v1_social_networks_url' +require_relative 'resume_v1_language' +require_relative 'resume_v1_education' +require_relative 'resume_v1_professional_experience' +require_relative 'resume_v1_certificate' + +module Mindee + module Product + module Resume + # The list of the candidate's professional experiences. + class ResumeV1ProfessionalExperiences < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + Resume::ResumeV1ProfessionalExperience.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 17}" + out_str << "+#{char * 12}" + out_str << "+#{char * 38}" + out_str << "+#{char * 27}" + out_str << "+#{char * 11}" + out_str << "+#{char * 10}" + out_str << "+#{char * 22}" + out_str << "+#{char * 13}" + out_str << "+#{char * 12}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Contract Type ' + out_str << ' | Department' + out_str << ' | Description ' + out_str << ' | Employer ' + out_str << ' | End Month' + out_str << ' | End Year' + out_str << ' | Role ' + out_str << ' | Start Month' + out_str << ' | Start Year' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end +end diff --git a/lib/mindee/product/resume/resume_v1_social_networks_url.rb b/lib/mindee/product/resume/resume_v1_social_networks_url.rb index 42ccafbc..063b4cbf 100644 --- a/lib/mindee/product/resume/resume_v1_social_networks_url.rb +++ b/lib/mindee/product/resume/resume_v1_social_networks_url.rb @@ -18,7 +18,7 @@ class ResumeV1SocialNetworksUrl < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @name = prediction['name'] @url = prediction['url'] @page_id = page_id diff --git a/lib/mindee/product/resume/resume_v1_social_networks_urls.rb b/lib/mindee/product/resume/resume_v1_social_networks_urls.rb new file mode 100644 index 00000000..40acc2f0 --- /dev/null +++ b/lib/mindee/product/resume/resume_v1_social_networks_urls.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require_relative 'resume_v1_social_networks_url' +require_relative 'resume_v1_language' +require_relative 'resume_v1_education' +require_relative 'resume_v1_professional_experience' +require_relative 'resume_v1_certificate' + +module Mindee + module Product + module Resume + # The list of social network profiles of the candidate. + class ResumeV1SocialNetworksUrls < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + Resume::ResumeV1SocialNetworksUrl.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 22}" + out_str << "+#{char * 52}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Name ' + out_str << ' | URL ' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end +end diff --git a/lib/mindee/product/universal/universal.rb b/lib/mindee/product/universal/universal.rb new file mode 100644 index 00000000..7869bfb6 --- /dev/null +++ b/lib/mindee/product/universal/universal.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require_relative 'universal_document' +require_relative 'universal_page' + +module Mindee + module Product + # Universal product module. + module Universal + # Universal Document V1 prediction inference. + class Universal < Mindee::Parsing::Common::Inference + @endpoint_name = '' + @endpoint_version = '' + @has_sync = true + @has_async = true + + # @param prediction [Hash] + def initialize(prediction) + super + @prediction = UniversalDocument.new(prediction['prediction']) + @pages = [] # : Array[Mindee::Parsing::Common::Page] + prediction['pages'].each do |page| + if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? + @pages.push(UniversalPage.new(page)) + end + end + end + + class << self + # Name of the endpoint for this product. + # @return [String] + attr_reader :endpoint_name + # Version for this product. + # @return [String] + attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync + end + end + end + end +end diff --git a/lib/mindee/product/universal/universal_document.rb b/lib/mindee/product/universal/universal_document.rb new file mode 100644 index 00000000..7ea2e9ff --- /dev/null +++ b/lib/mindee/product/universal/universal_document.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require_relative '../../parsing' +require_relative 'universal_prediction' + +module Mindee + module Product + module Universal + # Universal Document V1 prediction + class UniversalDocument < Mindee::Product::Universal::UniversalPrediction + include Mindee::Parsing::Standard + # @param raw_prediction [Hash] + def initialize(raw_prediction) + super + raw_prediction.each do |field_name, field_contents| + if field_contents.is_a?(Array) + @fields[field_name] = Parsing::Universal::UniversalListField.new(field_contents) + elsif field_contents.is_a?(Hash) && Parsing::Universal.universal_object?(field_contents) + @fields[field_name] = Parsing::Universal::UniversalObjectField.new(field_contents) + else + field_contents_str = field_contents.dup + if field_contents_str.key?('value') && field_contents_str['value'].nil? == false + field_contents_str['value'] = field_contents_str['value'].to_s + end + @fields[field_name] = Mindee::Parsing::Standard::StringField.new(field_contents_str) + end + end + end + end + end + end +end diff --git a/lib/mindee/product/generated/generated_v1_page.rb b/lib/mindee/product/universal/universal_page.rb similarity index 52% rename from lib/mindee/product/generated/generated_v1_page.rb rename to lib/mindee/product/universal/universal_page.rb index 0a252a7e..7da359e5 100644 --- a/lib/mindee/product/generated/generated_v1_page.rb +++ b/lib/mindee/product/universal/universal_page.rb @@ -1,40 +1,40 @@ # frozen_string_literal: true require_relative '../../parsing' -require_relative 'generated_v1_prediction' +require_relative 'universal_prediction' module Mindee module Product - module Generated - # Generated Document V1 page. - class GeneratedV1Page < Mindee::Parsing::Common::Page + module Universal + # Universal Document V1 page. + class UniversalPage < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = GeneratedV1PagePrediction.new( + super + @prediction = UniversalPagePrediction.new( prediction['prediction'], prediction['id'] ) end end - # Generated Document V1 page prediction. - class GeneratedV1PagePrediction < GeneratedV1Prediction + # Universal Document V1 page prediction. + class UniversalPagePrediction < UniversalPrediction include Mindee::Parsing::Standard - include Mindee::Parsing::Generated + include Mindee::Parsing::Universal def initialize(raw_prediction, page_id = nil) - super() + super(raw_prediction) raw_prediction.each do |field_name, field_contents| if field_contents.is_a?(Array) - @fields[field_name] = GeneratedListField.new(field_contents, page_id) - elsif field_contents.is_a?(Hash) && Parsing::Generated.generated_object?(field_contents) - @fields[field_name] = GeneratedObjectField.new(field_contents, page_id) + @fields[field_name] = Mindee::Parsing::Universal::UniversalListField.new(field_contents, page_id) + elsif field_contents.is_a?(Hash) && Parsing::Universal.universal_object?(field_contents) + @fields[field_name] = Mindee::Parsing::Universal::UniversalObjectField.new(field_contents, page_id) else field_contents_str = field_contents.dup if field_contents_str.key?('value') && !field_contents_str['value'].nil? field_contents_str['value'] = field_contents_str['value'].to_s end - @fields[field_name] = StringField.new(field_contents_str, page_id) + @fields[field_name] = Mindee::Parsing::Standard::StringField.new(field_contents_str, page_id) end end end diff --git a/lib/mindee/product/generated/generated_v1_prediction.rb b/lib/mindee/product/universal/universal_prediction.rb similarity index 61% rename from lib/mindee/product/generated/generated_v1_prediction.rb rename to lib/mindee/product/universal/universal_prediction.rb index 81810f7e..144d0a58 100644 --- a/lib/mindee/product/generated/generated_v1_prediction.rb +++ b/lib/mindee/product/universal/universal_prediction.rb @@ -4,19 +4,19 @@ module Mindee module Product - module Generated - # Generated Document V1 page. - class GeneratedV1Prediction < Mindee::Parsing::Common::Prediction + module Universal + # Universal Document V1 page. + class UniversalPrediction < Mindee::Parsing::Common::Prediction include Mindee::Parsing::Common include Mindee::Parsing::Standard - include Mindee::Parsing::Generated + include Mindee::Parsing::Universal # All value fields in the document - # @return [Hash] + # @return [Hash] attr_reader :fields - def initialize - super() - @fields = {} + def initialize(_ = nil) + super + @fields = {} # : Hash[Symbol | String, untyped] end # String representation. @@ -24,7 +24,9 @@ def to_s out_str = '' pattern = %r{^(\n* *)( {2}):} @fields.each do |field_name, field_value| - str_value = if field_value.is_a?(GeneratedListField) && field_value.values.length.positive? + str_value = if field_value.is_a?( + Mindee::Parsing::Universal::UniversalListField + ) && field_value.values.length.positive? generate_field_string(field_name, field_value, pattern) else field_value.to_s @@ -39,21 +41,24 @@ def to_s private def generate_field_string(field_name, field_value, pattern) - return '' if field_value.values.empty? || field_value.values.nil? + values = field_value.values + return '' if values.nil? || values.empty? str_value = '' - str_value += if field_value.values[0].is_a?(Parsing::Generated::GeneratedObjectField) - field_value.values[0].str_level(1).sub(pattern, '\\1* :') + first_value = values[0] + str_value += if first_value.is_a?(Parsing::Universal::UniversalObjectField) + first_value.str_level(1).sub(pattern, '\\1* :') else - "#{field_value.values[0].to_s.sub(pattern, '\\1* :')}\n" + "#{first_value.to_s.sub(pattern, '\\1* :')}\n" end - field_value.values[1..].each do |sub_value| - str_value += if sub_value.is_a?(Parsing::Generated::GeneratedObjectField) + Array(values[1..]).each do |sub_value| + str_value += if sub_value.is_a?(Parsing::Universal::UniversalObjectField) sub_value.str_level(1).sub(pattern, '\\1* :') else "#{' ' * (field_name.length + 2)} #{sub_value}\n" end end + str_value.rstrip end @@ -66,7 +71,7 @@ def generate_list_field_string(field_name, field_value, pattern) end def generate_sub_value_string(field_name, sub_value, pattern) - if sub_value.is_a?(GeneratedObjectField) + if sub_value.is_a?(Mindee::Parsing::Universal::UniversalObjectField) sub_value.str_level(1).gsub(pattern, '\1* :') else (' ' * (field_name.length + 2)) + "#{sub_value}\n" @@ -76,29 +81,32 @@ def generate_sub_value_string(field_name, sub_value, pattern) # Returns a hash of all fields that aren't a collection # @return [Hash] def single_fields - single_fields = {} + single_fields = {} # : Hash[Symbol | String, untyped] @fields.each do |field_name, field_value| - single_fields[field_name] = field_value if field_value.is_a?(StringField) + single_fields[field_name] = field_value if field_value.is_a?(Mindee::Parsing::Standard::StringField) end single_fields end # Returns a hash of all list-like fields - # @return [Hash] + # @return [Hash] def list_fields - list_fields = {} + list_fields = {} # : Hash[Symbol | String, Mindee::Parsing::Universal::UniversalListField] @fields.each do |field_name, field_value| - list_fields[field_name] = field_value if field_value.is_a?(GeneratedListField) + list_fields[field_name] = field_value if field_value.is_a?(Mindee::Parsing::Universal::UniversalListField) end list_fields end # Returns a hash of all object-like fields - # @return [Hash] + # @return [Hash] def object_fields - object_fields = {} + object_fields = {} # : Hash[Symbol | String, untyped] @fields.each do |field_name, field_value| - object_fields[field_name] = field_value if field_value.is_a?(GeneratedObjectField) + if field_value.is_a?(Mindee::Parsing::Universal::UniversalObjectField) + object_fields[field_name] = + field_value + end end object_fields end diff --git a/lib/mindee/product/us/bank_check/bank_check_v1.rb b/lib/mindee/product/us/bank_check/bank_check_v1.rb index 35361163..8dd0008f 100644 --- a/lib/mindee/product/us/bank_check/bank_check_v1.rb +++ b/lib/mindee/product/us/bank_check/bank_check_v1.rb @@ -13,6 +13,8 @@ module BankCheck class BankCheckV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'bank_check' @endpoint_version = '1' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = BankCheckV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(BankCheckV1Page.new(page)) - end + @pages.push(BankCheckV1Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/us/bank_check/bank_check_v1_document.rb b/lib/mindee/product/us/bank_check/bank_check_v1_document.rb index 158ad8ab..2d3064f2 100644 --- a/lib/mindee/product/us/bank_check/bank_check_v1_document.rb +++ b/lib/mindee/product/us/bank_check/bank_check_v1_document.rb @@ -31,16 +31,28 @@ class BankCheckV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @account_number = StringField.new(prediction['account_number'], page_id) - @amount = AmountField.new(prediction['amount'], page_id) - @check_number = StringField.new(prediction['check_number'], page_id) - @date = DateField.new(prediction['date'], page_id) - @payees = [] + super + @account_number = Parsing::Standard::StringField.new( + prediction['account_number'], + page_id + ) + @amount = Parsing::Standard::AmountField.new( + prediction['amount'], + page_id + ) + @check_number = Parsing::Standard::StringField.new( + prediction['check_number'], + page_id + ) + @date = Parsing::Standard::DateField.new(prediction['date'], page_id) + @payees = [] # : Array[Parsing::Standard::StringField] prediction['payees'].each do |item| - @payees.push(StringField.new(item, page_id)) + @payees.push(Parsing::Standard::StringField.new(item, page_id)) end - @routing_number = StringField.new(prediction['routing_number'], page_id) + @routing_number = Parsing::Standard::StringField.new( + prediction['routing_number'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/us/bank_check/bank_check_v1_page.rb b/lib/mindee/product/us/bank_check/bank_check_v1_page.rb index f3fdc45b..78013224 100644 --- a/lib/mindee/product/us/bank_check/bank_check_v1_page.rb +++ b/lib/mindee/product/us/bank_check/bank_check_v1_page.rb @@ -11,11 +11,15 @@ module BankCheck class BankCheckV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = BankCheckV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + BankCheckV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end @@ -33,12 +37,15 @@ class BankCheckV1PagePrediction < BankCheckV1Document # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - @check_position = PositionField.new(prediction['check_position'], page_id) + @check_position = Parsing::Standard::PositionField.new( + prediction['check_position'], + page_id + ) @signatures_positions = [] prediction['signatures_positions'].each do |item| - @signatures_positions.push(PositionField.new(item, page_id)) + @signatures_positions.push(Parsing::Standard::PositionField.new(item, page_id)) end - super(prediction, page_id) + super end # @return [String] diff --git a/lib/mindee/product/us/driver_license/driver_license_v1.rb b/lib/mindee/product/us/driver_license/driver_license_v1.rb deleted file mode 100644 index 69496e27..00000000 --- a/lib/mindee/product/us/driver_license/driver_license_v1.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'driver_license_v1_document' -require_relative 'driver_license_v1_page' - -module Mindee - module Product - module US - # Driver License module. - module DriverLicense - # Driver License API version 1 inference prediction. - class DriverLicenseV1 < Mindee::Parsing::Common::Inference - @endpoint_name = 'us_driver_license' - @endpoint_version = '1' - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = DriverLicenseV1Document.new(prediction['prediction'], nil) - @pages = [] - prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(DriverLicenseV1Page.new(page)) - end - end - end - - class << self - # Name of the endpoint for this product. - # @return [String] - attr_reader :endpoint_name - # Version for this product. - # @return [String] - attr_reader :endpoint_version - end - end - end - end - end -end diff --git a/lib/mindee/product/us/driver_license/driver_license_v1_document.rb b/lib/mindee/product/us/driver_license/driver_license_v1_document.rb deleted file mode 100644 index 016449d5..00000000 --- a/lib/mindee/product/us/driver_license/driver_license_v1_document.rb +++ /dev/null @@ -1,113 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' - -module Mindee - module Product - module US - module DriverLicense - # Driver License API version 1.1 document data. - class DriverLicenseV1Document < Mindee::Parsing::Common::Prediction - include Mindee::Parsing::Standard - # US driver license holders address - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :address - # US driver license holders date of birth - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :date_of_birth - # Document Discriminator Number of the US Driver License - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :dd_number - # US driver license holders class - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :dl_class - # ID number of the US Driver License. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :driver_license_id - # US driver license holders endorsements - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :endorsements - # Date on which the documents expires. - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :expiry_date - # US driver license holders eye colour - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :eye_color - # US driver license holders first name(s) - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :first_name - # US driver license holders hair colour - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :hair_color - # US driver license holders hight - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :height - # Date on which the documents was issued. - # @return [Mindee::Parsing::Standard::DateField] - attr_reader :issued_date - # US driver license holders last name - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :last_name - # US driver license holders restrictions - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :restrictions - # US driver license holders gender - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :sex - # US State - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :state - # US driver license holders weight - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :weight - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - super() - @address = StringField.new(prediction['address'], page_id) - @date_of_birth = DateField.new(prediction['date_of_birth'], page_id) - @dd_number = StringField.new(prediction['dd_number'], page_id) - @dl_class = StringField.new(prediction['dl_class'], page_id) - @driver_license_id = StringField.new(prediction['driver_license_id'], page_id) - @endorsements = StringField.new(prediction['endorsements'], page_id) - @expiry_date = DateField.new(prediction['expiry_date'], page_id) - @eye_color = StringField.new(prediction['eye_color'], page_id) - @first_name = StringField.new(prediction['first_name'], page_id) - @hair_color = StringField.new(prediction['hair_color'], page_id) - @height = StringField.new(prediction['height'], page_id) - @issued_date = DateField.new(prediction['issued_date'], page_id) - @last_name = StringField.new(prediction['last_name'], page_id) - @restrictions = StringField.new(prediction['restrictions'], page_id) - @sex = StringField.new(prediction['sex'], page_id) - @state = StringField.new(prediction['state'], page_id) - @weight = StringField.new(prediction['weight'], page_id) - end - - # @return [String] - def to_s - out_str = String.new - out_str << "\n:State: #{@state}".rstrip - out_str << "\n:Driver License ID: #{@driver_license_id}".rstrip - out_str << "\n:Expiry Date: #{@expiry_date}".rstrip - out_str << "\n:Date Of Issue: #{@issued_date}".rstrip - out_str << "\n:Last Name: #{@last_name}".rstrip - out_str << "\n:First Name: #{@first_name}".rstrip - out_str << "\n:Address: #{@address}".rstrip - out_str << "\n:Date Of Birth: #{@date_of_birth}".rstrip - out_str << "\n:Restrictions: #{@restrictions}".rstrip - out_str << "\n:Endorsements: #{@endorsements}".rstrip - out_str << "\n:Driver License Class: #{@dl_class}".rstrip - out_str << "\n:Sex: #{@sex}".rstrip - out_str << "\n:Height: #{@height}".rstrip - out_str << "\n:Weight: #{@weight}".rstrip - out_str << "\n:Hair Color: #{@hair_color}".rstrip - out_str << "\n:Eye Color: #{@eye_color}".rstrip - out_str << "\n:Document Discriminator: #{@dd_number}".rstrip - out_str[1..].to_s - end - end - end - end - end -end diff --git a/lib/mindee/product/us/driver_license/driver_license_v1_page.rb b/lib/mindee/product/us/driver_license/driver_license_v1_page.rb deleted file mode 100644 index 15c9c9cb..00000000 --- a/lib/mindee/product/us/driver_license/driver_license_v1_page.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'driver_license_v1_document' - -module Mindee - module Product - module US - module DriverLicense - # Driver License API version 1.1 page data. - class DriverLicenseV1Page < Mindee::Parsing::Common::Page - # @param prediction [Hash] - def initialize(prediction) - super(prediction) - @prediction = DriverLicenseV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) - end - end - - # Driver License V1 page prediction. - class DriverLicenseV1PagePrediction < DriverLicenseV1Document - include Mindee::Parsing::Standard - - # Has a photo of the US driver license holder - # @return [Mindee::Parsing::Standard::PositionField] - attr_reader :photo - # Has a signature of the US driver license holder - # @return [Mindee::Parsing::Standard::PositionField] - attr_reader :signature - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - @photo = PositionField.new(prediction['photo'], page_id) - @signature = PositionField.new(prediction['signature'], page_id) - super(prediction, page_id) - end - - # @return [String] - def to_s - out_str = String.new - out_str << "\n:Photo: #{@photo}".rstrip - out_str << "\n:Signature: #{@signature}".rstrip - out_str << "\n#{super}" - out_str - end - end - end - end - end -end diff --git a/lib/mindee/product/us/healthcare_card/healthcare_card_v1.rb b/lib/mindee/product/us/healthcare_card/healthcare_card_v1.rb index 1af4823f..75c0bcd3 100644 --- a/lib/mindee/product/us/healthcare_card/healthcare_card_v1.rb +++ b/lib/mindee/product/us/healthcare_card/healthcare_card_v1.rb @@ -13,6 +13,8 @@ module HealthcareCard class HealthcareCardV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'us_healthcare_cards' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = HealthcareCardV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(HealthcareCardV1Page.new(page)) - end + @pages.push(HealthcareCardV1Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rb b/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rb index 9cacc78d..296e8f06 100644 --- a/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rb +++ b/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rb @@ -19,7 +19,7 @@ class HealthcareCardV1Copay < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @service_fees = prediction['service_fees'] @service_name = prediction['service_name'] @page_id = page_id @@ -28,7 +28,8 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:service_fees] = @service_fees.nil? ? '' : Field.float_to_string(@service_fees) + printable[:service_fees] = + @service_fees.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@service_fees) printable[:service_name] = format_for_display(@service_name) printable end @@ -36,7 +37,8 @@ def printable_values # @return [Hash] def table_printable_values printable = {} - printable[:service_fees] = @service_fees.nil? ? '' : Field.float_to_string(@service_fees) + printable[:service_fees] = + @service_fees.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@service_fees) printable[:service_name] = format_for_display(@service_name, nil) printable end diff --git a/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copays.rb b/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copays.rb new file mode 100644 index 00000000..16c401fe --- /dev/null +++ b/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copays.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require_relative 'healthcare_card_v1_copay' + +module Mindee + module Product + module US + module HealthcareCard + # Is a fixed amount for a covered service. + class HealthcareCardV1Copays < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + HealthcareCard::HealthcareCardV1Copay.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 14}" + out_str << "+#{char * 14}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | Service Fees' + out_str << ' | Service Name' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end + end +end diff --git a/lib/mindee/product/us/healthcare_card/healthcare_card_v1_document.rb b/lib/mindee/product/us/healthcare_card/healthcare_card_v1_document.rb index b86f6018..bd973bef 100644 --- a/lib/mindee/product/us/healthcare_card/healthcare_card_v1_document.rb +++ b/lib/mindee/product/us/healthcare_card/healthcare_card_v1_document.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../../../parsing' -require_relative 'healthcare_card_v1_copay' +require_relative 'healthcare_card_v1_copays' module Mindee module Product @@ -14,7 +14,7 @@ class HealthcareCardV1Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Parsing::Standard::StringField] attr_reader :company_name # Is a fixed amount for a covered service. - # @return [Array] + # @return [Mindee::Product::US::HealthcareCard::HealthcareCardV1Copays] attr_reader :copays # The list of dependents covered by the healthcare plan. # @return [Array] @@ -50,25 +50,52 @@ class HealthcareCardV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @company_name = StringField.new(prediction['company_name'], page_id) - @copays = [] - prediction['copays'].each do |item| - @copays.push(HealthcareCardV1Copay.new(item, page_id)) - end - @dependents = [] + super + @company_name = Parsing::Standard::StringField.new( + prediction['company_name'], + page_id + ) + @copays = Product::US::HealthcareCard::HealthcareCardV1Copays.new(prediction['copays'], page_id) + @dependents = [] # : Array[Parsing::Standard::StringField] prediction['dependents'].each do |item| - @dependents.push(StringField.new(item, page_id)) + @dependents.push(Parsing::Standard::StringField.new(item, page_id)) end - @enrollment_date = DateField.new(prediction['enrollment_date'], page_id) - @group_number = StringField.new(prediction['group_number'], page_id) - @issuer80840 = StringField.new(prediction['issuer_80840'], page_id) - @member_id = StringField.new(prediction['member_id'], page_id) - @member_name = StringField.new(prediction['member_name'], page_id) - @payer_id = StringField.new(prediction['payer_id'], page_id) - @rx_bin = StringField.new(prediction['rx_bin'], page_id) - @rx_grp = StringField.new(prediction['rx_grp'], page_id) - @rx_pcn = StringField.new(prediction['rx_pcn'], page_id) + @enrollment_date = Parsing::Standard::DateField.new( + prediction['enrollment_date'], + page_id + ) + @group_number = Parsing::Standard::StringField.new( + prediction['group_number'], + page_id + ) + @issuer80840 = Parsing::Standard::StringField.new( + prediction['issuer_80840'], + page_id + ) + @member_id = Parsing::Standard::StringField.new( + prediction['member_id'], + page_id + ) + @member_name = Parsing::Standard::StringField.new( + prediction['member_name'], + page_id + ) + @payer_id = Parsing::Standard::StringField.new( + prediction['payer_id'], + page_id + ) + @rx_bin = Parsing::Standard::StringField.new( + prediction['rx_bin'], + page_id + ) + @rx_grp = Parsing::Standard::StringField.new( + prediction['rx_grp'], + page_id + ) + @rx_pcn = Parsing::Standard::StringField.new( + prediction['rx_pcn'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/us/healthcare_card/healthcare_card_v1_page.rb b/lib/mindee/product/us/healthcare_card/healthcare_card_v1_page.rb index a37d24c7..74bbc23b 100644 --- a/lib/mindee/product/us/healthcare_card/healthcare_card_v1_page.rb +++ b/lib/mindee/product/us/healthcare_card/healthcare_card_v1_page.rb @@ -11,11 +11,15 @@ module HealthcareCard class HealthcareCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = HealthcareCardV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + HealthcareCardV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/us/us_mail/us_mail_v2.rb b/lib/mindee/product/us/us_mail/us_mail_v2.rb deleted file mode 100644 index 5b58064a..00000000 --- a/lib/mindee/product/us/us_mail/us_mail_v2.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'us_mail_v2_document' -require_relative 'us_mail_v2_page' - -module Mindee - module Product - module US - # US Mail module. - module UsMail - # US Mail API version 2 inference prediction. - class UsMailV2 < Mindee::Parsing::Common::Inference - @endpoint_name = 'us_mail' - @endpoint_version = '2' - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = UsMailV2Document.new(prediction['prediction'], nil) - @pages = [] - prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(UsMailV2Page.new(page)) - end - end - end - - class << self - # Name of the endpoint for this product. - # @return [String] - attr_reader :endpoint_name - # Version for this product. - # @return [String] - attr_reader :endpoint_version - end - end - end - end - end -end diff --git a/lib/mindee/product/us/us_mail/us_mail_v2_document.rb b/lib/mindee/product/us/us_mail/us_mail_v2_document.rb deleted file mode 100644 index ac4edb92..00000000 --- a/lib/mindee/product/us/us_mail/us_mail_v2_document.rb +++ /dev/null @@ -1,100 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'us_mail_v2_sender_address' -require_relative 'us_mail_v2_recipient_address' - -module Mindee - module Product - module US - module UsMail - # US Mail API version 2.0 document data. - class UsMailV2Document < Mindee::Parsing::Common::Prediction - include Mindee::Parsing::Standard - # The addresses of the recipients. - # @return [Array] - attr_reader :recipient_addresses - # The names of the recipients. - # @return [Array] - attr_reader :recipient_names - # The address of the sender. - # @return [Mindee::Product::US::UsMail::UsMailV2SenderAddress] - attr_reader :sender_address - # The name of the sender. - # @return [Mindee::Parsing::Standard::StringField] - attr_reader :sender_name - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - super() - @recipient_addresses = [] - prediction['recipient_addresses'].each do |item| - @recipient_addresses.push(UsMailV2RecipientAddress.new(item, page_id)) - end - @recipient_names = [] - prediction['recipient_names'].each do |item| - @recipient_names.push(StringField.new(item, page_id)) - end - @sender_address = UsMailV2SenderAddress.new(prediction['sender_address'], page_id) - @sender_name = StringField.new(prediction['sender_name'], page_id) - end - - # @return [String] - def to_s - sender_address = @sender_address.to_s - recipient_names = @recipient_names.join("\n #{' ' * 17}") - recipient_addresses = recipient_addresses_to_s - out_str = String.new - out_str << "\n:Sender Name: #{@sender_name}".rstrip - out_str << "\n:Sender Address:" - out_str << sender_address - out_str << "\n:Recipient Names: #{recipient_names}".rstrip - out_str << "\n:Recipient Addresses:" - out_str << recipient_addresses - out_str[1..].to_s - end - - private - - # @param char [String] - # @return [String] - def recipient_addresses_separator(char) - out_str = String.new - out_str << ' ' - out_str << "+#{char * 17}" - out_str << "+#{char * 37}" - out_str << "+#{char * 19}" - out_str << "+#{char * 13}" - out_str << "+#{char * 24}" - out_str << "+#{char * 7}" - out_str << "+#{char * 27}" - out_str << '+' - out_str - end - - # @return [String] - def recipient_addresses_to_s - return '' if @recipient_addresses.empty? - - line_items = @recipient_addresses.map(&:to_table_line).join("\n#{recipient_addresses_separator('-')}\n ") - out_str = String.new - out_str << "\n#{recipient_addresses_separator('-')}" - out_str << "\n |" - out_str << ' City |' - out_str << ' Complete Address |' - out_str << ' Is Address Change |' - out_str << ' Postal Code |' - out_str << ' Private Mailbox Number |' - out_str << ' State |' - out_str << ' Street |' - out_str << "\n#{recipient_addresses_separator('=')}" - out_str << "\n #{line_items}" - out_str << "\n#{recipient_addresses_separator('-')}" - out_str - end - end - end - end - end -end diff --git a/lib/mindee/product/us/us_mail/us_mail_v2_page.rb b/lib/mindee/product/us/us_mail/us_mail_v2_page.rb deleted file mode 100644 index fbe123e1..00000000 --- a/lib/mindee/product/us/us_mail/us_mail_v2_page.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'us_mail_v2_document' - -module Mindee - module Product - module US - module UsMail - # US Mail API version 2.0 page data. - class UsMailV2Page < Mindee::Parsing::Common::Page - # @param prediction [Hash] - def initialize(prediction) - super(prediction) - @prediction = UsMailV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) - end - end - - # US Mail V2 page prediction. - class UsMailV2PagePrediction < UsMailV2Document - # @return [String] - def to_s - out_str = String.new - out_str << "\n#{super}" - out_str - end - end - end - end - end -end diff --git a/lib/mindee/product/us/us_mail/us_mail_v2_recipient_address.rb b/lib/mindee/product/us/us_mail/us_mail_v2_recipient_address.rb deleted file mode 100644 index 8c38e2e3..00000000 --- a/lib/mindee/product/us/us_mail/us_mail_v2_recipient_address.rb +++ /dev/null @@ -1,105 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' - -module Mindee - module Product - module US - module UsMail - # The addresses of the recipients. - class UsMailV2RecipientAddress < Mindee::Parsing::Standard::FeatureField - include Mindee::Parsing::Standard - # The city of the recipient's address. - # @return [String] - attr_reader :city - # The complete address of the recipient. - # @return [String] - attr_reader :complete - # Indicates if the recipient's address is a change of address. - # @return [Boolean] - attr_reader :is_address_change - # The postal code of the recipient's address. - # @return [String] - attr_reader :postal_code - # The private mailbox number of the recipient's address. - # @return [String] - attr_reader :private_mailbox_number - # Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. - # @return [String] - attr_reader :state - # The street of the recipient's address. - # @return [String] - attr_reader :street - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - super(prediction, page_id) - @city = prediction['city'] - @complete = prediction['complete'] - @is_address_change = prediction['is_address_change'] - @postal_code = prediction['postal_code'] - @private_mailbox_number = prediction['private_mailbox_number'] - @state = prediction['state'] - @street = prediction['street'] - @page_id = page_id - end - - # @return [Hash] - def printable_values - printable = {} - printable[:city] = format_for_display(@city) - printable[:complete] = format_for_display(@complete) - printable[:is_address_change] = format_for_display(@is_address_change) - printable[:postal_code] = format_for_display(@postal_code) - printable[:private_mailbox_number] = format_for_display(@private_mailbox_number) - printable[:state] = format_for_display(@state) - printable[:street] = format_for_display(@street) - printable - end - - # @return [Hash] - def table_printable_values - printable = {} - printable[:city] = format_for_display(@city, 15) - printable[:complete] = format_for_display(@complete, 35) - printable[:is_address_change] = format_for_display(@is_address_change, nil) - printable[:postal_code] = format_for_display(@postal_code, nil) - printable[:private_mailbox_number] = format_for_display(@private_mailbox_number, nil) - printable[:state] = format_for_display(@state, nil) - printable[:street] = format_for_display(@street, 25) - printable - end - - # @return [String] - def to_table_line - printable = table_printable_values - out_str = String.new - out_str << format('| %- 16s', printable[:city]) - out_str << format('| %- 36s', printable[:complete]) - out_str << format('| %- 18s', printable[:is_address_change]) - out_str << format('| %- 12s', printable[:postal_code]) - out_str << format('| %- 23s', printable[:private_mailbox_number]) - out_str << format('| %- 6s', printable[:state]) - out_str << format('| %- 26s', printable[:street]) - out_str << '|' - end - - # @return [String] - def to_s - printable = printable_values - out_str = String.new - out_str << "\n :City: #{printable[:city]}" - out_str << "\n :Complete Address: #{printable[:complete]}" - out_str << "\n :Is Address Change: #{printable[:is_address_change]}" - out_str << "\n :Postal Code: #{printable[:postal_code]}" - out_str << "\n :Private Mailbox Number: #{printable[:private_mailbox_number]}" - out_str << "\n :State: #{printable[:state]}" - out_str << "\n :Street: #{printable[:street]}" - out_str - end - end - end - end - end -end diff --git a/lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb b/lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb deleted file mode 100644 index cbbd7837..00000000 --- a/lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' - -module Mindee - module Product - module US - module UsMail - # The address of the sender. - class UsMailV2SenderAddress < Mindee::Parsing::Standard::FeatureField - include Mindee::Parsing::Standard - # The city of the sender's address. - # @return [String] - attr_reader :city - # The complete address of the sender. - # @return [String] - attr_reader :complete - # The postal code of the sender's address. - # @return [String] - attr_reader :postal_code - # Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. - # @return [String] - attr_reader :state - # The street of the sender's address. - # @return [String] - attr_reader :street - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - super(prediction, page_id) - @city = prediction['city'] - @complete = prediction['complete'] - @postal_code = prediction['postal_code'] - @state = prediction['state'] - @street = prediction['street'] - @page_id = page_id - end - - # @return [Hash] - def printable_values - printable = {} - printable[:city] = format_for_display(@city) - printable[:complete] = format_for_display(@complete) - printable[:postal_code] = format_for_display(@postal_code) - printable[:state] = format_for_display(@state) - printable[:street] = format_for_display(@street) - printable - end - - # @return [String] - def to_s - printable = printable_values - out_str = String.new - out_str << "\n :City: #{printable[:city]}" - out_str << "\n :Complete Address: #{printable[:complete]}" - out_str << "\n :Postal Code: #{printable[:postal_code]}" - out_str << "\n :State: #{printable[:state]}" - out_str << "\n :Street: #{printable[:street]}" - out_str - end - end - end - end - end -end diff --git a/lib/mindee/product/us/us_mail/us_mail_v3.rb b/lib/mindee/product/us/us_mail/us_mail_v3.rb index c81105c6..02557697 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v3.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v3.rb @@ -13,6 +13,8 @@ module UsMail class UsMailV3 < Mindee::Parsing::Common::Inference @endpoint_name = 'us_mail' @endpoint_version = '3' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @prediction = UsMailV3Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(UsMailV3Page.new(page)) - end + @pages.push(UsMailV3Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/us/us_mail/us_mail_v3_document.rb b/lib/mindee/product/us/us_mail/us_mail_v3_document.rb index f8ae3a3a..99f81a50 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v3_document.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v3_document.rb @@ -2,7 +2,7 @@ require_relative '../../../parsing' require_relative 'us_mail_v3_sender_address' -require_relative 'us_mail_v3_recipient_address' +require_relative 'us_mail_v3_recipient_addresses' module Mindee module Product @@ -15,7 +15,7 @@ class UsMailV3Document < Mindee::Parsing::Common::Prediction # @return [Mindee::Parsing::Standard::BooleanField] attr_reader :is_return_to_sender # The addresses of the recipients. - # @return [Array] + # @return [Mindee::Product::US::UsMail::UsMailV3RecipientAddresses] attr_reader :recipient_addresses # The names of the recipients. # @return [Array] @@ -30,18 +30,26 @@ class UsMailV3Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() - @is_return_to_sender = BooleanField.new(prediction['is_return_to_sender'], page_id) - @recipient_addresses = [] - prediction['recipient_addresses'].each do |item| - @recipient_addresses.push(UsMailV3RecipientAddress.new(item, page_id)) - end - @recipient_names = [] + super + @is_return_to_sender = Parsing::Standard::BooleanField.new( + prediction['is_return_to_sender'], + page_id + ) + @recipient_addresses = Product::US::UsMail::UsMailV3RecipientAddresses.new( + prediction['recipient_addresses'], page_id + ) + @recipient_names = [] # : Array[Parsing::Standard::StringField] prediction['recipient_names'].each do |item| - @recipient_names.push(StringField.new(item, page_id)) + @recipient_names.push(Parsing::Standard::StringField.new(item, page_id)) end - @sender_address = UsMailV3SenderAddress.new(prediction['sender_address'], page_id) - @sender_name = StringField.new(prediction['sender_name'], page_id) + @sender_address = Product::US::UsMail::UsMailV3SenderAddress.new( + prediction['sender_address'], + page_id + ) + @sender_name = Parsing::Standard::StringField.new( + prediction['sender_name'], + page_id + ) end # @return [String] diff --git a/lib/mindee/product/us/us_mail/us_mail_v3_page.rb b/lib/mindee/product/us/us_mail/us_mail_v3_page.rb index 15bcb318..6241c325 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v3_page.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v3_page.rb @@ -11,11 +11,15 @@ module UsMail class UsMailV3Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = UsMailV3PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + UsMailV3PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/us/us_mail/us_mail_v3_recipient_address.rb b/lib/mindee/product/us/us_mail/us_mail_v3_recipient_address.rb index 808f7291..f2b109e4 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v3_recipient_address.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v3_recipient_address.rb @@ -16,7 +16,7 @@ class UsMailV3RecipientAddress < Mindee::Parsing::Standard::FeatureField # @return [String] attr_reader :complete # Indicates if the recipient's address is a change of address. - # @return [Boolean] + # @return [bool] attr_reader :is_address_change # The postal code of the recipient's address. # @return [String] @@ -37,7 +37,7 @@ class UsMailV3RecipientAddress < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @city = prediction['city'] @complete = prediction['complete'] @is_address_change = prediction['is_address_change'] diff --git a/lib/mindee/product/us/us_mail/us_mail_v3_recipient_addresses.rb b/lib/mindee/product/us/us_mail/us_mail_v3_recipient_addresses.rb new file mode 100644 index 00000000..1a2e4e8f --- /dev/null +++ b/lib/mindee/product/us/us_mail/us_mail_v3_recipient_addresses.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require_relative 'us_mail_v3_sender_address' +require_relative 'us_mail_v3_recipient_address' + +module Mindee + module Product + module US + module UsMail + # The addresses of the recipients. + class UsMailV3RecipientAddresses < Array + # Entries. + # @return [Array] + attr_reader :entries + + # @param prediction [Array] + # @param page_id [Integer, nil] + def initialize(prediction, page_id) + entries = prediction.map do |entry| + UsMail::UsMailV3RecipientAddress.new(entry, page_id) + end + super(entries) + end + + # Creates a line of rST table-compliant string separators. + # @param char [String] Character to use as a separator. + # @return [String] + def self.line_items_separator(char) + out_str = String.new + out_str << "+#{char * 17}" + out_str << "+#{char * 37}" + out_str << "+#{char * 19}" + out_str << "+#{char * 13}" + out_str << "+#{char * 24}" + out_str << "+#{char * 7}" + out_str << "+#{char * 27}" + out_str << "+#{char * 17}" + out_str + end + + # @return [String] + def to_s + return '' if empty? + + lines = map do |entry| + "\n #{entry.to_table_line}\n#{self.class.line_items_separator('-')}" + end.join + out_str = String.new + out_str << ("\n#{self.class.line_items_separator('-')}\n ") + out_str << ' | City ' + out_str << ' | Complete Address ' + out_str << ' | Is Address Change' + out_str << ' | Postal Code' + out_str << ' | Private Mailbox Number' + out_str << ' | State' + out_str << ' | Street ' + out_str << ' | Unit ' + out_str << (" |\n#{self.class.line_items_separator('=')}") + out_str + lines + end + end + end + end + end +end diff --git a/lib/mindee/product/us/us_mail/us_mail_v3_sender_address.rb b/lib/mindee/product/us/us_mail/us_mail_v3_sender_address.rb index 14353d0e..0777c21f 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v3_sender_address.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v3_sender_address.rb @@ -28,7 +28,7 @@ class UsMailV3SenderAddress < Mindee::Parsing::Standard::FeatureField # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction, page_id) + super @city = prediction['city'] @complete = prediction['complete'] @postal_code = prediction['postal_code'] diff --git a/lib/mindee/product/us/w9/w9_v1.rb b/lib/mindee/product/us/w9/w9_v1.rb index c6aee79d..dcafdaa0 100644 --- a/lib/mindee/product/us/w9/w9_v1.rb +++ b/lib/mindee/product/us/w9/w9_v1.rb @@ -13,16 +13,16 @@ module W9 class W9V1 < Mindee::Parsing::Common::Inference @endpoint_name = 'us_w9' @endpoint_version = '1' + @has_async = false + @has_sync = true # @param prediction [Hash] def initialize(prediction) super - @prediction = W9V1Document.new + @prediction = W9V1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| - if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(W9V1Page.new(page)) - end + @pages.push(W9V1Page.new(page)) end end @@ -33,6 +33,12 @@ class << self # Version for this product. # @return [String] attr_reader :endpoint_version + # Whether this product has access to an asynchronous endpoint. + # @return [bool] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [bool] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/us/w9/w9_v1_page.rb b/lib/mindee/product/us/w9/w9_v1_page.rb index 5f1b8521..e2c17d8f 100644 --- a/lib/mindee/product/us/w9/w9_v1_page.rb +++ b/lib/mindee/product/us/w9/w9_v1_page.rb @@ -11,11 +11,15 @@ module W9 class W9V1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) - @prediction = W9V1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + super + @prediction = if prediction['prediction'].empty? + nil + else + W9V1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end @@ -63,19 +67,46 @@ class W9V1PagePrediction < W9V1Document # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - @address = StringField.new(prediction['address'], page_id) - @business_name = StringField.new(prediction['business_name'], page_id) - @city_state_zip = StringField.new(prediction['city_state_zip'], page_id) - @ein = StringField.new(prediction['ein'], page_id) - @name = StringField.new(prediction['name'], page_id) - @signature_date_position = PositionField.new(prediction['signature_date_position'], page_id) - @signature_position = PositionField.new(prediction['signature_position'], page_id) - @ssn = StringField.new(prediction['ssn'], page_id) - @tax_classification = StringField.new(prediction['tax_classification'], page_id) - @tax_classification_llc = StringField.new(prediction['tax_classification_llc'], page_id) - @tax_classification_other_details = StringField.new(prediction['tax_classification_other_details'], page_id) - @w9_revision_date = StringField.new(prediction['w9_revision_date'], page_id) - super() + @address = Parsing::Standard::StringField.new( + prediction['address'], + page_id + ) + @business_name = Parsing::Standard::StringField.new( + prediction['business_name'], + page_id + ) + @city_state_zip = Parsing::Standard::StringField.new( + prediction['city_state_zip'], + page_id + ) + @ein = Parsing::Standard::StringField.new(prediction['ein'], page_id) + @name = Parsing::Standard::StringField.new(prediction['name'], page_id) + @signature_date_position = Parsing::Standard::PositionField.new( + prediction['signature_date_position'], + page_id + ) + @signature_position = Parsing::Standard::PositionField.new( + prediction['signature_position'], + page_id + ) + @ssn = Parsing::Standard::StringField.new(prediction['ssn'], page_id) + @tax_classification = Parsing::Standard::StringField.new( + prediction['tax_classification'], + page_id + ) + @tax_classification_llc = Parsing::Standard::StringField.new( + prediction['tax_classification_llc'], + page_id + ) + @tax_classification_other_details = Parsing::Standard::StringField.new( + prediction['tax_classification_other_details'], + page_id + ) + @w9_revision_date = Parsing::Standard::StringField.new( + prediction['w9_revision_date'], + page_id + ) + super end # @return [String] diff --git a/lib/mindee/version.rb b/lib/mindee/version.rb index ef1ad60c..9aa6656e 100644 --- a/lib/mindee/version.rb +++ b/lib/mindee/version.rb @@ -6,7 +6,7 @@ module Mindee VERSION = '3.20.0' # Finds and return the current platform. - # @return [String] + # @return [Symbol, Hash[Symbol | String, Regexp], Nil?] def self.find_platform host = RbConfig::CONFIG['host_os'] platforms = { diff --git a/mindee.gemspec b/mindee.gemspec index a1f43493..4abc776c 100644 --- a/mindee.gemspec +++ b/mindee.gemspec @@ -6,20 +6,18 @@ Gem::Specification.new do |spec| spec.name = 'mindee' spec.version = Mindee::VERSION spec.authors = ['Mindee, SA'] - spec.email = ['devrel@mindee.co'] + spec.email = ['opensource@mindee.co'] spec.summary = 'Mindee API Helper Library for Ruby' spec.description = "Quickly and easily connect to Mindee's API services using Ruby." spec.homepage = 'https://github.com/mindee/mindee-api-ruby' spec.license = 'MIT' - spec.metadata['homepage_uri'] = 'https://mindee.com/' - spec.metadata['source_code_uri'] = 'https://github.com/mindee/mindee-api-ruby' - spec.metadata['changelog_uri'] = 'https://github.com/mindee/mindee-api-ruby/blob/main/CHANGELOG.md' + spec.metadata['homepage_uri'] = 'https://mindee.com/' + spec.metadata['source_code_uri'] = 'https://github.com/mindee/mindee-api-ruby' + spec.metadata['changelog_uri'] = 'https://github.com/mindee/mindee-api-ruby/blob/main/CHANGELOG.md' spec.metadata['rubygems_mfa_required'] = 'true' - # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(.github|spec|features)/}) } end @@ -27,15 +25,19 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.required_ruby_version = Gem::Requirement.new('>= 2.6') - - spec.add_runtime_dependency 'marcel', '~> 1.0.2' - spec.add_runtime_dependency 'mini_magick', '>=4', '< 6' - spec.add_runtime_dependency 'origamindee', '~> 3.1.0' - spec.add_runtime_dependency 'pdf-reader', '~> 2.12.0' - - spec.add_development_dependency 'rake', '~> 12.3.3' - spec.add_development_dependency 'rspec', '~> 3.12.0' - spec.add_development_dependency 'rubocop', '~> 1.49.0' - spec.add_development_dependency 'yard', '~> 0.9.34' + spec.required_ruby_version = Gem::Requirement.new('>= 3.0') + + spec.add_dependency 'base64', '~> 0.1.0' + spec.add_dependency 'marcel', '~> 1.0.4' + spec.add_dependency 'mini_magick', '>= 4', '< 6' + spec.add_dependency 'origamindee', '~> 4.0.0' + spec.add_dependency 'pdf-reader', '~> 2.13.0' + + spec.add_development_dependency 'prism', '~> 1.3' + spec.add_development_dependency 'rake', '~> 13.2.1' + spec.add_development_dependency 'rbs', '~> 3.6' + spec.add_development_dependency 'rspec', '~> 3.13.0' + spec.add_development_dependency 'rubocop', '~> 1.70.0' + spec.add_development_dependency 'steep', '~> 1.7.1' + spec.add_development_dependency 'yard', '~> 0.9.37' end diff --git a/sig/custom/marcel.rbs b/sig/custom/marcel.rbs new file mode 100644 index 00000000..d7834736 --- /dev/null +++ b/sig/custom/marcel.rbs @@ -0,0 +1,3 @@ +module Marcel + MimeType: untyped +end \ No newline at end of file diff --git a/sig/custom/mini_magick.rbs b/sig/custom/mini_magick.rbs new file mode 100644 index 00000000..d52fbfad --- /dev/null +++ b/sig/custom/mini_magick.rbs @@ -0,0 +1,24 @@ +# Stub for the mini_magick library. +module MiniMagick + class Image + def format: (String, ?Integer?, ?Hash[Symbol, untyped]?) -> Net::BufferedIO + def self.format: (String, ?Integer?, ?Hash[Symbol, untyped]?) -> Net::BufferedIO + def self.quality: (String) -> Net::BufferedIO + def self.crop: (String) -> Net::BufferedIO + def self.height: () -> Integer + def height: () -> Integer + def self.width: () -> Integer + def width: () -> Integer + def self.read: (untyped) -> self + def self.resolution: () -> Array[Float | Integer] + def self.write: (StringIO | String) -> Net::BufferedIO + def write: (StringIO | String) -> Net::BufferedIO + def quality: (Integer) -> void + def self.resize: (String) -> void + def resize: (String) -> void + def self.to_blob: () -> String + def to_blob: () -> String + def self.[]: (?untyped) -> untyped + def []: (?untyped) -> untyped + end +end \ No newline at end of file diff --git a/sig/custom/net_http.rbs b/sig/custom/net_http.rbs new file mode 100644 index 00000000..e842655a --- /dev/null +++ b/sig/custom/net_http.rbs @@ -0,0 +1,34 @@ +# This is a stub of mock type declarations for the net/http standard library, which isn't +# currently supported by Steep. +# Do not mess with it unless Steep fixes the handling of this library. + +module Net + class BufferedIO + end + class HTTP + def self.start: [T] (String?, Integer?, use_ssl: bool?, ?read_timeout: Integer) { (HTTP) -> T } -> T + + def request: (untyped) -> untyped + + # Stub for the HTTP POST request class. + class Post + def initialize: (untyped, Hash[String, String]?) -> void + def set_form: (untyped, String?) -> void + def new: (untyped, untyped) -> void + end + + # Stub for the HTTP GET request class. + class Get + def initialize: (untyped, ?Hash[String, String]?) -> void + def new: (untyped, untyped) -> void + def basic_auth: (untyped, untyped) -> void + def []=: (?untyped, ?untyped) -> bool + end + end + + class HTTPRedirection + def []: (untyped) -> untyped + def body: -> untyped + def code: -> String? + end +end \ No newline at end of file diff --git a/sig/custom/origami.rbs b/sig/custom/origami.rbs new file mode 100644 index 00000000..2f9b1e4e --- /dev/null +++ b/sig/custom/origami.rbs @@ -0,0 +1,54 @@ +# Stubs for the origami library. +# This one _should_ exist, but it would take too long, so this is a stub. +module Origami + class Array + def each: { (untyped) -> untyped } -> untyped + end + class PDF + def self.read: (StringIO) -> untyped + def initialize: () -> void + def append_page: (Page) -> void + def delete_pages_at: (::Array[Integer]) -> void + def pages: () -> untyped + def save: (StringIO) -> void + def to_io_stream: -> StringIO + class LinearParser + def initialize: (Hash[Symbol, untyped]) -> void + def new: (Hash[Symbol, untyped]) -> void + def parse: (StringIO?) -> PDF + end + end + + class Page + def initialize: () -> void + def add_xobject: (Graphics::ImageXObject, String) -> untyped + def Contents: (?untyped?) -> untyped + end + + module Graphics + class ImageXObject + def initialize: () -> void + + def BitsPerComponent=: (Integer) -> untyped + def ColorSpace=: (Symbol) -> untyped + def data=: (StringIO) -> untyped + def self.from_image_file: (StringIO, String) -> untyped + def Height=: (Integer | Float) -> untyped + def Width=: (Integer | Float) -> untyped + end + end + + class InvalidPDFError < StandardError + end + + class Parser + VERBOSE_QUIET: String + end + + class Stream + def initialize: (?String) -> untyped + def data : () -> untyped + def data= : (String | StringIO) -> void + def dictionary : -> Hash[Symbol, untyped] + end +end \ No newline at end of file diff --git a/sig/mindee.rbs b/sig/mindee.rbs new file mode 100644 index 00000000..927d1ddb --- /dev/null +++ b/sig/mindee.rbs @@ -0,0 +1,59 @@ +class Object + private + def logger: -> Logger +end + +module Mindee + module Errors + end + + module Extraction + end + + module HTTP + end + + module PDF + end + + module Input + module Source + end + end + + module Image + module ImageUtils + end + + module ImageCompressor + end + end + + module Logging + end + + module Parsing + module Common + end + + module Standard + end + + module Universal + end + end + + module Product + module EU + end + + module FR + end + + module IND + end + + module US + end + end +end diff --git a/sig/mindee/client.rbs b/sig/mindee/client.rbs new file mode 100644 index 00000000..d74002a0 --- /dev/null +++ b/sig/mindee/client.rbs @@ -0,0 +1,63 @@ +OTS_OWNER: String + +module Mindee + OTS_OWNER: String + + class PageOptions + attr_accessor page_indexes: Array[Integer] + attr_accessor operation: :KEEP_ONLY | :REMOVE + attr_accessor on_min_pages: Integer? + + def initialize: (params: Hash[Symbol | String, untyped]) -> void + end + + class ParseOptions + attr_accessor all_words: bool + attr_accessor full_text: bool + attr_accessor close_file: bool + attr_accessor page_options: PageOptions + attr_accessor cropper: bool + attr_accessor initial_delay_sec: Integer | Float + attr_accessor delay_sec: Integer | Float + attr_accessor max_retries: Integer + + def initialize: (params: Hash[Symbol | String, untyped]) -> void + end + + class WorkflowOptions + attr_accessor document_alias: (String?) + attr_accessor priority: (Symbol?) + attr_accessor full_text: bool + attr_accessor public_url: (String?) + attr_accessor page_options: (PageOptions) + + def initialize: (params: Hash[Symbol | String, untyped]) -> void + end + + class Client + def initialize: (api_key: String) -> void + def logger: () -> untyped + def parse: (Input::Source::LocalInputSource | Input::Source::URLInputSource, untyped, ?endpoint: (HTTP::Endpoint?), options: ParseOptions | Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse + def parse_sync: (Input::Source::LocalInputSource | Input::Source::URLInputSource, untyped, HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse + def enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, untyped, ?endpoint: (HTTP::Endpoint?), options: ParseOptions|Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse + def parse_queued: (String, singleton(Parsing::Common::Inference), ?endpoint: HTTP::Endpoint?) -> Parsing::Common::ApiResponse + def enqueue_and_parse: (Input::Source::URLInputSource|Input::Source::LocalInputSource, untyped, HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse + def execute_workflow: (Input::Source::URLInputSource|Input::Source::LocalInputSource, String, options: (Hash[Symbol | String, untyped] | WorkflowOptions)) -> Parsing::Common::WorkflowResponse + def load_prediction: (singleton(Parsing::Common::Inference), Input::LocalResponse) -> Parsing::Common::ApiResponse + def source_from_path: (String, ?repair_pdf: bool) -> Input::Source::PathInputSource + def source_from_bytes: (String, String, ?repair_pdf: bool) -> Input::Source::BytesInputSource + def source_from_b64string: (String, String, ?repair_pdf: bool) -> Input::Source::Base64InputSource + def source_from_file: (File, String, ?repair_pdf: bool) -> Input::Source::FileInputSource + def source_from_url: (String) -> Input::Source::URLInputSource + def create_endpoint: (endpoint_name: String, account_name: String, version: String) -> HTTP::Endpoint + + private + def normalize_parse_options: ((Hash[Symbol | String, untyped] | ParseOptions)) -> ParseOptions + def process_pdf_if_required: (Input::Source::LocalInputSource, ParseOptions | WorkflowOptions) -> void + def initialize_endpoint: (singleton(Parsing::Common::Inference), ?endpoint_name: String, ?account_name: String, ?version: String) -> HTTP::Endpoint + def validate_async_params: (Integer | Float, Integer | Float, Integer) -> void + def fix_endpoint_name: (singleton(Parsing::Common::Inference), String?) -> String? + def fix_account_name: (String) -> String + def fix_version: (singleton(Parsing::Common::Inference), String) -> String + end +end diff --git a/sig/mindee/errors/mindee_error.rbs b/sig/mindee/errors/mindee_error.rbs new file mode 100644 index 00000000..10dac7a6 --- /dev/null +++ b/sig/mindee/errors/mindee_error.rbs @@ -0,0 +1,13 @@ +# lib/mindee/errors/mindee_error.rb +module Mindee + module Errors + class MindeeError < StandardError + end + class MindeeAPIError < MindeeError + end + class MindeeConfigurationError < MindeeError + end + class MindeeGeometryError < MindeeError + end + end +end diff --git a/sig/mindee/errors/mindee_http_error.rbs b/sig/mindee/errors/mindee_http_error.rbs new file mode 100644 index 00000000..29eaedc0 --- /dev/null +++ b/sig/mindee/errors/mindee_http_error.rbs @@ -0,0 +1,16 @@ +# lib/mindee/errors/mindee_http_error.rb +module Mindee + module Errors + class MindeeHTTPError < Errors::MindeeError + def status_code: -> untyped + def api_code: -> untyped + def api_details: -> untyped + def api_message: -> untyped + def initialize: (untyped, untyped, untyped) -> untyped + end + class MindeeHTTPClientError < MindeeHTTPError + end + class MindeeHTTPServerError < MindeeHTTPError + end + end +end diff --git a/sig/mindee/errors/mindee_input_error.rbs b/sig/mindee/errors/mindee_input_error.rbs new file mode 100644 index 00000000..170440e0 --- /dev/null +++ b/sig/mindee/errors/mindee_input_error.rbs @@ -0,0 +1,17 @@ +# lib/mindee/errors/mindee_input_error.rb +module Mindee + module Errors + class MindeeInputError < MindeeError + end + class MindeeSourceError < MindeeInputError + end + class MindeeMimeTypeError < MindeeSourceError + def invalid_mimetype: -> untyped + def initialize: (untyped) -> untyped + end + class MindeeImageError < MindeeInputError + end + class MindeePDFError < MindeeInputError + end + end +end diff --git a/sig/mindee/extraction/multi_receipts_extractor.rbs b/sig/mindee/extraction/multi_receipts_extractor.rbs new file mode 100644 index 00000000..ee8c191a --- /dev/null +++ b/sig/mindee/extraction/multi_receipts_extractor.rbs @@ -0,0 +1,6 @@ +# lib/mindee/extraction/multi_receipts_extractor.rb +module Mindee + module Extraction + def self.extract_receipts: (untyped, untyped) -> Array[untyped] + end +end diff --git a/sig/mindee/geometry/min_max.rbs b/sig/mindee/geometry/min_max.rbs new file mode 100644 index 00000000..9735cd3b --- /dev/null +++ b/sig/mindee/geometry/min_max.rbs @@ -0,0 +1,10 @@ +# lib/mindee/geometry/min_max.rb +module Mindee + module Geometry + class MinMax + def min: -> untyped + def max: -> untyped + def initialize: (untyped, untyped) -> untyped + end + end +end diff --git a/sig/mindee/geometry/point.rbs b/sig/mindee/geometry/point.rbs new file mode 100644 index 00000000..edbb9f78 --- /dev/null +++ b/sig/mindee/geometry/point.rbs @@ -0,0 +1,13 @@ +# lib/mindee/geometry/point.rb +module Mindee + module Geometry + class Point + def x: -> untyped + def x=: (untyped) -> untyped + def y: -> untyped + def y=: (untyped) -> untyped + def initialize: (untyped, untyped) -> untyped + def []: (untyped) -> bot + end + end +end diff --git a/sig/mindee/geometry/polygon.rbs b/sig/mindee/geometry/polygon.rbs new file mode 100644 index 00000000..5100a56f --- /dev/null +++ b/sig/mindee/geometry/polygon.rbs @@ -0,0 +1,9 @@ +# lib/mindee/geometry/polygon.rb +module Mindee + module Geometry + class Polygon < Array[untyped] + def centroid: -> untyped + def point_in_y?: (untyped) -> untyped + end + end +end diff --git a/sig/mindee/geometry/quadrilateral.rbs b/sig/mindee/geometry/quadrilateral.rbs new file mode 100644 index 00000000..421ce916 --- /dev/null +++ b/sig/mindee/geometry/quadrilateral.rbs @@ -0,0 +1,18 @@ +# lib/mindee/geometry/quadrilateral.rb +module Mindee + module Geometry + class Quadrilateral + def top_left: -> Point + def top_left=: (Point) -> bool + def top_right: -> Point + def top_right=: (Point) -> untyped + def bottom_right: -> Point + def bottom_right=: (Point) -> untyped + def bottom_left: -> Point + def bottom_left=: (Point) -> untyped + def initialize: (Point, Point, Point, Point) -> void + def []: (Integer) -> Point + def size: -> Integer + end + end +end diff --git a/sig/mindee/geometry/utils.rbs b/sig/mindee/geometry/utils.rbs new file mode 100644 index 00000000..cfb2f36b --- /dev/null +++ b/sig/mindee/geometry/utils.rbs @@ -0,0 +1,13 @@ +# lib/mindee/geometry/utils.rb +module Mindee + module Geometry + def self.quadrilateral_from_prediction: (untyped) -> untyped + def self.polygon_from_prediction: (untyped) -> untyped + def self.get_bbox: (untyped) -> [untyped, untyped, untyped, untyped] + def self.get_bounding_box: (untyped) -> Quadrilateral + def self.get_centroid: (untyped) -> untyped + def self.get_min_max_y: (untyped) -> untyped + def self.get_min_max_x: (untyped) -> untyped + def self.below?: (untyped, untyped, untyped, untyped) -> bool + end +end diff --git a/sig/mindee/http/endpoint.rbs b/sig/mindee/http/endpoint.rbs new file mode 100644 index 00000000..39a57dc0 --- /dev/null +++ b/sig/mindee/http/endpoint.rbs @@ -0,0 +1,26 @@ +# lib/mindee/http/endpoint.rb +module Mindee + module HTTP + API_KEY_ENV_NAME: String + API_KEY_DEFAULT: nil + BASE_URL_ENV_NAME: String + BASE_URL_DEFAULT: String + REQUEST_TIMEOUT_ENV_NAME: String + TIMEOUT_DEFAULT: Integer + USER_AGENT: String + class Endpoint + def logger: () -> untyped + def api_key: -> String? + def request_timeout: -> Integer + def url_root: -> String + def initialize: (untyped, untyped, untyped, ?api_key: String) -> String + def predict: (untyped, untyped, untyped, untyped, untyped) -> [untyped, untyped] + def predict_async: (untyped, untyped, untyped, untyped, untyped) -> [untyped, untyped] + def parse_async: (untyped) -> [untyped, untyped] + def predict_req_post: (untyped, ?all_words: false, ?full_text: false, ?close_file: true, ?cropper: false) -> untyped + def document_queue_req_get: (untyped, untyped, untyped, untyped, untyped) -> untyped + def document_queue_req: (untyped) -> untyped + def check_api_key: -> nil + end + end +end diff --git a/sig/mindee/http/http_error_handler.rbs b/sig/mindee/http/http_error_handler.rbs new file mode 100644 index 00000000..3a138830 --- /dev/null +++ b/sig/mindee/http/http_error_handler.rbs @@ -0,0 +1,10 @@ +# lib/mindee/http/http_error_handler.rb +module Mindee + module HTTP + module ErrorHandler + def extract_error: (untyped) -> nil + def create_error_obj: (untyped) -> (Hash[String, String] | Hash[untyped, untyped])? + def self.handle_error: (untyped, untyped) -> untyped + end + end +end diff --git a/sig/mindee/http/response_validation.rbs b/sig/mindee/http/response_validation.rbs new file mode 100644 index 00000000..91c43939 --- /dev/null +++ b/sig/mindee/http/response_validation.rbs @@ -0,0 +1,10 @@ +# lib/mindee/http/response_validation.rb +module Mindee + module HTTP + module ResponseValidation + def self.valid_sync_response?: (untyped) -> bool + def self.valid_async_response?: (untyped) -> bool + def self.clean_request!: (untyped) -> nil + end + end +end diff --git a/sig/mindee/http/workflow_endpoint.rbs b/sig/mindee/http/workflow_endpoint.rbs new file mode 100644 index 00000000..4284c64a --- /dev/null +++ b/sig/mindee/http/workflow_endpoint.rbs @@ -0,0 +1,14 @@ +# lib/mindee/http/workflow_endpoint.rb +module Mindee + module HTTP + class WorkflowEndpoint + def api_key: -> String + def request_timeout: -> Integer + def url: -> String + def initialize: (untyped, ?api_key: String) -> String + def execute_workflow: (untyped, untyped, untyped, untyped, untyped) -> [untyped, untyped] + def workflow_execution_req_post: (untyped, untyped, untyped, untyped, untyped) -> untyped + def check_api_key: -> nil + end + end +end diff --git a/sig/mindee/image/extracted_image.rbs b/sig/mindee/image/extracted_image.rbs new file mode 100644 index 00000000..2ad71f56 --- /dev/null +++ b/sig/mindee/image/extracted_image.rbs @@ -0,0 +1,15 @@ +# lib/mindee/image/extracted_image.rb +module Mindee + module Image + class ExtractedImage + def logger: () -> untyped + def page_id: -> Integer + def element_id: -> Integer + def buffer: -> StringIO + def internal_file_name: -> String + def initialize: (Input::Source::LocalInputSource, Integer, Integer) -> Integer + def write_to_file: (String, ?String?) -> nil + def as_source: -> Input::Source::BytesInputSource + end + end +end diff --git a/sig/mindee/image/image_compressor.rbs b/sig/mindee/image/image_compressor.rbs new file mode 100644 index 00000000..dd4eda57 --- /dev/null +++ b/sig/mindee/image/image_compressor.rbs @@ -0,0 +1,8 @@ +# lib/mindee/image/image_compressor.rb +module Mindee + module Image + module ImageCompressor + def self.compress_image: (singleton(MiniMagick::Image) | MiniMagick::Image | StringIO, ?quality: Integer, ?max_width: Integer?, ?max_height: Integer?) -> StringIO + end + end +end diff --git a/sig/mindee/image/image_extractor.rbs b/sig/mindee/image/image_extractor.rbs new file mode 100644 index 00000000..a8fcb815 --- /dev/null +++ b/sig/mindee/image/image_extractor.rbs @@ -0,0 +1,13 @@ +# lib/mindee/image/image_extractor.rb +module Mindee + module Image + module ImageExtractor + def self.attach_image_as_new_file: (untyped, ?format: String) -> untyped + def self.to_blob: () -> String + def self.extract_multiple_images_from_source: (untyped, untyped, untyped) -> Array[untyped] + def self.extract_images_from_polygons: (untyped, untyped, untyped, untyped) -> Array[untyped] + def self.create_extracted_image: (StringIO, String, untyped, untyped) -> untyped + def self.load_input_source_pdf_page_as_stringio: (untyped, untyped) -> untyped + end + end +end diff --git a/sig/mindee/image/image_utils.rbs b/sig/mindee/image/image_utils.rbs new file mode 100644 index 00000000..24bdaa88 --- /dev/null +++ b/sig/mindee/image/image_utils.rbs @@ -0,0 +1,19 @@ +# lib/mindee/image/image_utils.rb +module Mindee + module Image + module ImageUtils + def self.resize_image: (singleton(MiniMagick::Image) | MiniMagick::Image, Integer, Integer) -> void + def self.compress_image_quality: (singleton(MiniMagick::Image) | MiniMagick::Image, untyped) -> untyped + def self.to_image: (singleton(MiniMagick::Image) | MiniMagick::Image | StringIO | IO | File | Tempfile?) -> (singleton(MiniMagick::Image) | MiniMagick::Image) + def self.image_to_stringio: (singleton(MiniMagick::Image) | MiniMagick::Image, ?String) -> StringIO + def self.calculate_new_dimensions: (singleton(MiniMagick::Image) | MiniMagick::Image, ?max_width: Integer | Float?, ?max_height: Integer | Float?) -> [Integer, Integer] + def self.calculate_dimensions_from_media_box: (singleton(MiniMagick::Image) | MiniMagick::Image, Array[Integer]?) -> [Integer, Integer] + def self.pdf_to_magick_image: (StringIO, Integer) -> singleton(MiniMagick::Image) + def self.normalize_polygon: (Geometry::Quadrilateral | Geometry::Polygon | Array[Geometry::Point]) -> Geometry::Quadrilateral + def self.read_page_content: (StringIO) -> singleton(MiniMagick::Image) + def self.crop_image: (singleton(MiniMagick::Image), Geometry::MinMax, Geometry::MinMax) -> singleton(MiniMagick::Image) + def self.write_image_to_buffer: (singleton(MiniMagick::Image) | MiniMagick::Image, StringIO) -> Net::BufferedIO + def self.determine_file_extension: (Input::Source::LocalInputSource) -> String? + end + end +end diff --git a/sig/mindee/input/local_response.rbs b/sig/mindee/input/local_response.rbs new file mode 100644 index 00000000..40306b8f --- /dev/null +++ b/sig/mindee/input/local_response.rbs @@ -0,0 +1,13 @@ +# lib/mindee/input/local_response.rb +module Mindee + module Input + class LocalResponse + def file: -> StringIO + def initialize: (untyped) -> Integer + def as_hash: -> nil + def self.process_secret_key: (untyped) -> untyped + def get_hmac_signature: (untyped) -> untyped + def valid_hmac_signature?: (untyped, untyped) -> untyped + end + end +end diff --git a/sig/mindee/input/sources/base64_input_source.rbs b/sig/mindee/input/sources/base64_input_source.rbs new file mode 100644 index 00000000..0ddae587 --- /dev/null +++ b/sig/mindee/input/sources/base64_input_source.rbs @@ -0,0 +1,11 @@ +# lib/mindee/input/sources/base64_input_source.rb +module Mindee + module Input + module Source + class Base64InputSource < LocalInputSource + def initialize: (String, String, ?repair_pdf: bool) -> void + def read_contents: (?close: bool) -> [String, String, Hash[Symbol, untyped]] + end + end + end +end diff --git a/sig/mindee/input/sources/bytes_input_source.rbs b/sig/mindee/input/sources/bytes_input_source.rbs new file mode 100644 index 00000000..a3e21b66 --- /dev/null +++ b/sig/mindee/input/sources/bytes_input_source.rbs @@ -0,0 +1,10 @@ +# lib/mindee/input/sources/bytes_input_source.rb +module Mindee + module Input + module Source + class BytesInputSource < LocalInputSource + def initialize: (String, String, ?repair_pdf: bool) -> void + end + end + end +end diff --git a/sig/mindee/input/sources/file_input_source.rbs b/sig/mindee/input/sources/file_input_source.rbs new file mode 100644 index 00000000..a3d4a713 --- /dev/null +++ b/sig/mindee/input/sources/file_input_source.rbs @@ -0,0 +1,10 @@ +# lib/mindee/input/sources/file_input_source.rb +module Mindee + module Input + module Source + class FileInputSource < LocalInputSource + def initialize: (File, String, ?repair_pdf: bool) -> void + end + end + end +end diff --git a/sig/mindee/input/sources/local_input_source.rbs b/sig/mindee/input/sources/local_input_source.rbs new file mode 100644 index 00000000..985fa780 --- /dev/null +++ b/sig/mindee/input/sources/local_input_source.rbs @@ -0,0 +1,24 @@ +# lib/mindee/input/sources/local_input_source.rb +module Mindee + module Input + module Source + ALLOWED_MIME_TYPES: Array[String] + class LocalInputSource + def filename: -> String + def file_mimetype: -> String + def io_stream: -> StringIO + def initialize: (StringIO | File, String, ?repair_pdf: bool) -> void + def logger: () -> untyped + def rescue_broken_pdf: (StringIO) -> StringIO + def pdf?: -> bool + def process_pdf: (PageOptions) -> StringIO? + def read_contents: (?close: bool) -> [String, String?, Hash[:filename, String]] + def count_pages: -> Integer + def write_to_file: (String) -> void + def compress!: (?quality: Integer, ?max_width: Integer?, ?max_height: Integer?, ?force_source_text: bool, ?disable_source_text: bool) -> Integer + def source_text?: -> bool? + end + def self.convert_to_unicode_escape: (String) -> String + end + end +end diff --git a/sig/mindee/input/sources/path_input_source.rbs b/sig/mindee/input/sources/path_input_source.rbs new file mode 100644 index 00000000..0e6dd7ba --- /dev/null +++ b/sig/mindee/input/sources/path_input_source.rbs @@ -0,0 +1,10 @@ +# lib/mindee/input/sources/path_input_source.rb +module Mindee + module Input + module Source + class PathInputSource < LocalInputSource + def initialize: (String, ?repair_pdf: bool) -> void + end + end + end +end diff --git a/sig/mindee/input/sources/url_input_source.rbs b/sig/mindee/input/sources/url_input_source.rbs new file mode 100644 index 00000000..93d08b5f --- /dev/null +++ b/sig/mindee/input/sources/url_input_source.rbs @@ -0,0 +1,20 @@ +# lib/mindee/input/sources/url_input_source.rb +module Mindee + module Input + module Source + class URLInputSource + def url: -> String + def logger: () -> untyped + def initialize: (String) -> void + def write_to_file: (String, ?filename: String?, ?username: String?, ?password: String?, ?token: String?, ?max_redirects: Integer) -> String + def as_local_input_source: (?filename: String?, ?username: String?, ?password: String?, ?token: String?, ?max_redirects: Integer) -> BytesInputSource? + def fetch_file_content: (?username: String?, ?password: String?, ?token: String?, ?max_redirects: Integer) -> String + def extract_filename_from_url: (::URI::File | ::URI::FTP | ::URI::HTTP | ::URI::HTTPS | ::URI::LDAP | ::URI::LDAPS | ::URI::MailTo | ::URI::WS | ::URI::WSS | ::URI::Generic) -> String + def fill_filename: (String?) -> String + def make_request: (URI::Generic, Net::HTTP::Get, Integer) -> Net::HTTPRedirection + def get_file_extension: (String) -> String? + def generate_file_name: (?extension: String?) -> String + end + end + end +end diff --git a/sig/mindee/logging/logger.rbs b/sig/mindee/logging/logger.rbs new file mode 100644 index 00000000..7ef7e112 --- /dev/null +++ b/sig/mindee/logging/logger.rbs @@ -0,0 +1,9 @@ +module Mindee + module Logging + @logger: Logger + + def self.logger: -> Logger + + def self.logger=: (Logger) -> Logger + end +end diff --git a/sig/mindee/parsing/common/api_request.rbs b/sig/mindee/parsing/common/api_request.rbs new file mode 100644 index 00000000..94bfebd0 --- /dev/null +++ b/sig/mindee/parsing/common/api_request.rbs @@ -0,0 +1,15 @@ +# lib/mindee/parsing/common/api_request.rb +module Mindee + module Parsing + module Common + class ApiRequest + def error: -> untyped + def ressources: -> untyped + def status: -> untyped + def status_code: -> untyped + def url: -> untyped + def initialize: (untyped) -> untyped + end + end + end +end diff --git a/sig/mindee/parsing/common/api_response.rbs b/sig/mindee/parsing/common/api_response.rbs new file mode 100644 index 00000000..0e4c7198 --- /dev/null +++ b/sig/mindee/parsing/common/api_response.rbs @@ -0,0 +1,27 @@ +# lib/mindee/parsing/common/api_response.rb +module Mindee + module Parsing + module Common + module JobStatus + WAITING: :waiting + PROCESSING: :processing + COMPLETED: :completed + FAILURE: :failed + end + module RequestStatus + FAILURE: :failure + SUCCESS: :success + end + + + class ApiResponse + def logger: () -> untyped + def document: -> Parsing::Common::Document? + def job: -> Parsing::Common::Job? + def api_request: -> Parsing::Common::ApiRequest? + def raw_http: -> String + def initialize: (singleton(Parsing::Common::Inference), Hash[Symbol | String, untyped], String) -> void + end + end + end +end diff --git a/sig/mindee/parsing/common/document.rbs b/sig/mindee/parsing/common/document.rbs new file mode 100644 index 00000000..f7a0cb65 --- /dev/null +++ b/sig/mindee/parsing/common/document.rbs @@ -0,0 +1,20 @@ +# lib/mindee/parsing/common/document.rb +module Mindee + module Parsing + module Common + class Document + def inference: -> untyped + def name: -> untyped + def id: -> untyped + def extras: -> nil + def ocr: -> nil + def n_pages: -> untyped + def self.load_ocr: (untyped) -> Parsing::Common::OCR::OCR? + def self.extract_extras: (untyped) -> Parsing::Common::Extras::Extras? + def initialize: (untyped, untyped) -> untyped + def to_s: -> String + def inject_full_text_ocr: (untyped) -> untyped + end + end + end +end diff --git a/sig/mindee/parsing/common/execution.rbs b/sig/mindee/parsing/common/execution.rbs new file mode 100644 index 00000000..18fc0a22 --- /dev/null +++ b/sig/mindee/parsing/common/execution.rbs @@ -0,0 +1,23 @@ +# lib/mindee/parsing/common/execution.rb +module Mindee + module Parsing + module Common + class Execution + def batch_name: -> untyped + def created_at: -> untyped + def file: -> untyped + def id: -> untyped + def inference: -> untyped + def priority: -> untyped + def reviewed_at: -> untyped + def available_at: -> untyped + def reviewed_prediction: -> untyped + def status: -> untyped + def type: -> untyped + def uploaded_at: -> untyped + def workflow_id: -> untyped + def initialize: (untyped, untyped) -> untyped + end + end + end +end diff --git a/sig/mindee/parsing/common/execution_file.rbs b/sig/mindee/parsing/common/execution_file.rbs new file mode 100644 index 00000000..9dd72a56 --- /dev/null +++ b/sig/mindee/parsing/common/execution_file.rbs @@ -0,0 +1,12 @@ +# lib/mindee/parsing/common/execution_file.rb +module Mindee + module Parsing + module Common + class ExecutionFile + def name: -> untyped + def alias: -> untyped + def initialize: (untyped) -> untyped + end + end + end +end diff --git a/sig/mindee/parsing/common/execution_priority.rbs b/sig/mindee/parsing/common/execution_priority.rbs new file mode 100644 index 00000000..b8a05329 --- /dev/null +++ b/sig/mindee/parsing/common/execution_priority.rbs @@ -0,0 +1,13 @@ +# lib/mindee/parsing/common/execution_priority.rb +module Mindee + module Parsing + module Common + module ExecutionPriority + LOW: :low + MEDIUM: :medium + HIGH: :high + def self.to_priority: (untyped) -> (:high | :low | :medium)? + end + end + end +end diff --git a/sig/mindee/parsing/common/extras/cropper_extra.rbs b/sig/mindee/parsing/common/extras/cropper_extra.rbs new file mode 100644 index 00000000..b2c9c16c --- /dev/null +++ b/sig/mindee/parsing/common/extras/cropper_extra.rbs @@ -0,0 +1,14 @@ +# lib/mindee/parsing/common/extras/cropper_extra.rb +module Mindee + module Parsing + module Common + module Extras + class CropperExtra + def croppings: -> Array[Standard::PositionField] + def initialize: (untyped, ?nil) -> untyped + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/parsing/common/extras/extras.rbs b/sig/mindee/parsing/common/extras/extras.rbs new file mode 100644 index 00000000..99303fe4 --- /dev/null +++ b/sig/mindee/parsing/common/extras/extras.rbs @@ -0,0 +1,18 @@ +# lib/mindee/parsing/common/extras/extras.rb +module Mindee + module Parsing + module Common + module Extras + class Extras + def cropper: -> untyped + def full_text_ocr: -> untyped + def initialize: (untyped) -> void + def new: (untyped) -> void + def to_s: -> String + def add_artificial_extra: (untyped) -> nil + end + def empty?: -> bool + end + end + end +end diff --git a/sig/mindee/parsing/common/extras/full_text_ocr_extra.rbs b/sig/mindee/parsing/common/extras/full_text_ocr_extra.rbs new file mode 100644 index 00000000..d78a0917 --- /dev/null +++ b/sig/mindee/parsing/common/extras/full_text_ocr_extra.rbs @@ -0,0 +1,15 @@ +# lib/mindee/parsing/common/extras/full_text_ocr_extra.rb +module Mindee + module Parsing + module Common + module Extras + class FullTextOCRExtra + def contents: -> untyped + def language: -> untyped + def initialize: (untyped) -> nil + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/parsing/common/inference.rbs b/sig/mindee/parsing/common/inference.rbs new file mode 100644 index 00000000..6b75aa71 --- /dev/null +++ b/sig/mindee/parsing/common/inference.rbs @@ -0,0 +1,19 @@ +# lib/mindee/parsing/common/inference.rb +module Mindee + module Parsing + module Common + class Inference + def is_rotation_applied: -> untyped + def pages: -> Array[Page] + def prediction: -> untyped + def product: -> untyped + def initialize: (untyped) -> void + def to_s: -> String + def self.endpoint_name: -> String + def self.endpoint_version: -> String + def self.has_async: -> bool + def self.has_sync: -> bool + end + end + end +end diff --git a/sig/mindee/parsing/common/job.rbs b/sig/mindee/parsing/common/job.rbs new file mode 100644 index 00000000..2b764519 --- /dev/null +++ b/sig/mindee/parsing/common/job.rbs @@ -0,0 +1,16 @@ +# lib/mindee/parsing/common/job.rb +module Mindee + module Parsing + module Common + class Job + def id: -> String + def issued_at: -> Time + def available_at: -> Time + def status: () -> (:waiting | :processing | :completed | :failed) + def millisecs_taken: -> Integer + def error: -> Hash[Symbol | String, untyped] + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/parsing/common/ocr/mvision_v1.rbs b/sig/mindee/parsing/common/ocr/mvision_v1.rbs new file mode 100644 index 00000000..e178c3e0 --- /dev/null +++ b/sig/mindee/parsing/common/ocr/mvision_v1.rbs @@ -0,0 +1,15 @@ +# lib/mindee/parsing/common/ocr/mvision_v1.rb +module Mindee + module Parsing + module Common + module OCR + class MVisionV1 + def pages: -> [] + def initialize: (untyped) -> untyped + def to_s: -> String + def reconstruct_vertically: (untyped, untyped, untyped) -> untyped + end + end + end + end +end diff --git a/sig/mindee/parsing/common/ocr/ocr.rbs b/sig/mindee/parsing/common/ocr/ocr.rbs new file mode 100644 index 00000000..dbf97e19 --- /dev/null +++ b/sig/mindee/parsing/common/ocr/ocr.rbs @@ -0,0 +1,39 @@ +# lib/mindee/parsing/common/ocr/ocr.rb +module Mindee + module Parsing + module Common + module OCR + class OCRWord + def confidence: -> untyped + def confidence=: (untyped) -> untyped + def text: -> untyped + def bounding_box: -> untyped + def polygon: -> untyped + def initialize: (untyped) -> void + def to_s: -> untyped + end + class OCRLine < Array[untyped] + def initialize: (?Array[untyped]?, ?Array[untyped]?) -> void + def sort_on_x: -> OCRLine + def to_s: -> String + end + class OCRPage + def all_words: -> Array[untyped] + def lines: -> Array[untyped] + def initialize: (untyped) -> untyped + def all_lines: -> Array[untyped] + def to_s: -> String + def parse_one: (Array[OCRWord], untyped, Array[untyped], Array[untyped]) -> Array[OCRLine]? + def to_lines: -> Array[untyped] + def words_on_same_line?: (OCRWord, OCRWord) -> untyped + end + class OCR + def mvision_v1: -> untyped + def initialize: (untyped) -> untyped + def to_s: -> untyped + def reconstruct_vertically: (untyped, untyped, ?Float) -> untyped + end + end + end + end +end diff --git a/sig/mindee/parsing/common/orientation.rbs b/sig/mindee/parsing/common/orientation.rbs new file mode 100644 index 00000000..1c789144 --- /dev/null +++ b/sig/mindee/parsing/common/orientation.rbs @@ -0,0 +1,12 @@ +# lib/mindee/parsing/common/orientation.rb +module Mindee + module Parsing + module Common + class Orientation + def page_id: -> untyped + def value: -> untyped + def initialize: (untyped, untyped) -> untyped + end + end + end +end diff --git a/sig/mindee/parsing/common/page.rbs b/sig/mindee/parsing/common/page.rbs new file mode 100644 index 00000000..b0149632 --- /dev/null +++ b/sig/mindee/parsing/common/page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/parsing/common/page.rb +module Mindee + module Parsing + module Common + class Page + def page_id: -> untyped + def orientation: -> untyped + def prediction: -> untyped + def extras: -> untyped + def initialize: (untyped) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/common/prediction.rbs b/sig/mindee/parsing/common/prediction.rbs new file mode 100644 index 00000000..20902f7c --- /dev/null +++ b/sig/mindee/parsing/common/prediction.rbs @@ -0,0 +1,11 @@ +# lib/mindee/parsing/common/prediction.rb +module Mindee + module Parsing + module Common + class Prediction + def to_s: -> String + def initialize: (untyped?, untyped?) -> void + end + end + end +end diff --git a/sig/mindee/parsing/common/product.rbs b/sig/mindee/parsing/common/product.rbs new file mode 100644 index 00000000..066b2577 --- /dev/null +++ b/sig/mindee/parsing/common/product.rbs @@ -0,0 +1,13 @@ +# lib/mindee/parsing/common/product.rb +module Mindee + module Parsing + module Common + class Product + def name: -> untyped + def type: -> untyped + def version: -> untyped + def initialize: (Hash[String, untyped]) -> untyped + end + end + end +end diff --git a/sig/mindee/parsing/common/workflow_response.rbs b/sig/mindee/parsing/common/workflow_response.rbs new file mode 100644 index 00000000..de4fd817 --- /dev/null +++ b/sig/mindee/parsing/common/workflow_response.rbs @@ -0,0 +1,13 @@ +# lib/mindee/parsing/common/workflow_response.rb +module Mindee + module Parsing + module Common + class WorkflowResponse + def execution: -> untyped + def api_request: -> untyped + def raw_http: -> untyped + def initialize: (untyped, untyped, untyped) -> untyped + end + end + end +end diff --git a/sig/mindee/parsing/standard/abstract_field.rbs b/sig/mindee/parsing/standard/abstract_field.rbs new file mode 100644 index 00000000..0374fa1e --- /dev/null +++ b/sig/mindee/parsing/standard/abstract_field.rbs @@ -0,0 +1,19 @@ +# lib/mindee/parsing/standard/abstract_field.rb +module Mindee + module Parsing + module Standard + class AbstractField + def bounding_box: -> Geometry::Polygon? + def polygon: -> Geometry::Polygon? + def page_id: -> Integer? + def confidence: -> Float? + def confidence=: (Float?) -> Float? + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + def self.array_confidence: (Array[untyped]) -> Float + def self.array_sum: (Array[untyped]) -> Float + def self.float_to_string: (Float, ?Integer) -> String + end + end + end +end diff --git a/sig/mindee/parsing/standard/amount_field.rbs b/sig/mindee/parsing/standard/amount_field.rbs new file mode 100644 index 00000000..8d7ba001 --- /dev/null +++ b/sig/mindee/parsing/standard/amount_field.rbs @@ -0,0 +1,12 @@ +# lib/mindee/parsing/standard/amount_field.rb +module Mindee + module Parsing + module Standard + class AmountField # failed to identify its superclass + def value: -> untyped + def initialize: (untyped, untyped, ?reconstructed: false) -> nil + def to_s: -> untyped + end + end + end +end diff --git a/sig/mindee/parsing/standard/base_field.rbs b/sig/mindee/parsing/standard/base_field.rbs new file mode 100644 index 00000000..a92fb08f --- /dev/null +++ b/sig/mindee/parsing/standard/base_field.rbs @@ -0,0 +1,12 @@ +# lib/mindee/parsing/standard/base_field.rb +module Mindee + module Parsing + module Standard + class BaseField < Parsing::Standard::AbstractField + def initialize: (Hash[Symbol | String, untyped], Integer?, ?reconstructed: bool) -> void + def value: -> (String | Float | Integer | bool) + def reconstructed: -> bool + end + end + end +end diff --git a/sig/mindee/parsing/standard/boolean_field.rbs b/sig/mindee/parsing/standard/boolean_field.rbs new file mode 100644 index 00000000..77fdeca6 --- /dev/null +++ b/sig/mindee/parsing/standard/boolean_field.rbs @@ -0,0 +1,12 @@ +# lib/mindee/parsing/standard/boolean_field.rb +module Mindee + module Parsing + module Standard + class BooleanField < BaseField + def value: -> bool? + def initialize: (Hash[Symbol | String, untyped], ?Integer?, ?reconstructed: false) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/standard/classification_field.rbs b/sig/mindee/parsing/standard/classification_field.rbs new file mode 100644 index 00000000..81cfd536 --- /dev/null +++ b/sig/mindee/parsing/standard/classification_field.rbs @@ -0,0 +1,10 @@ +# lib/mindee/parsing/standard/classification_field.rb +module Mindee + module Parsing + module Standard + class ClassificationField < BaseField + def value: -> String + end + end + end +end diff --git a/sig/mindee/parsing/standard/company_registration_field.rbs b/sig/mindee/parsing/standard/company_registration_field.rbs new file mode 100644 index 00000000..4e18c623 --- /dev/null +++ b/sig/mindee/parsing/standard/company_registration_field.rbs @@ -0,0 +1,14 @@ +# lib/mindee/parsing/standard/company_registration_field.rb +module Mindee + module Parsing + module Standard + class CompanyRegistrationField < BaseField + def type: -> untyped + def initialize: (untyped, untyped, ?reconstructed: false) -> untyped + def to_table_line: -> String + def to_s: -> String + def printable_values: -> Hash[String, untyped] + end + end + end +end diff --git a/sig/mindee/parsing/standard/date_field.rbs b/sig/mindee/parsing/standard/date_field.rbs new file mode 100644 index 00000000..e3b27680 --- /dev/null +++ b/sig/mindee/parsing/standard/date_field.rbs @@ -0,0 +1,14 @@ +# lib/mindee/parsing/standard/date_field.rb +module Mindee + module Parsing + module Standard + class DateField # failed to identify its superclass + def date_object: -> untyped + def value: -> untyped + def raw: -> untyped + def is_computed: -> untyped + def initialize: (untyped, untyped) -> nil + end + end + end +end diff --git a/sig/mindee/parsing/standard/feature_field.rbs b/sig/mindee/parsing/standard/feature_field.rbs new file mode 100644 index 00000000..863439e1 --- /dev/null +++ b/sig/mindee/parsing/standard/feature_field.rbs @@ -0,0 +1,10 @@ +# lib/mindee/parsing/standard/feature_field.rb +module Mindee + module Parsing + module Standard + class FeatureField < BaseField + def format_for_display: (String | bool?, ?Integer?) -> String + end + end + end +end diff --git a/sig/mindee/parsing/standard/locale_field.rbs b/sig/mindee/parsing/standard/locale_field.rbs new file mode 100644 index 00000000..d806cd77 --- /dev/null +++ b/sig/mindee/parsing/standard/locale_field.rbs @@ -0,0 +1,16 @@ +# lib/mindee/parsing/standard/locale_field.rb +module Mindee + module Parsing + module Standard + class LocaleField + def confidence: -> Float? + def language: -> String? + def country: -> String? + def currency: -> String? + def value: -> String? + def initialize: (Hash[Symbol | String, untyped], ?Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/standard/payment_details_field.rbs b/sig/mindee/parsing/standard/payment_details_field.rbs new file mode 100644 index 00000000..f2de2ee4 --- /dev/null +++ b/sig/mindee/parsing/standard/payment_details_field.rbs @@ -0,0 +1,15 @@ +# lib/mindee/parsing/standard/payment_details_field.rb +module Mindee + module Parsing + module Standard + class PaymentDetailsField # failed to identify its superclass + def account_number: -> untyped + def iban: -> untyped + def routing_number: -> untyped + def swift: -> untyped + def initialize: (untyped, untyped, ?reconstructed: false) -> untyped + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/standard/position_field.rbs b/sig/mindee/parsing/standard/position_field.rbs new file mode 100644 index 00000000..090df5c9 --- /dev/null +++ b/sig/mindee/parsing/standard/position_field.rbs @@ -0,0 +1,17 @@ +# lib/mindee/parsing/standard/position_field.rb +module Mindee + module Parsing + module Standard + class PositionField + def polygon: -> Geometry::Polygon + def value: -> Geometry::Polygon + def quadrangle: -> Geometry::Quadrilateral + def rectangle: -> Geometry::Quadrilateral + def bounding_box: -> Geometry::Quadrilateral + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + def to_quadrilateral: (Hash[Symbol | String, Array[untyped]], String) -> Geometry::Quadrilateral? + end + end + end +end diff --git a/sig/mindee/parsing/standard/string_field.rbs b/sig/mindee/parsing/standard/string_field.rbs new file mode 100644 index 00000000..9ff2314a --- /dev/null +++ b/sig/mindee/parsing/standard/string_field.rbs @@ -0,0 +1,12 @@ +# lib/mindee/parsing/standard/string_field.rb +module Mindee + module Parsing + module Standard + class StringField < BaseField + def value: -> String + def raw_value: -> String + def initialize: (Hash[Symbol | String, untyped], ?Integer?, ?reconstructed: bool) -> void + end + end + end +end diff --git a/sig/mindee/parsing/standard/tax_field.rbs b/sig/mindee/parsing/standard/tax_field.rbs new file mode 100644 index 00000000..0a62bfe5 --- /dev/null +++ b/sig/mindee/parsing/standard/tax_field.rbs @@ -0,0 +1,23 @@ +# lib/mindee/parsing/standard/tax_field.rb +module Mindee + module Parsing + module Standard + class TaxField < BaseField + def value: -> untyped + def rate: -> untyped + def code: -> untyped + def base: -> untyped + def initialize: (untyped, untyped) -> void + def print_float: (untyped) -> String + def to_s: -> String + def printable_values: -> Hash[untyped, String] + def to_table_line: -> String + end + class Taxes < Array[TaxField] + def initialize: (untyped, untyped) -> void + def line_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/universal/universal_list_field.rbs b/sig/mindee/parsing/universal/universal_list_field.rbs new file mode 100644 index 00000000..692cb141 --- /dev/null +++ b/sig/mindee/parsing/universal/universal_list_field.rbs @@ -0,0 +1,17 @@ +# lib/mindee/parsing/universal/universal_list_field.rb +module Mindee + module Parsing + module Universal + class UniversalListField + def page_id: -> Integer? + def page_id=: (Integer?) -> untyped + def values: -> Array[UniversalObjectField | Standard::StringField] + def values=: (Array[UniversalObjectField | Standard::StringField]) -> Array[UniversalObjectField | Standard::StringField] + def initialize: (Array[Hash[Symbol | String, untyped]], ?nil) -> untyped + def contents_list: -> Array[String] + def contents_string: (?String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/universal/universal_object_field.rbs b/sig/mindee/parsing/universal/universal_object_field.rbs new file mode 100644 index 00000000..5e97e672 --- /dev/null +++ b/sig/mindee/parsing/universal/universal_object_field.rbs @@ -0,0 +1,23 @@ +# lib/mindee/parsing/universal/universal_object_field.rb +module Mindee + module Parsing + module Universal + class UniversalObjectField + def page_id: -> Integer? + def page_id=: (Integer?) -> untyped + def confidence: -> Float? + def confidence=: (Float?) -> untyped + def raw_value: -> Hash[Symbol | String, untyped] + def raw_value=: (Hash[Symbol | String, untyped]) -> untyped + def initialize: (Hash[Symbol | String, untyped], ?Integer?) -> void + def str_level: (?Integer) -> String + def method_missing: (Symbol, *Array[untyped]) -> Object + def respond_to_missing?: (Symbol, ?bool) -> bool + def to_s: -> String + def handle_position_field: (String | Symbol, untyped, Integer?) -> void + def handle_default_field: (String | Symbol, untyped) -> void + end + def self.universal_object?: (Hash[Symbol | String, untyped]) -> bool + end + end +end diff --git a/sig/mindee/pdf/extracted_pdf.rbs b/sig/mindee/pdf/extracted_pdf.rbs new file mode 100644 index 00000000..ed76f17f --- /dev/null +++ b/sig/mindee/pdf/extracted_pdf.rbs @@ -0,0 +1,15 @@ +# lib/mindee/pdf/extracted_pdf.rb +module Mindee + module PDF + module PDFExtractor + class ExtractedPDF + def pdf_bytes: -> untyped + def filename: -> untyped + def initialize: (untyped, untyped) -> untyped + def page_count: -> nil + def write_to_file: (untyped, ?override: false) -> Integer + def as_input_source: -> untyped + end + end + end +end diff --git a/sig/mindee/pdf/pdf_compressor.rbs b/sig/mindee/pdf/pdf_compressor.rbs new file mode 100644 index 00000000..91e0bbfe --- /dev/null +++ b/sig/mindee/pdf/pdf_compressor.rbs @@ -0,0 +1,15 @@ +# lib/mindee/pdf/pdf_compressor.rb +PDFReader: untyped +PDF: untyped +module Mindee + module PDF + module PDFCompressor + def self.logger: () -> untyped + def self.compress_pdf: (StringIO, ?quality: Integer, ?force_source_text_compression: bool, ?disable_source_text: bool) -> StringIO + def self.process_pdf_pages: (Origami::PDF, Integer) -> Array[Origami::Page] + def self.create_output_pdf: (Array[Origami::Page], bool, StringIO) -> Origami::PDF + def self.inject_text: (StringIO, Array[Origami::Page]) -> nil + def self.process_pdf_page: (StringIO, Integer, Integer, Array[Integer]?) -> Origami::Page + end + end +end diff --git a/sig/mindee/pdf/pdf_extractor.rbs b/sig/mindee/pdf/pdf_extractor.rbs new file mode 100644 index 00000000..5199ffc3 --- /dev/null +++ b/sig/mindee/pdf/pdf_extractor.rbs @@ -0,0 +1,16 @@ +# lib/mindee/pdf/pdf_extractor.rb +module Mindee + module PDF + module PDFExtractor + class PDFExtractor + def initialize: (untyped) -> StringIO + def page_count: -> untyped + def cut_pages: (Array[untyped]) -> untyped + def extract_sub_documents: (Array[untyped]) -> Array[untyped] + def extract_invoices: (untyped, ?strict: false) -> Array[untyped] + def source_pdf: -> StringIO + def filename: -> untyped + end + end + end +end diff --git a/sig/mindee/pdf/pdf_processor.rbs b/sig/mindee/pdf/pdf_processor.rbs new file mode 100644 index 00000000..3697527a --- /dev/null +++ b/sig/mindee/pdf/pdf_processor.rbs @@ -0,0 +1,12 @@ +# lib/mindee/pdf/pdf_processor.rb +module Mindee + module PDF + module PDFProcessor + def self.parse: (StringIO, PageOptions) -> StringIO + def self.indexes_from_keep: (Array[Integer], Array[untyped]) -> (Array[Integer] | Array[untyped]) + def self.indexes_from_remove: (Array[Integer], Array[untyped]) -> (Array[Integer] | Array[untyped]) + def self.open_pdf: (StringIO) -> Origami::PDF + def self.get_page: (Origami::PDF, Integer) -> StringIO + end + end +end diff --git a/sig/mindee/pdf/pdf_tools.rbs b/sig/mindee/pdf/pdf_tools.rbs new file mode 100644 index 00000000..5e96d9f3 --- /dev/null +++ b/sig/mindee/pdf/pdf_tools.rbs @@ -0,0 +1,23 @@ +# lib/mindee/pdf/pdf_tools.rb +module Mindee + module PDF + module PDFTools + def to_io_stream: (?Hash[untyped, untyped]) -> StringIO + def self.stream_has_text?: (untyped) -> bool + def self.source_text?: (untyped) -> bool? + def self.create_xobject: (untyped) -> untyped + def self.set_xobject_properties: (untyped, untyped) -> untyped + def self.determine_filter: (untyped) -> (:DCTDecode | :FlateDecode | :LZWDecode) + def self.determine_colorspace: (untyped) -> (:DeviceCMYK | :DeviceGray | :DeviceRGB) + def self.add_content_to_page: (untyped, untyped, untyped, untyped) -> untyped + def compile: (untyped) -> untyped + def intents_as_pdfa1: () -> untyped + def delinearize!: () -> untyped + def linearized?: () -> untyped + def load_all_objects: () -> untyped + def output: (untyped) -> untyped + def self.set_page_dimensions: (untyped, untyped, untyped) -> untyped + def self.process_image_xobject: (untyped, untyped, untyped, untyped) -> untyped + end + end +end diff --git a/sig/mindee/product/barcode_reader/barcode_reader_v1.rbs b/sig/mindee/product/barcode_reader/barcode_reader_v1.rbs new file mode 100644 index 00000000..f92cb485 --- /dev/null +++ b/sig/mindee/product/barcode_reader/barcode_reader_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/barcode_reader/barcode_reader_v1.rb + +module Mindee + module Product + module BarcodeReader + class BarcodeReaderV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/barcode_reader/barcode_reader_v1_document.rbs b/sig/mindee/product/barcode_reader/barcode_reader_v1_document.rbs new file mode 100644 index 00000000..a0c77046 --- /dev/null +++ b/sig/mindee/product/barcode_reader/barcode_reader_v1_document.rbs @@ -0,0 +1,14 @@ +# lib/mindee/product/barcode_reader/barcode_reader_v1_document.rb + +module Mindee + module Product + module BarcodeReader + class BarcodeReaderV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def codes_1d: -> (Array[Parsing::Standard::StringField]) + def codes_2d: -> (Array[Parsing::Standard::StringField]) + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/barcode_reader/barcode_reader_v1_page.rbs b/sig/mindee/product/barcode_reader/barcode_reader_v1_page.rbs new file mode 100644 index 00000000..a32b8ad7 --- /dev/null +++ b/sig/mindee/product/barcode_reader/barcode_reader_v1_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb + +module Mindee + module Product + module BarcodeReader + class BarcodeReaderV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class BarcodeReaderV1PagePrediction < BarcodeReaderV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/bill_of_lading/bill_of_lading_v1.rbs b/sig/mindee/product/bill_of_lading/bill_of_lading_v1.rbs new file mode 100644 index 00000000..e5ec9295 --- /dev/null +++ b/sig/mindee/product/bill_of_lading/bill_of_lading_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/bill_of_lading/bill_of_lading_v1.rb + +module Mindee + module Product + module BillOfLading + class BillOfLadingV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rbs b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rbs new file mode 100644 index 00000000..53f1a000 --- /dev/null +++ b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module BillOfLading + class BillOfLadingV1Carrier < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def name: -> String + def professional_number: -> String + def scac: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rbs b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rbs new file mode 100644 index 00000000..d043b7f7 --- /dev/null +++ b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rbs @@ -0,0 +1,19 @@ +module Mindee + module Product + module BillOfLading + class BillOfLadingV1CarrierItem < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def description: -> String + def gross_weight: -> Float + def measurement: -> Float + def measurement_unit: -> String + def quantity: -> Float + def weight_unit: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_items.rbs b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_items.rbs new file mode 100644 index 00000000..417a6db4 --- /dev/null +++ b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_items.rbs @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mindee + module Product + module BillOfLading + class BillOfLadingV1CarrierItems < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rbs b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rbs new file mode 100644 index 00000000..4e5e3a9b --- /dev/null +++ b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rbs @@ -0,0 +1,15 @@ +module Mindee + module Product + module BillOfLading + class BillOfLadingV1Consignee < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> String + def email: -> String + def name: -> String + def phone: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/bill_of_lading/bill_of_lading_v1_document.rbs b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_document.rbs new file mode 100644 index 00000000..68e6a05b --- /dev/null +++ b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_document.rbs @@ -0,0 +1,25 @@ +# lib/mindee/product/bill_of_lading/bill_of_lading_v1_document.rb + +module Mindee + module Product + module BillOfLading + class BillOfLadingV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def bill_of_lading_number: -> (Parsing::Standard::StringField) + def carrier: -> (Product::BillOfLading::BillOfLadingV1Carrier) + def carrier_items: -> (Product::BillOfLading::BillOfLadingV1CarrierItems) + def consignee: -> (Product::BillOfLading::BillOfLadingV1Consignee) + def date_of_issue: -> (Parsing::Standard::DateField) + def departure_date: -> (Parsing::Standard::DateField) + def notify_party: -> (Product::BillOfLading::BillOfLadingV1NotifyParty) + def place_of_delivery: -> (Parsing::Standard::StringField) + def port_of_discharge: -> (Parsing::Standard::StringField) + def port_of_loading: -> (Parsing::Standard::StringField) + def shipper: -> (Product::BillOfLading::BillOfLadingV1Shipper) + def carrier_items_separator: (String) -> String + def carrier_items_to_s: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rbs b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rbs new file mode 100644 index 00000000..40a0cd50 --- /dev/null +++ b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rbs @@ -0,0 +1,15 @@ +module Mindee + module Product + module BillOfLading + class BillOfLadingV1NotifyParty < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> String + def email: -> String + def name: -> String + def phone: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/bill_of_lading/bill_of_lading_v1_page.rbs b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_page.rbs new file mode 100644 index 00000000..098c026f --- /dev/null +++ b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/bill_of_lading/bill_of_lading_v1_page.rb + +module Mindee + module Product + module BillOfLading + class BillOfLadingV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class BillOfLadingV1PagePrediction < BillOfLadingV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rbs b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rbs new file mode 100644 index 00000000..ea7f8a9e --- /dev/null +++ b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rbs @@ -0,0 +1,15 @@ +module Mindee + module Product + module BillOfLading + class BillOfLadingV1Shipper < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> String + def email: -> String + def name: -> String + def phone: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/business_card/business_card_v1.rbs b/sig/mindee/product/business_card/business_card_v1.rbs new file mode 100644 index 00000000..3fb7f15f --- /dev/null +++ b/sig/mindee/product/business_card/business_card_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/business_card/business_card_v1.rb + +module Mindee + module Product + module BusinessCard + class BusinessCardV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/business_card/business_card_v1_document.rbs b/sig/mindee/product/business_card/business_card_v1_document.rbs new file mode 100644 index 00000000..05440b8b --- /dev/null +++ b/sig/mindee/product/business_card/business_card_v1_document.rbs @@ -0,0 +1,23 @@ +# lib/mindee/product/business_card/business_card_v1_document.rb + +module Mindee + module Product + module BusinessCard + class BusinessCardV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> (Parsing::Standard::StringField) + def company: -> (Parsing::Standard::StringField) + def email: -> (Parsing::Standard::StringField) + def fax_number: -> (Parsing::Standard::StringField) + def firstname: -> (Parsing::Standard::StringField) + def job_title: -> (Parsing::Standard::StringField) + def lastname: -> (Parsing::Standard::StringField) + def mobile_number: -> (Parsing::Standard::StringField) + def phone_number: -> (Parsing::Standard::StringField) + def social_media: -> (Array[Parsing::Standard::StringField]) + def website: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/business_card/business_card_v1_page.rbs b/sig/mindee/product/business_card/business_card_v1_page.rbs new file mode 100644 index 00000000..8a0c7b30 --- /dev/null +++ b/sig/mindee/product/business_card/business_card_v1_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/business_card/business_card_v1_page.rb + +module Mindee + module Product + module BusinessCard + class BusinessCardV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class BusinessCardV1PagePrediction < BusinessCardV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/cropper/cropper_v1.rbs b/sig/mindee/product/cropper/cropper_v1.rbs new file mode 100644 index 00000000..b045ce26 --- /dev/null +++ b/sig/mindee/product/cropper/cropper_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/cropper/cropper_v1.rb + +module Mindee + module Product + module Cropper + class CropperV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/cropper/cropper_v1_document.rbs b/sig/mindee/product/cropper/cropper_v1_document.rbs new file mode 100644 index 00000000..04c60c29 --- /dev/null +++ b/sig/mindee/product/cropper/cropper_v1_document.rbs @@ -0,0 +1,12 @@ +# lib/mindee/product/cropper/cropper_v1_document.rb + +module Mindee + module Product + module Cropper + class CropperV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/cropper/cropper_v1_page.rbs b/sig/mindee/product/cropper/cropper_v1_page.rbs new file mode 100644 index 00000000..14f01d1b --- /dev/null +++ b/sig/mindee/product/cropper/cropper_v1_page.rbs @@ -0,0 +1,16 @@ +# lib/mindee/product/cropper/cropper_v1_page.rb + +module Mindee + module Product + module Cropper + class CropperV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class CropperV1PagePrediction < CropperV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def cropping: -> Array[Parsing::Standard::PositionField] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/delivery_note/delivery_note_v1.rbs b/sig/mindee/product/delivery_note/delivery_note_v1.rbs new file mode 100644 index 00000000..d0417d2e --- /dev/null +++ b/sig/mindee/product/delivery_note/delivery_note_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/delivery_note/delivery_note_v1.rb + +module Mindee + module Product + module DeliveryNote + class DeliveryNoteV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/delivery_note/delivery_note_v1_document.rbs b/sig/mindee/product/delivery_note/delivery_note_v1_document.rbs new file mode 100644 index 00000000..8b0fd425 --- /dev/null +++ b/sig/mindee/product/delivery_note/delivery_note_v1_document.rbs @@ -0,0 +1,19 @@ +# lib/mindee/product/delivery_note/delivery_note_v1_document.rb + +module Mindee + module Product + module DeliveryNote + class DeliveryNoteV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def customer_address: -> (Parsing::Standard::StringField) + def customer_name: -> (Parsing::Standard::StringField) + def delivery_date: -> (Parsing::Standard::DateField) + def delivery_number: -> (Parsing::Standard::StringField) + def supplier_address: -> (Parsing::Standard::StringField) + def supplier_name: -> (Parsing::Standard::StringField) + def total_amount: -> (Parsing::Standard::AmountField) + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/delivery_note/delivery_note_v1_page.rbs b/sig/mindee/product/delivery_note/delivery_note_v1_page.rbs new file mode 100644 index 00000000..0c738100 --- /dev/null +++ b/sig/mindee/product/delivery_note/delivery_note_v1_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/delivery_note/delivery_note_v1_page.rb + +module Mindee + module Product + module DeliveryNote + class DeliveryNoteV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class DeliveryNoteV1PagePrediction < DeliveryNoteV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/driver_license/driver_license_v1.rbs b/sig/mindee/product/driver_license/driver_license_v1.rbs new file mode 100644 index 00000000..e2efa549 --- /dev/null +++ b/sig/mindee/product/driver_license/driver_license_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/driver_license/driver_license_v1.rb + +module Mindee + module Product + module DriverLicense + class DriverLicenseV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/driver_license/driver_license_v1_document.rbs b/sig/mindee/product/driver_license/driver_license_v1_document.rbs new file mode 100644 index 00000000..be47a3b3 --- /dev/null +++ b/sig/mindee/product/driver_license/driver_license_v1_document.rbs @@ -0,0 +1,25 @@ +# lib/mindee/product/driver_license/driver_license_v1_document.rb + +module Mindee + module Product + module DriverLicense + class DriverLicenseV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def category: -> (Parsing::Standard::StringField) + def country_code: -> (Parsing::Standard::StringField) + def date_of_birth: -> (Parsing::Standard::DateField) + def dd_number: -> (Parsing::Standard::StringField) + def expiry_date: -> (Parsing::Standard::DateField) + def first_name: -> (Parsing::Standard::StringField) + def id: -> (Parsing::Standard::StringField) + def issued_date: -> (Parsing::Standard::DateField) + def issuing_authority: -> (Parsing::Standard::StringField) + def last_name: -> (Parsing::Standard::StringField) + def mrz: -> (Parsing::Standard::StringField) + def place_of_birth: -> (Parsing::Standard::StringField) + def state: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/driver_license/driver_license_v1_page.rbs b/sig/mindee/product/driver_license/driver_license_v1_page.rbs new file mode 100644 index 00000000..1c172f04 --- /dev/null +++ b/sig/mindee/product/driver_license/driver_license_v1_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/driver_license/driver_license_v1_page.rb + +module Mindee + module Product + module DriverLicense + class DriverLicenseV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class DriverLicenseV1PagePrediction < DriverLicenseV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/eu/license_plate/license_plate_v1.rbs b/sig/mindee/product/eu/license_plate/license_plate_v1.rbs new file mode 100644 index 00000000..c30e110e --- /dev/null +++ b/sig/mindee/product/eu/license_plate/license_plate_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../license_plate/license_plate_v1.rb + +module Mindee + module Product + module EU + module LicensePlate + class LicensePlateV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/eu/license_plate/license_plate_v1_document.rbs b/sig/mindee/product/eu/license_plate/license_plate_v1_document.rbs new file mode 100644 index 00000000..0daa0011 --- /dev/null +++ b/sig/mindee/product/eu/license_plate/license_plate_v1_document.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/../license_plate/license_plate_v1_document.rb + +module Mindee + module Product + module EU + module LicensePlate + class LicensePlateV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def license_plates: -> (Array[Parsing::Standard::StringField]) + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/eu/license_plate/license_plate_v1_page.rbs b/sig/mindee/product/eu/license_plate/license_plate_v1_page.rbs new file mode 100644 index 00000000..b213e4eb --- /dev/null +++ b/sig/mindee/product/eu/license_plate/license_plate_v1_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../license_plate/license_plate_v1_page.rb + +module Mindee + module Product + module EU + module LicensePlate + class LicensePlateV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class LicensePlateV1PagePrediction < LicensePlateV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/financial_document/financial_document_v1.rbs b/sig/mindee/product/financial_document/financial_document_v1.rbs new file mode 100644 index 00000000..f3c23cc8 --- /dev/null +++ b/sig/mindee/product/financial_document/financial_document_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/financial_document/financial_document_v1.rb + +module Mindee + module Product + module FinancialDocument + class FinancialDocumentV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/financial_document/financial_document_v1_document.rbs b/sig/mindee/product/financial_document/financial_document_v1_document.rbs new file mode 100644 index 00000000..b38c14b8 --- /dev/null +++ b/sig/mindee/product/financial_document/financial_document_v1_document.rbs @@ -0,0 +1,46 @@ +# lib/mindee/product/financial_document/financial_document_v1_document.rb + +module Mindee + module Product + module FinancialDocument + class FinancialDocumentV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def billing_address: -> (Parsing::Standard::StringField) + def category: -> (Parsing::Standard::ClassificationField) + def customer_address: -> (Parsing::Standard::StringField) + def customer_company_registrations: -> (Array[Parsing::Standard::CompanyRegistrationField]) + def customer_id: -> (Parsing::Standard::StringField) + def customer_name: -> (Parsing::Standard::StringField) + def date: -> (Parsing::Standard::DateField) + def document_number: -> (Parsing::Standard::StringField) + def document_type: -> (Parsing::Standard::ClassificationField) + def due_date: -> (Parsing::Standard::DateField) + def invoice_number: -> (Parsing::Standard::StringField) + def line_items: -> (Product::FinancialDocument::FinancialDocumentV1LineItems) + def locale: -> (Parsing::Standard::LocaleField) + def payment_date: -> (Parsing::Standard::DateField) + def po_number: -> (Parsing::Standard::StringField) + def receipt_number: -> (Parsing::Standard::StringField) + def reference_numbers: -> (Array[Parsing::Standard::StringField]) + def shipping_address: -> (Parsing::Standard::StringField) + def subcategory: -> (Parsing::Standard::ClassificationField) + def supplier_address: -> (Parsing::Standard::StringField) + def supplier_company_registrations: -> (Array[Parsing::Standard::CompanyRegistrationField]) + def supplier_email: -> (Parsing::Standard::StringField) + def supplier_name: -> (Parsing::Standard::StringField) + def supplier_payment_details: -> (Array[Parsing::Standard::PaymentDetailsField]) + def supplier_phone_number: -> (Parsing::Standard::StringField) + def supplier_website: -> (Parsing::Standard::StringField) + def taxes: -> (Parsing::Standard::Taxes) + def time: -> (Parsing::Standard::StringField) + def tip: -> (Parsing::Standard::AmountField) + def total_amount: -> (Parsing::Standard::AmountField) + def total_net: -> (Parsing::Standard::AmountField) + def total_tax: -> (Parsing::Standard::AmountField) + def line_items_separator: (String) -> String + def line_items_to_s: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/financial_document/financial_document_v1_line_item.rbs b/sig/mindee/product/financial_document/financial_document_v1_line_item.rbs new file mode 100644 index 00000000..4cb2b923 --- /dev/null +++ b/sig/mindee/product/financial_document/financial_document_v1_line_item.rbs @@ -0,0 +1,21 @@ +module Mindee + module Product + module FinancialDocument + class FinancialDocumentV1LineItem < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def description: -> String + def product_code: -> String + def quantity: -> Float + def tax_amount: -> Float + def tax_rate: -> Float + def total_amount: -> Float + def unit_measure: -> String + def unit_price: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/financial_document/financial_document_v1_line_items.rbs b/sig/mindee/product/financial_document/financial_document_v1_line_items.rbs new file mode 100644 index 00000000..a31d8119 --- /dev/null +++ b/sig/mindee/product/financial_document/financial_document_v1_line_items.rbs @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mindee + module Product + module FinancialDocument + class FinancialDocumentV1LineItems < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/financial_document/financial_document_v1_page.rbs b/sig/mindee/product/financial_document/financial_document_v1_page.rbs new file mode 100644 index 00000000..88bfa9b8 --- /dev/null +++ b/sig/mindee/product/financial_document/financial_document_v1_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/financial_document/financial_document_v1_page.rb + +module Mindee + module Product + module FinancialDocument + class FinancialDocumentV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class FinancialDocumentV1PagePrediction < FinancialDocumentV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/fr/bank_account_details/bank_account_details_v1.rbs b/sig/mindee/product/fr/bank_account_details/bank_account_details_v1.rbs new file mode 100644 index 00000000..0226de7b --- /dev/null +++ b/sig/mindee/product/fr/bank_account_details/bank_account_details_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../bank_account_details/bank_account_details_v1.rb + +module Mindee + module Product + module FR + module BankAccountDetails + class BankAccountDetailsV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rbs b/sig/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rbs new file mode 100644 index 00000000..eddda830 --- /dev/null +++ b/sig/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../bank_account_details/bank_account_details_v1_document.rb + +module Mindee + module Product + module FR + module BankAccountDetails + class BankAccountDetailsV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def account_holder_name: -> (Parsing::Standard::StringField) + def iban: -> (Parsing::Standard::StringField) + def swift: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rbs b/sig/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rbs new file mode 100644 index 00000000..7852515b --- /dev/null +++ b/sig/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../bank_account_details/bank_account_details_v1_page.rb + +module Mindee + module Product + module FR + module BankAccountDetails + class BankAccountDetailsV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class BankAccountDetailsV1PagePrediction < BankAccountDetailsV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_account_details/bank_account_details_v2.rbs b/sig/mindee/product/fr/bank_account_details/bank_account_details_v2.rbs new file mode 100644 index 00000000..6429e295 --- /dev/null +++ b/sig/mindee/product/fr/bank_account_details/bank_account_details_v2.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../bank_account_details/bank_account_details_v2.rb + +module Mindee + module Product + module FR + module BankAccountDetails + class BankAccountDetailsV2 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rbs b/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rbs new file mode 100644 index 00000000..63a1d4b0 --- /dev/null +++ b/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rbs @@ -0,0 +1,17 @@ +module Mindee + module Product + module FR + module BankAccountDetails + class BankAccountDetailsV2Bban < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def bban_bank_code: -> String + def bban_branch_code: -> String + def bban_key: -> String + def bban_number: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rbs b/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rbs new file mode 100644 index 00000000..64225f36 --- /dev/null +++ b/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rbs @@ -0,0 +1,18 @@ +# lib/mindee/product/../bank_account_details/bank_account_details_v2_document.rb + +module Mindee + module Product + module FR + module BankAccountDetails + class BankAccountDetailsV2Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def account_holders_names: -> (Parsing::Standard::StringField) + def bban: -> (Product::FR::BankAccountDetails::BankAccountDetailsV2Bban) + def iban: -> (Parsing::Standard::StringField) + def swift_code: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rbs b/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rbs new file mode 100644 index 00000000..75b8fa3f --- /dev/null +++ b/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../bank_account_details/bank_account_details_v2_page.rb + +module Mindee + module Product + module FR + module BankAccountDetails + class BankAccountDetailsV2Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class BankAccountDetailsV2PagePrediction < BankAccountDetailsV2Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs new file mode 100644 index 00000000..eeabf480 --- /dev/null +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../bank_statement/bank_statement_v2.rb + +module Mindee + module Product + module FR + module BankStatement + class BankStatementV2 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs new file mode 100644 index 00000000..9a536ff4 --- /dev/null +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs @@ -0,0 +1,29 @@ +# lib/mindee/product/../bank_statement/bank_statement_v2_document.rb + +module Mindee + module Product + module FR + module BankStatement + class BankStatementV2Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def account_number: -> (Parsing::Standard::StringField) + def bank_address: -> (Parsing::Standard::StringField) + def bank_name: -> (Parsing::Standard::StringField) + def client_address: -> (Parsing::Standard::StringField) + def client_names: -> (Array[Parsing::Standard::StringField]) + def closing_balance: -> (Parsing::Standard::AmountField) + def opening_balance: -> (Parsing::Standard::AmountField) + def statement_date: -> (Parsing::Standard::DateField) + def statement_end_date: -> (Parsing::Standard::DateField) + def statement_start_date: -> (Parsing::Standard::DateField) + def total_credits: -> (Parsing::Standard::AmountField) + def total_debits: -> (Parsing::Standard::AmountField) + def transactions: -> (Product::FR::BankStatement::BankStatementV2Transactions) + def transactions_separator: (String) -> String + def transactions_to_s: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs new file mode 100644 index 00000000..c586ae46 --- /dev/null +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../bank_statement/bank_statement_v2_page.rb + +module Mindee + module Product + module FR + module BankStatement + class BankStatementV2Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class BankStatementV2PagePrediction < BankStatementV2Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs new file mode 100644 index 00000000..41e4158d --- /dev/null +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs @@ -0,0 +1,18 @@ +module Mindee + module Product + module FR + module BankStatement + class BankStatementV2Transaction < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def amount: -> Float + def date: -> String + def description: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rbs new file mode 100644 index 00000000..4e36cf22 --- /dev/null +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rbs @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mindee + module Product + module FR + module BankStatement + class BankStatementV2Transactions < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/carte_grise/carte_grise_v1.rbs b/sig/mindee/product/fr/carte_grise/carte_grise_v1.rbs new file mode 100644 index 00000000..d7d43f76 --- /dev/null +++ b/sig/mindee/product/fr/carte_grise/carte_grise_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../carte_grise/carte_grise_v1.rb + +module Mindee + module Product + module FR + module CarteGrise + class CarteGriseV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/fr/carte_grise/carte_grise_v1_document.rbs b/sig/mindee/product/fr/carte_grise/carte_grise_v1_document.rbs new file mode 100644 index 00000000..41385d93 --- /dev/null +++ b/sig/mindee/product/fr/carte_grise/carte_grise_v1_document.rbs @@ -0,0 +1,55 @@ +# lib/mindee/product/../carte_grise/carte_grise_v1_document.rb + +module Mindee + module Product + module FR + module CarteGrise + class CarteGriseV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def a: -> (Parsing::Standard::StringField) + def b: -> (Parsing::Standard::DateField) + def c1: -> (Parsing::Standard::StringField) + def c3: -> (Parsing::Standard::StringField) + def c41: -> (Parsing::Standard::StringField) + def c4a: -> (Parsing::Standard::StringField) + def d1: -> (Parsing::Standard::StringField) + def d3: -> (Parsing::Standard::StringField) + def e: -> (Parsing::Standard::StringField) + def f1: -> (Parsing::Standard::StringField) + def f2: -> (Parsing::Standard::StringField) + def f3: -> (Parsing::Standard::StringField) + def formula_number: -> (Parsing::Standard::StringField) + def g: -> (Parsing::Standard::StringField) + def g1: -> (Parsing::Standard::StringField) + def i: -> (Parsing::Standard::DateField) + def j: -> (Parsing::Standard::StringField) + def j1: -> (Parsing::Standard::StringField) + def j2: -> (Parsing::Standard::StringField) + def j3: -> (Parsing::Standard::StringField) + def mrz1: -> (Parsing::Standard::StringField) + def mrz2: -> (Parsing::Standard::StringField) + def owner_first_name: -> (Parsing::Standard::StringField) + def owner_surname: -> (Parsing::Standard::StringField) + def p1: -> (Parsing::Standard::StringField) + def p2: -> (Parsing::Standard::StringField) + def p3: -> (Parsing::Standard::StringField) + def p6: -> (Parsing::Standard::StringField) + def q: -> (Parsing::Standard::StringField) + def s1: -> (Parsing::Standard::StringField) + def s2: -> (Parsing::Standard::StringField) + def u1: -> (Parsing::Standard::StringField) + def u2: -> (Parsing::Standard::StringField) + def v7: -> (Parsing::Standard::StringField) + def x1: -> (Parsing::Standard::StringField) + def y1: -> (Parsing::Standard::StringField) + def y2: -> (Parsing::Standard::StringField) + def y3: -> (Parsing::Standard::StringField) + def y4: -> (Parsing::Standard::StringField) + def y5: -> (Parsing::Standard::StringField) + def y6: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/carte_grise/carte_grise_v1_page.rbs b/sig/mindee/product/fr/carte_grise/carte_grise_v1_page.rbs new file mode 100644 index 00000000..3e9cda3a --- /dev/null +++ b/sig/mindee/product/fr/carte_grise/carte_grise_v1_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../carte_grise/carte_grise_v1_page.rb + +module Mindee + module Product + module FR + module CarteGrise + class CarteGriseV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class CarteGriseV1PagePrediction < CarteGriseV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1.rbs new file mode 100644 index 00000000..3fd86396 --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../energy_bill/energy_bill_v1.rb + +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_document.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_document.rbs new file mode 100644 index 00000000..526d7b7e --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_document.rbs @@ -0,0 +1,34 @@ +# lib/mindee/product/../energy_bill/energy_bill_v1_document.rb + +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def contract_id: -> (Parsing::Standard::StringField) + def delivery_point: -> (Parsing::Standard::StringField) + def due_date: -> (Parsing::Standard::DateField) + def energy_consumer: -> (Product::FR::EnergyBill::EnergyBillV1EnergyConsumer) + def energy_supplier: -> (Product::FR::EnergyBill::EnergyBillV1EnergySupplier) + def energy_usage: -> (Product::FR::EnergyBill::EnergyBillV1EnergyUsages) + def invoice_date: -> (Parsing::Standard::DateField) + def invoice_number: -> (Parsing::Standard::StringField) + def meter_details: -> (Product::FR::EnergyBill::EnergyBillV1MeterDetail) + def subscription: -> (Product::FR::EnergyBill::EnergyBillV1Subscriptions) + def taxes_and_contributions: -> (Product::FR::EnergyBill::EnergyBillV1TaxesAndContributions) + def total_amount: -> (Parsing::Standard::AmountField) + def total_before_taxes: -> (Parsing::Standard::AmountField) + def total_taxes: -> (Parsing::Standard::AmountField) + def subscription_separator: (String) -> String + def subscription_to_s: -> String + def energy_usage_separator: (String) -> String + def energy_usage_to_s: -> String + def taxes_and_contributions_separator: (String) -> String + def taxes_and_contributions_to_s: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rbs new file mode 100644 index 00000000..ad976177 --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rbs @@ -0,0 +1,15 @@ +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1EnergyConsumer < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> String + def name: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rbs new file mode 100644 index 00000000..4b6ba552 --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rbs @@ -0,0 +1,15 @@ +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1EnergySupplier < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> String + def name: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rbs new file mode 100644 index 00000000..60c93a99 --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rbs @@ -0,0 +1,21 @@ +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1EnergyUsage < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def description: -> String + def end_date: -> String + def start_date: -> String + def tax_rate: -> Float + def total: -> Float + def unit_price: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_usages.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_usages.rbs new file mode 100644 index 00000000..595028be --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_usages.rbs @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1EnergyUsages < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rbs new file mode 100644 index 00000000..ccfa50a8 --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rbs @@ -0,0 +1,16 @@ +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1MeterDetail < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def meter_number: -> String + def meter_type: -> String + def unit: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_page.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_page.rbs new file mode 100644 index 00000000..19b92043 --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../energy_bill/energy_bill_v1_page.rb + +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class EnergyBillV1PagePrediction < EnergyBillV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rbs new file mode 100644 index 00000000..0812fdd8 --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rbs @@ -0,0 +1,21 @@ +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1Subscription < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def description: -> String + def end_date: -> String + def start_date: -> String + def tax_rate: -> Float + def total: -> Float + def unit_price: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_subscriptions.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_subscriptions.rbs new file mode 100644 index 00000000..6685a82b --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_subscriptions.rbs @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1Subscriptions < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rbs new file mode 100644 index 00000000..80fba64c --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rbs @@ -0,0 +1,21 @@ +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1TaxesAndContribution < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def description: -> String + def end_date: -> String + def start_date: -> String + def tax_rate: -> Float + def total: -> Float + def unit_price: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contributions.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contributions.rbs new file mode 100644 index 00000000..96b2326c --- /dev/null +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contributions.rbs @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mindee + module Product + module FR + module EnergyBill + class EnergyBillV1TaxesAndContributions < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/health_card/health_card_v1.rbs b/sig/mindee/product/fr/health_card/health_card_v1.rbs new file mode 100644 index 00000000..35ac7d57 --- /dev/null +++ b/sig/mindee/product/fr/health_card/health_card_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../health_card/health_card_v1.rb + +module Mindee + module Product + module FR + module HealthCard + class HealthCardV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/fr/health_card/health_card_v1_document.rbs b/sig/mindee/product/fr/health_card/health_card_v1_document.rbs new file mode 100644 index 00000000..ba15f3d2 --- /dev/null +++ b/sig/mindee/product/fr/health_card/health_card_v1_document.rbs @@ -0,0 +1,18 @@ +# lib/mindee/product/../health_card/health_card_v1_document.rb + +module Mindee + module Product + module FR + module HealthCard + class HealthCardV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def given_names: -> (Array[Parsing::Standard::StringField]) + def issuance_date: -> (Parsing::Standard::DateField) + def social_security: -> (Parsing::Standard::StringField) + def surname: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/health_card/health_card_v1_page.rbs b/sig/mindee/product/fr/health_card/health_card_v1_page.rbs new file mode 100644 index 00000000..3ff463d3 --- /dev/null +++ b/sig/mindee/product/fr/health_card/health_card_v1_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../health_card/health_card_v1_page.rb + +module Mindee + module Product + module FR + module HealthCard + class HealthCardV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class HealthCardV1PagePrediction < HealthCardV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/id_card/id_card_v1.rbs b/sig/mindee/product/fr/id_card/id_card_v1.rbs new file mode 100644 index 00000000..1892193f --- /dev/null +++ b/sig/mindee/product/fr/id_card/id_card_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../id_card/id_card_v1.rb + +module Mindee + module Product + module FR + module IdCard + class IdCardV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/fr/id_card/id_card_v1_document.rbs b/sig/mindee/product/fr/id_card/id_card_v1_document.rbs new file mode 100644 index 00000000..2e4af612 --- /dev/null +++ b/sig/mindee/product/fr/id_card/id_card_v1_document.rbs @@ -0,0 +1,24 @@ +# lib/mindee/product/../id_card/id_card_v1_document.rb + +module Mindee + module Product + module FR + module IdCard + class IdCardV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def authority: -> (Parsing::Standard::StringField) + def birth_date: -> (Parsing::Standard::DateField) + def birth_place: -> (Parsing::Standard::StringField) + def expiry_date: -> (Parsing::Standard::DateField) + def gender: -> (Parsing::Standard::StringField) + def given_names: -> (Array[Parsing::Standard::StringField]) + def id_number: -> (Parsing::Standard::StringField) + def mrz1: -> (Parsing::Standard::StringField) + def mrz2: -> (Parsing::Standard::StringField) + def surname: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/id_card/id_card_v1_page.rbs b/sig/mindee/product/fr/id_card/id_card_v1_page.rbs new file mode 100644 index 00000000..78f682d7 --- /dev/null +++ b/sig/mindee/product/fr/id_card/id_card_v1_page.rbs @@ -0,0 +1,18 @@ +# lib/mindee/product/../id_card/id_card_v1_page.rb + +module Mindee + module Product + module FR + module IdCard + class IdCardV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class IdCardV1PagePrediction < IdCardV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def document_side: -> Parsing::Standard::ClassificationField + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/id_card/id_card_v2.rbs b/sig/mindee/product/fr/id_card/id_card_v2.rbs new file mode 100644 index 00000000..eb5ed751 --- /dev/null +++ b/sig/mindee/product/fr/id_card/id_card_v2.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../id_card/id_card_v2.rb + +module Mindee + module Product + module FR + module IdCard + class IdCardV2 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/fr/id_card/id_card_v2_document.rbs b/sig/mindee/product/fr/id_card/id_card_v2_document.rbs new file mode 100644 index 00000000..22abd297 --- /dev/null +++ b/sig/mindee/product/fr/id_card/id_card_v2_document.rbs @@ -0,0 +1,29 @@ +# lib/mindee/product/../id_card/id_card_v2_document.rb + +module Mindee + module Product + module FR + module IdCard + class IdCardV2Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def alternate_name: -> (Parsing::Standard::StringField) + def authority: -> (Parsing::Standard::StringField) + def birth_date: -> (Parsing::Standard::DateField) + def birth_place: -> (Parsing::Standard::StringField) + def card_access_number: -> (Parsing::Standard::StringField) + def document_number: -> (Parsing::Standard::StringField) + def expiry_date: -> (Parsing::Standard::DateField) + def gender: -> (Parsing::Standard::StringField) + def given_names: -> (Array[Parsing::Standard::StringField]) + def issue_date: -> (Parsing::Standard::DateField) + def mrz1: -> (Parsing::Standard::StringField) + def mrz2: -> (Parsing::Standard::StringField) + def mrz3: -> (Parsing::Standard::StringField) + def nationality: -> (Parsing::Standard::StringField) + def surname: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/id_card/id_card_v2_page.rbs b/sig/mindee/product/fr/id_card/id_card_v2_page.rbs new file mode 100644 index 00000000..bfbeeb7a --- /dev/null +++ b/sig/mindee/product/fr/id_card/id_card_v2_page.rbs @@ -0,0 +1,19 @@ +# lib/mindee/product/../id_card/id_card_v2_page.rb + +module Mindee + module Product + module FR + module IdCard + class IdCardV2Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class IdCardV2PagePrediction < IdCardV2Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def document_side: -> Parsing::Standard::ClassificationField + def document_type: -> Parsing::Standard::ClassificationField + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2.rbs b/sig/mindee/product/fr/payslip/payslip_v2.rbs new file mode 100644 index 00000000..e74b64b9 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../payslip/payslip_v2.rb + +module Mindee + module Product + module FR + module Payslip + class PayslipV2 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rbs b/sig/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rbs new file mode 100644 index 00000000..5c30345e --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rbs @@ -0,0 +1,16 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV2BankAccountDetail < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def bank_name: -> String + def iban: -> String + def swift: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_document.rbs b/sig/mindee/product/fr/payslip/payslip_v2_document.rbs new file mode 100644 index 00000000..922974b1 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_document.rbs @@ -0,0 +1,24 @@ +# lib/mindee/product/../payslip/payslip_v2_document.rb + +module Mindee + module Product + module FR + module Payslip + class PayslipV2Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def bank_account_details: -> (Product::FR::Payslip::PayslipV2BankAccountDetail) + def employee: -> (Product::FR::Payslip::PayslipV2Employee) + def employer: -> (Product::FR::Payslip::PayslipV2Employer) + def employment: -> (Product::FR::Payslip::PayslipV2Employment) + def pay_detail: -> (Product::FR::Payslip::PayslipV2PayDetail) + def pay_period: -> (Product::FR::Payslip::PayslipV2PayPeriod) + def pto: -> (Product::FR::Payslip::PayslipV2Pto) + def salary_details: -> (Product::FR::Payslip::PayslipV2SalaryDetails) + def salary_details_separator: (String) -> String + def salary_details_to_s: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_employee.rbs b/sig/mindee/product/fr/payslip/payslip_v2_employee.rbs new file mode 100644 index 00000000..cc1cc577 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_employee.rbs @@ -0,0 +1,20 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV2Employee < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> String + def date_of_birth: -> String + def first_name: -> String + def last_name: -> String + def phone_number: -> String + def registration_number: -> String + def social_security_number: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_employer.rbs b/sig/mindee/product/fr/payslip/payslip_v2_employer.rbs new file mode 100644 index 00000000..06d2dc82 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_employer.rbs @@ -0,0 +1,20 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV2Employer < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> String + def company_id: -> String + def company_site: -> String + def naf_code: -> String + def name: -> String + def phone_number: -> String + def urssaf_number: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_employment.rbs b/sig/mindee/product/fr/payslip/payslip_v2_employment.rbs new file mode 100644 index 00000000..774c714b --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_employment.rbs @@ -0,0 +1,19 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV2Employment < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def category: -> String + def coefficient: -> Float + def collective_agreement: -> String + def job_title: -> String + def position_level: -> String + def start_date: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_page.rbs b/sig/mindee/product/fr/payslip/payslip_v2_page.rbs new file mode 100644 index 00000000..8b1b29d5 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../payslip/payslip_v2_page.rb + +module Mindee + module Product + module FR + module Payslip + class PayslipV2Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class PayslipV2PagePrediction < PayslipV2Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_pay_detail.rbs b/sig/mindee/product/fr/payslip/payslip_v2_pay_detail.rbs new file mode 100644 index 00000000..9cd65bc6 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_pay_detail.rbs @@ -0,0 +1,23 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV2PayDetail < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def gross_salary: -> Float + def gross_salary_ytd: -> Float + def income_tax_rate: -> Float + def income_tax_withheld: -> Float + def net_paid: -> Float + def net_paid_before_tax: -> Float + def net_taxable: -> Float + def net_taxable_ytd: -> Float + def total_cost_employer: -> Float + def total_taxes_and_deductions: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_pay_period.rbs b/sig/mindee/product/fr/payslip/payslip_v2_pay_period.rbs new file mode 100644 index 00000000..eb4bf897 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_pay_period.rbs @@ -0,0 +1,18 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV2PayPeriod < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def end_date: -> String + def month: -> String + def payment_date: -> String + def start_date: -> String + def year: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_pto.rbs b/sig/mindee/product/fr/payslip/payslip_v2_pto.rbs new file mode 100644 index 00000000..a80ad073 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_pto.rbs @@ -0,0 +1,16 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV2Pto < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def accrued_this_period: -> Float + def balance_end_of_period: -> Float + def used_this_period: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_salary_detail.rbs b/sig/mindee/product/fr/payslip/payslip_v2_salary_detail.rbs new file mode 100644 index 00000000..a2f92410 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_salary_detail.rbs @@ -0,0 +1,19 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV2SalaryDetail < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def amount: -> Float + def base: -> Float + def description: -> String + def rate: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_salary_details.rbs b/sig/mindee/product/fr/payslip/payslip_v2_salary_details.rbs new file mode 100644 index 00000000..896ba0b7 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v2_salary_details.rbs @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mindee + module Product + module FR + module Payslip + class PayslipV2SalaryDetails < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3.rbs b/sig/mindee/product/fr/payslip/payslip_v3.rbs new file mode 100644 index 00000000..193937f1 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../payslip/payslip_v3.rb + +module Mindee + module Product + module FR + module Payslip + class PayslipV3 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rbs b/sig/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rbs new file mode 100644 index 00000000..fbf0ebdf --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rbs @@ -0,0 +1,16 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV3BankAccountDetail < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def bank_name: -> String + def iban: -> String + def swift: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_document.rbs b/sig/mindee/product/fr/payslip/payslip_v3_document.rbs new file mode 100644 index 00000000..33a9dbd3 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_document.rbs @@ -0,0 +1,26 @@ +# lib/mindee/product/../payslip/payslip_v3_document.rb + +module Mindee + module Product + module FR + module Payslip + class PayslipV3Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def bank_account_details: -> (Product::FR::Payslip::PayslipV3BankAccountDetail) + def employee: -> (Product::FR::Payslip::PayslipV3Employee) + def employer: -> (Product::FR::Payslip::PayslipV3Employer) + def employment: -> (Product::FR::Payslip::PayslipV3Employment) + def paid_time_off: -> (Product::FR::Payslip::PayslipV3PaidTimeOffs) + def pay_detail: -> (Product::FR::Payslip::PayslipV3PayDetail) + def pay_period: -> (Product::FR::Payslip::PayslipV3PayPeriod) + def salary_details: -> (Product::FR::Payslip::PayslipV3SalaryDetails) + def salary_details_separator: (String) -> String + def salary_details_to_s: -> String + def paid_time_off_separator: (String) -> String + def paid_time_off_to_s: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_employee.rbs b/sig/mindee/product/fr/payslip/payslip_v3_employee.rbs new file mode 100644 index 00000000..a2d2b10c --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_employee.rbs @@ -0,0 +1,20 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV3Employee < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> String + def date_of_birth: -> String + def first_name: -> String + def last_name: -> String + def phone_number: -> String + def registration_number: -> String + def social_security_number: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_employer.rbs b/sig/mindee/product/fr/payslip/payslip_v3_employer.rbs new file mode 100644 index 00000000..54067b7e --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_employer.rbs @@ -0,0 +1,20 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV3Employer < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> String + def company_id: -> String + def company_site: -> String + def naf_code: -> String + def name: -> String + def phone_number: -> String + def urssaf_number: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_employment.rbs b/sig/mindee/product/fr/payslip/payslip_v3_employment.rbs new file mode 100644 index 00000000..3e6f9639 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_employment.rbs @@ -0,0 +1,20 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV3Employment < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def category: -> String + def coefficient: -> String + def collective_agreement: -> String + def job_title: -> String + def position_level: -> String + def seniority_date: -> String + def start_date: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_page.rbs b/sig/mindee/product/fr/payslip/payslip_v3_page.rbs new file mode 100644 index 00000000..eeaf8d78 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../payslip/payslip_v3_page.rb + +module Mindee + module Product + module FR + module Payslip + class PayslipV3Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class PayslipV3PagePrediction < PayslipV3Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_paid_time_off.rbs b/sig/mindee/product/fr/payslip/payslip_v3_paid_time_off.rbs new file mode 100644 index 00000000..d5cdd7fa --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_paid_time_off.rbs @@ -0,0 +1,20 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV3PaidTimeOff < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def accrued: -> Float + def period: -> String + def pto_type: -> String + def remaining: -> Float + def used: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_paid_time_offs.rbs b/sig/mindee/product/fr/payslip/payslip_v3_paid_time_offs.rbs new file mode 100644 index 00000000..eb201c80 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_paid_time_offs.rbs @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mindee + module Product + module FR + module Payslip + class PayslipV3PaidTimeOffs < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_pay_detail.rbs b/sig/mindee/product/fr/payslip/payslip_v3_pay_detail.rbs new file mode 100644 index 00000000..466d7423 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_pay_detail.rbs @@ -0,0 +1,23 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV3PayDetail < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def gross_salary: -> Float + def gross_salary_ytd: -> Float + def income_tax_rate: -> Float + def income_tax_withheld: -> Float + def net_paid: -> Float + def net_paid_before_tax: -> Float + def net_taxable: -> Float + def net_taxable_ytd: -> Float + def total_cost_employer: -> Float + def total_taxes_and_deductions: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_pay_period.rbs b/sig/mindee/product/fr/payslip/payslip_v3_pay_period.rbs new file mode 100644 index 00000000..eba9d2e7 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_pay_period.rbs @@ -0,0 +1,18 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV3PayPeriod < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def end_date: -> String + def month: -> String + def payment_date: -> String + def start_date: -> String + def year: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_salary_detail.rbs b/sig/mindee/product/fr/payslip/payslip_v3_salary_detail.rbs new file mode 100644 index 00000000..5c5d417a --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_salary_detail.rbs @@ -0,0 +1,20 @@ +module Mindee + module Product + module FR + module Payslip + class PayslipV3SalaryDetail < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def amount: -> Float + def base: -> Float + def description: -> String + def number: -> Float + def rate: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_salary_details.rbs b/sig/mindee/product/fr/payslip/payslip_v3_salary_details.rbs new file mode 100644 index 00000000..2344f862 --- /dev/null +++ b/sig/mindee/product/fr/payslip/payslip_v3_salary_details.rbs @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mindee + module Product + module FR + module Payslip + class PayslipV3SalaryDetails < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/ind/indian_passport/indian_passport_v1.rbs b/sig/mindee/product/ind/indian_passport/indian_passport_v1.rbs new file mode 100644 index 00000000..ecdcf7df --- /dev/null +++ b/sig/mindee/product/ind/indian_passport/indian_passport_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../indian_passport/indian_passport_v1.rb + +module Mindee + module Product + module IND + module IndianPassport + class IndianPassportV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/ind/indian_passport/indian_passport_v1_document.rbs b/sig/mindee/product/ind/indian_passport/indian_passport_v1_document.rbs new file mode 100644 index 00000000..33a6e1f8 --- /dev/null +++ b/sig/mindee/product/ind/indian_passport/indian_passport_v1_document.rbs @@ -0,0 +1,37 @@ +# lib/mindee/product/../indian_passport/indian_passport_v1_document.rb + +module Mindee + module Product + module IND + module IndianPassport + class IndianPassportV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address1: -> (Parsing::Standard::StringField) + def address2: -> (Parsing::Standard::StringField) + def address3: -> (Parsing::Standard::StringField) + def birth_date: -> (Parsing::Standard::DateField) + def birth_place: -> (Parsing::Standard::StringField) + def country: -> (Parsing::Standard::StringField) + def expiry_date: -> (Parsing::Standard::DateField) + def file_number: -> (Parsing::Standard::StringField) + def gender: -> (Parsing::Standard::ClassificationField) + def given_names: -> (Parsing::Standard::StringField) + def id_number: -> (Parsing::Standard::StringField) + def issuance_date: -> (Parsing::Standard::DateField) + def issuance_place: -> (Parsing::Standard::StringField) + def legal_guardian: -> (Parsing::Standard::StringField) + def mrz1: -> (Parsing::Standard::StringField) + def mrz2: -> (Parsing::Standard::StringField) + def name_of_mother: -> (Parsing::Standard::StringField) + def name_of_spouse: -> (Parsing::Standard::StringField) + def old_passport_date_of_issue: -> (Parsing::Standard::DateField) + def old_passport_number: -> (Parsing::Standard::StringField) + def old_passport_place_of_issue: -> (Parsing::Standard::StringField) + def page_number: -> (Parsing::Standard::ClassificationField) + def surname: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/ind/indian_passport/indian_passport_v1_page.rbs b/sig/mindee/product/ind/indian_passport/indian_passport_v1_page.rbs new file mode 100644 index 00000000..4d332417 --- /dev/null +++ b/sig/mindee/product/ind/indian_passport/indian_passport_v1_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../indian_passport/indian_passport_v1_page.rb + +module Mindee + module Product + module IND + module IndianPassport + class IndianPassportV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class IndianPassportV1PagePrediction < IndianPassportV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/international_id/international_id_v2.rbs b/sig/mindee/product/international_id/international_id_v2.rbs new file mode 100644 index 00000000..dcd65fbb --- /dev/null +++ b/sig/mindee/product/international_id/international_id_v2.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/international_id/international_id_v2.rb + +module Mindee + module Product + module InternationalId + class InternationalIdV2 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/international_id/international_id_v2_document.rbs b/sig/mindee/product/international_id/international_id_v2_document.rbs new file mode 100644 index 00000000..5acda5f8 --- /dev/null +++ b/sig/mindee/product/international_id/international_id_v2_document.rbs @@ -0,0 +1,29 @@ +# lib/mindee/product/international_id/international_id_v2_document.rb + +module Mindee + module Product + module InternationalId + class InternationalIdV2Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> (Parsing::Standard::StringField) + def birth_date: -> (Parsing::Standard::DateField) + def birth_place: -> (Parsing::Standard::StringField) + def country_of_issue: -> (Parsing::Standard::StringField) + def document_number: -> (Parsing::Standard::StringField) + def document_type: -> (Parsing::Standard::ClassificationField) + def expiry_date: -> (Parsing::Standard::DateField) + def given_names: -> (Array[Parsing::Standard::StringField]) + def issue_date: -> (Parsing::Standard::DateField) + def mrz_line1: -> (Parsing::Standard::StringField) + def mrz_line2: -> (Parsing::Standard::StringField) + def mrz_line3: -> (Parsing::Standard::StringField) + def nationality: -> (Parsing::Standard::StringField) + def personal_number: -> (Parsing::Standard::StringField) + def sex: -> (Parsing::Standard::StringField) + def state_of_issue: -> (Parsing::Standard::StringField) + def surnames: -> (Array[Parsing::Standard::StringField]) + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/international_id/international_id_v2_page.rbs b/sig/mindee/product/international_id/international_id_v2_page.rbs new file mode 100644 index 00000000..154f6fec --- /dev/null +++ b/sig/mindee/product/international_id/international_id_v2_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/international_id/international_id_v2_page.rb + +module Mindee + module Product + module InternationalId + class InternationalIdV2Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class InternationalIdV2PagePrediction < InternationalIdV2Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/invoice/invoice_v4.rbs b/sig/mindee/product/invoice/invoice_v4.rbs new file mode 100644 index 00000000..b6df6ecf --- /dev/null +++ b/sig/mindee/product/invoice/invoice_v4.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/invoice/invoice_v4.rb + +module Mindee + module Product + module Invoice + class InvoiceV4 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/invoice/invoice_v4_document.rbs b/sig/mindee/product/invoice/invoice_v4_document.rbs new file mode 100644 index 00000000..bb69dd3d --- /dev/null +++ b/sig/mindee/product/invoice/invoice_v4_document.rbs @@ -0,0 +1,40 @@ +# lib/mindee/product/invoice/invoice_v4_document.rb + +module Mindee + module Product + module Invoice + class InvoiceV4Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def billing_address: -> (Parsing::Standard::StringField) + def customer_address: -> (Parsing::Standard::StringField) + def customer_company_registrations: -> (Array[Parsing::Standard::CompanyRegistrationField]) + def customer_id: -> (Parsing::Standard::StringField) + def customer_name: -> (Parsing::Standard::StringField) + def date: -> (Parsing::Standard::DateField) + def document_type: -> (Parsing::Standard::ClassificationField) + def due_date: -> (Parsing::Standard::DateField) + def invoice_number: -> (Parsing::Standard::StringField) + def line_items: -> (Product::Invoice::InvoiceV4LineItems) + def locale: -> (Parsing::Standard::LocaleField) + def payment_date: -> (Parsing::Standard::DateField) + def po_number: -> (Parsing::Standard::StringField) + def reference_numbers: -> (Array[Parsing::Standard::StringField]) + def shipping_address: -> (Parsing::Standard::StringField) + def supplier_address: -> (Parsing::Standard::StringField) + def supplier_company_registrations: -> (Array[Parsing::Standard::CompanyRegistrationField]) + def supplier_email: -> (Parsing::Standard::StringField) + def supplier_name: -> (Parsing::Standard::StringField) + def supplier_payment_details: -> (Array[Parsing::Standard::PaymentDetailsField]) + def supplier_phone_number: -> (Parsing::Standard::StringField) + def supplier_website: -> (Parsing::Standard::StringField) + def taxes: -> (Parsing::Standard::Taxes) + def total_amount: -> (Parsing::Standard::AmountField) + def total_net: -> (Parsing::Standard::AmountField) + def total_tax: -> (Parsing::Standard::AmountField) + def line_items_separator: (String) -> String + def line_items_to_s: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/invoice/invoice_v4_line_item.rbs b/sig/mindee/product/invoice/invoice_v4_line_item.rbs new file mode 100644 index 00000000..d0cd2fc2 --- /dev/null +++ b/sig/mindee/product/invoice/invoice_v4_line_item.rbs @@ -0,0 +1,21 @@ +module Mindee + module Product + module Invoice + class InvoiceV4LineItem < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def description: -> String + def product_code: -> String + def quantity: -> Float + def tax_amount: -> Float + def tax_rate: -> Float + def total_amount: -> Float + def unit_measure: -> String + def unit_price: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/invoice/invoice_v4_line_items.rbs b/sig/mindee/product/invoice/invoice_v4_line_items.rbs new file mode 100644 index 00000000..514e55c7 --- /dev/null +++ b/sig/mindee/product/invoice/invoice_v4_line_items.rbs @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mindee + module Product + module Invoice + class InvoiceV4LineItems < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/invoice/invoice_v4_page.rbs b/sig/mindee/product/invoice/invoice_v4_page.rbs new file mode 100644 index 00000000..e40b49f2 --- /dev/null +++ b/sig/mindee/product/invoice/invoice_v4_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/invoice/invoice_v4_page.rb + +module Mindee + module Product + module Invoice + class InvoiceV4Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class InvoiceV4PagePrediction < InvoiceV4Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs b/sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs new file mode 100644 index 00000000..6c736b6b --- /dev/null +++ b/sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs @@ -0,0 +1,14 @@ +# lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb +module Mindee + module Product + module InvoiceSplitter + class InvoiceSplitterV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + def endpoint_name: -> String + def endpoint_version: -> String + def has_async: -> bool + def has_sync: -> bool + end + end + end +end diff --git a/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs new file mode 100644 index 00000000..cf07f28f --- /dev/null +++ b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs @@ -0,0 +1,19 @@ +# lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +module Mindee + module Product + module InvoiceSplitter + class InvoiceSplitterV1PageGroup + def page_indexes: -> Array[Integer] + def confidence: -> Float? + def initialize: (Hash[Symbol | String, untyped]) -> void + def to_s: -> String + end + class InvoiceSplitterV1Document < Parsing::Common::Prediction + def invoice_page_groups: -> Array[InvoiceSplitterV1PageGroup] + def initialize: (Hash[Symbol | String, untyped], ?Integer?) -> void + def construct_invoice_page_groups_from_prediction: (Hash[Symbol | String, untyped]) -> nil + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs new file mode 100644 index 00000000..b2cf0c34 --- /dev/null +++ b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb +module Mindee + module Product + module InvoiceSplitter + class InvoiceSplitterV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class InvoiceSplitterV1PagePrediction < InvoiceSplitterV1Document + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rbs b/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rbs new file mode 100644 index 00000000..d433be3f --- /dev/null +++ b/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rb + +module Mindee + module Product + module MultiReceiptsDetector + class MultiReceiptsDetectorV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rbs b/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rbs new file mode 100644 index 00000000..22e75d25 --- /dev/null +++ b/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb + +module Mindee + module Product + module MultiReceiptsDetector + class MultiReceiptsDetectorV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def receipts: -> (Array[Parsing::Standard::PositionField]) + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rbs b/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rbs new file mode 100644 index 00000000..2c677dcd --- /dev/null +++ b/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb + +module Mindee + module Product + module MultiReceiptsDetector + class MultiReceiptsDetectorV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class MultiReceiptsDetectorV1PagePrediction < MultiReceiptsDetectorV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rbs new file mode 100644 index 00000000..cfd9ef90 --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rb + +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rbs new file mode 100644 index 00000000..5e1797bc --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1AddedSugar < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rbs new file mode 100644 index 00000000..892993b9 --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1Calorie < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rbs new file mode 100644 index 00000000..d42a60af --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1Cholesterol < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rbs new file mode 100644 index 00000000..feeb28ed --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1DietaryFiber < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rbs new file mode 100644 index 00000000..7f02aba9 --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rbs @@ -0,0 +1,28 @@ +# lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb + +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def added_sugars: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1AddedSugar) + def calories: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Calorie) + def cholesterol: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Cholesterol) + def dietary_fiber: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1DietaryFiber) + def nutrients: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrients) + def protein: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Protein) + def saturated_fat: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1SaturatedFat) + def serving_per_box: -> (Parsing::Standard::AmountField) + def serving_size: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1ServingSize) + def sodium: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Sodium) + def total_carbohydrate: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1TotalCarbohydrate) + def total_fat: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1TotalFat) + def total_sugars: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1TotalSugar) + def trans_fat: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1TransFat) + def nutrients_separator: (String) -> String + def nutrients_to_s: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rbs new file mode 100644 index 00000000..4e6a177d --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rbs @@ -0,0 +1,18 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1Nutrient < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def name: -> String + def per_100g: -> Float + def per_serving: -> Float + def unit: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rbs new file mode 100644 index 00000000..b92e950d --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rbs @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1Nutrients < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rbs new file mode 100644 index 00000000..f0fa02ec --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rb + +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class NutritionFactsLabelV1PagePrediction < NutritionFactsLabelV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rbs new file mode 100644 index 00000000..c25e7ab5 --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1Protein < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rbs new file mode 100644 index 00000000..7c3bf76f --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1SaturatedFat < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rbs new file mode 100644 index 00000000..e31b5f9c --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rbs @@ -0,0 +1,13 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1ServingSize < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def amount: -> Float + def unit: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rbs new file mode 100644 index 00000000..6221b6fb --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rbs @@ -0,0 +1,15 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1Sodium < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def unit: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rbs new file mode 100644 index 00000000..9ec1a14c --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1TotalCarbohydrate < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rbs new file mode 100644 index 00000000..2474c5c8 --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1TotalFat < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rbs new file mode 100644 index 00000000..229535e4 --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1TotalSugar < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rbs new file mode 100644 index 00000000..765d8b8c --- /dev/null +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rbs @@ -0,0 +1,14 @@ +module Mindee + module Product + module NutritionFactsLabel + class NutritionFactsLabelV1TransFat < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def daily_value: -> Float + def per_100g: -> Float + def per_serving: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/passport/passport_v1.rbs b/sig/mindee/product/passport/passport_v1.rbs new file mode 100644 index 00000000..f548ffc7 --- /dev/null +++ b/sig/mindee/product/passport/passport_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/passport/passport_v1.rb + +module Mindee + module Product + module Passport + class PassportV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/passport/passport_v1_document.rbs b/sig/mindee/product/passport/passport_v1_document.rbs new file mode 100644 index 00000000..6e7fd345 --- /dev/null +++ b/sig/mindee/product/passport/passport_v1_document.rbs @@ -0,0 +1,23 @@ +# lib/mindee/product/passport/passport_v1_document.rb + +module Mindee + module Product + module Passport + class PassportV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def birth_date: -> (Parsing::Standard::DateField) + def birth_place: -> (Parsing::Standard::StringField) + def country: -> (Parsing::Standard::StringField) + def expiry_date: -> (Parsing::Standard::DateField) + def gender: -> (Parsing::Standard::StringField) + def given_names: -> (Array[Parsing::Standard::StringField]) + def id_number: -> (Parsing::Standard::StringField) + def issuance_date: -> (Parsing::Standard::DateField) + def mrz1: -> (Parsing::Standard::StringField) + def mrz2: -> (Parsing::Standard::StringField) + def surname: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/passport/passport_v1_page.rbs b/sig/mindee/product/passport/passport_v1_page.rbs new file mode 100644 index 00000000..5dbe3cb3 --- /dev/null +++ b/sig/mindee/product/passport/passport_v1_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/passport/passport_v1_page.rb + +module Mindee + module Product + module Passport + class PassportV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class PassportV1PagePrediction < PassportV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/receipt/receipt_v5.rbs b/sig/mindee/product/receipt/receipt_v5.rbs new file mode 100644 index 00000000..58a33fb7 --- /dev/null +++ b/sig/mindee/product/receipt/receipt_v5.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/receipt/receipt_v5.rb + +module Mindee + module Product + module Receipt + class ReceiptV5 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/receipt/receipt_v5_document.rbs b/sig/mindee/product/receipt/receipt_v5_document.rbs new file mode 100644 index 00000000..901659c1 --- /dev/null +++ b/sig/mindee/product/receipt/receipt_v5_document.rbs @@ -0,0 +1,31 @@ +# lib/mindee/product/receipt/receipt_v5_document.rb + +module Mindee + module Product + module Receipt + class ReceiptV5Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def category: -> (Parsing::Standard::ClassificationField) + def date: -> (Parsing::Standard::DateField) + def document_type: -> (Parsing::Standard::ClassificationField) + def line_items: -> (Product::Receipt::ReceiptV5LineItems) + def locale: -> (Parsing::Standard::LocaleField) + def receipt_number: -> (Parsing::Standard::StringField) + def subcategory: -> (Parsing::Standard::ClassificationField) + def supplier_address: -> (Parsing::Standard::StringField) + def supplier_company_registrations: -> (Array[Parsing::Standard::CompanyRegistrationField]) + def supplier_name: -> (Parsing::Standard::StringField) + def supplier_phone_number: -> (Parsing::Standard::StringField) + def taxes: -> (Parsing::Standard::Taxes) + def time: -> (Parsing::Standard::StringField) + def tip: -> (Parsing::Standard::AmountField) + def total_amount: -> (Parsing::Standard::AmountField) + def total_net: -> (Parsing::Standard::AmountField) + def total_tax: -> (Parsing::Standard::AmountField) + def line_items_separator: (String) -> String + def line_items_to_s: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/receipt/receipt_v5_line_item.rbs b/sig/mindee/product/receipt/receipt_v5_line_item.rbs new file mode 100644 index 00000000..48029f4e --- /dev/null +++ b/sig/mindee/product/receipt/receipt_v5_line_item.rbs @@ -0,0 +1,17 @@ +module Mindee + module Product + module Receipt + class ReceiptV5LineItem < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def description: -> String + def quantity: -> Float + def total_amount: -> Float + def unit_price: -> Float + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/receipt/receipt_v5_line_items.rbs b/sig/mindee/product/receipt/receipt_v5_line_items.rbs new file mode 100644 index 00000000..6f26b02a --- /dev/null +++ b/sig/mindee/product/receipt/receipt_v5_line_items.rbs @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mindee + module Product + module Receipt + class ReceiptV5LineItems < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/receipt/receipt_v5_page.rbs b/sig/mindee/product/receipt/receipt_v5_page.rbs new file mode 100644 index 00000000..43f9487f --- /dev/null +++ b/sig/mindee/product/receipt/receipt_v5_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/receipt/receipt_v5_page.rb + +module Mindee + module Product + module Receipt + class ReceiptV5Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class ReceiptV5PagePrediction < ReceiptV5Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1.rbs b/sig/mindee/product/resume/resume_v1.rbs new file mode 100644 index 00000000..b6e3b396 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1.rbs @@ -0,0 +1,11 @@ +# lib/mindee/product/resume/resume_v1.rb + +module Mindee + module Product + module Resume + class ResumeV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_certificate.rbs b/sig/mindee/product/resume/resume_v1_certificate.rbs new file mode 100644 index 00000000..0f6fe453 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_certificate.rbs @@ -0,0 +1,17 @@ +module Mindee + module Product + module Resume + class ResumeV1Certificate < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def grade: -> String + def name: -> String + def provider: -> String + def year: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_certificates.rbs b/sig/mindee/product/resume/resume_v1_certificates.rbs new file mode 100644 index 00000000..b302e51b --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_certificates.rbs @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mindee + module Product + module Resume + class ResumeV1Certificates < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_document.rbs b/sig/mindee/product/resume/resume_v1_document.rbs new file mode 100644 index 00000000..586f4d08 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_document.rbs @@ -0,0 +1,39 @@ +# lib/mindee/product/resume/resume_v1_document.rb + +module Mindee + module Product + module Resume + class ResumeV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> (Parsing::Standard::StringField) + def certificates: -> (Product::Resume::ResumeV1Certificates) + def document_language: -> (Parsing::Standard::StringField) + def document_type: -> (Parsing::Standard::ClassificationField) + def education: -> (Product::Resume::ResumeV1Educations) + def email_address: -> (Parsing::Standard::StringField) + def given_names: -> (Array[Parsing::Standard::StringField]) + def hard_skills: -> (Array[Parsing::Standard::StringField]) + def job_applied: -> (Parsing::Standard::StringField) + def languages: -> (Product::Resume::ResumeV1Languages) + def nationality: -> (Parsing::Standard::StringField) + def phone_number: -> (Parsing::Standard::StringField) + def profession: -> (Parsing::Standard::StringField) + def professional_experiences: -> (Product::Resume::ResumeV1ProfessionalExperiences) + def social_networks_urls: -> (Product::Resume::ResumeV1SocialNetworksUrls) + def soft_skills: -> (Array[Parsing::Standard::StringField]) + def surnames: -> (Array[Parsing::Standard::StringField]) + def social_networks_urls_separator: (String) -> String + def social_networks_urls_to_s: -> String + def languages_separator: (String) -> String + def languages_to_s: -> String + def education_separator: (String) -> String + def education_to_s: -> String + def professional_experiences_separator: (String) -> String + def professional_experiences_to_s: -> String + def certificates_separator: (String) -> String + def certificates_to_s: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_education.rbs b/sig/mindee/product/resume/resume_v1_education.rbs new file mode 100644 index 00000000..bf0da62f --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_education.rbs @@ -0,0 +1,20 @@ +module Mindee + module Product + module Resume + class ResumeV1Education < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def degree_domain: -> String + def degree_type: -> String + def end_month: -> String + def end_year: -> String + def school: -> String + def start_month: -> String + def start_year: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_educations.rbs b/sig/mindee/product/resume/resume_v1_educations.rbs new file mode 100644 index 00000000..40526d40 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_educations.rbs @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mindee + module Product + module Resume + class ResumeV1Educations < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_language.rbs b/sig/mindee/product/resume/resume_v1_language.rbs new file mode 100644 index 00000000..efbf4658 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_language.rbs @@ -0,0 +1,15 @@ +module Mindee + module Product + module Resume + class ResumeV1Language < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def language: -> String + def level: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_languages.rbs b/sig/mindee/product/resume/resume_v1_languages.rbs new file mode 100644 index 00000000..6c7a7f07 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_languages.rbs @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mindee + module Product + module Resume + class ResumeV1Languages < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_page.rbs b/sig/mindee/product/resume/resume_v1_page.rbs new file mode 100644 index 00000000..82138774 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_page.rbs @@ -0,0 +1,15 @@ +# lib/mindee/product/resume/resume_v1_page.rb + +module Mindee + module Product + module Resume + class ResumeV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class ResumeV1PagePrediction < ResumeV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_professional_experience.rbs b/sig/mindee/product/resume/resume_v1_professional_experience.rbs new file mode 100644 index 00000000..c42140b4 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_professional_experience.rbs @@ -0,0 +1,22 @@ +module Mindee + module Product + module Resume + class ResumeV1ProfessionalExperience < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def contract_type: -> String + def department: -> String + def description: -> String + def employer: -> String + def end_month: -> String + def end_year: -> String + def role: -> String + def start_month: -> String + def start_year: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_professional_experiences.rbs b/sig/mindee/product/resume/resume_v1_professional_experiences.rbs new file mode 100644 index 00000000..23d649a3 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_professional_experiences.rbs @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mindee + module Product + module Resume + class ResumeV1ProfessionalExperiences < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_social_networks_url.rbs b/sig/mindee/product/resume/resume_v1_social_networks_url.rbs new file mode 100644 index 00000000..beca1ef2 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_social_networks_url.rbs @@ -0,0 +1,15 @@ +module Mindee + module Product + module Resume + class ResumeV1SocialNetworksUrl < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def name: -> String + def url: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/resume/resume_v1_social_networks_urls.rbs b/sig/mindee/product/resume/resume_v1_social_networks_urls.rbs new file mode 100644 index 00000000..cde69a22 --- /dev/null +++ b/sig/mindee/product/resume/resume_v1_social_networks_urls.rbs @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Mindee + module Product + module Resume + class ResumeV1SocialNetworksUrls < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/universal/universal.rbs b/sig/mindee/product/universal/universal.rbs new file mode 100644 index 00000000..12ce49b1 --- /dev/null +++ b/sig/mindee/product/universal/universal.rbs @@ -0,0 +1,14 @@ +# lib/mindee/product/universal/universal.rb +module Mindee + module Product + module Universal + class Universal < Parsing::Common::Inference + def initialize: (untyped) -> untyped + def endpoint_name: -> untyped + def endpoint_version: -> untyped + def has_async: -> untyped + def has_sync: -> untyped + end + end + end +end diff --git a/sig/mindee/product/universal/universal_document.rbs b/sig/mindee/product/universal/universal_document.rbs new file mode 100644 index 00000000..dfed539b --- /dev/null +++ b/sig/mindee/product/universal/universal_document.rbs @@ -0,0 +1,10 @@ +# lib/mindee/product/universal/universal_document.rb +module Mindee + module Product + module Universal + class UniversalDocument < Parsing::Common::Document + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/product/universal/universal_page.rbs b/sig/mindee/product/universal/universal_page.rbs new file mode 100644 index 00000000..f928c8eb --- /dev/null +++ b/sig/mindee/product/universal/universal_page.rbs @@ -0,0 +1,14 @@ +# lib/mindee/product/universal/universal_page.rb +module Mindee + module Product + module Universal + class UniversalPage < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class UniversalPagePrediction < UniversalPrediction + def initialize: (Hash[Symbol | String, untyped], ?nil) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/product/universal/universal_prediction.rbs b/sig/mindee/product/universal/universal_prediction.rbs new file mode 100644 index 00000000..176e4904 --- /dev/null +++ b/sig/mindee/product/universal/universal_prediction.rbs @@ -0,0 +1,19 @@ +# lib/mindee/product/universal/universal_prediction.rb +module Mindee + module Product + module Universal + class UniversalPrediction < Parsing::Common::Prediction + def fields: -> Hash[Symbol | String, untyped] + def initialize: (untyped?) -> void + def to_s: -> String + def generate_field_string: (String, Parsing::Universal::UniversalListField, Regexp) -> String + def generate_list_field_string: (String, Hash[Symbol | String, untyped], Regexp) -> String + def generate_sub_value_string: (String, Parsing::Universal::UniversalListField, Regexp) -> String + def single_fields: -> Hash[Symbol | String, untyped] + def list_fields: -> Hash[Symbol | String, Parsing::Universal::UniversalListField] + def object_fields: -> Hash[Symbol | String, untyped] + def list_field_names: -> Array[untyped] + end + end + end +end diff --git a/sig/mindee/product/us/bank_check/bank_check_v1.rbs b/sig/mindee/product/us/bank_check/bank_check_v1.rbs new file mode 100644 index 00000000..7374d8bb --- /dev/null +++ b/sig/mindee/product/us/bank_check/bank_check_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../bank_check/bank_check_v1.rb + +module Mindee + module Product + module US + module BankCheck + class BankCheckV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/us/bank_check/bank_check_v1_document.rbs b/sig/mindee/product/us/bank_check/bank_check_v1_document.rbs new file mode 100644 index 00000000..5729db25 --- /dev/null +++ b/sig/mindee/product/us/bank_check/bank_check_v1_document.rbs @@ -0,0 +1,20 @@ +# lib/mindee/product/../bank_check/bank_check_v1_document.rb + +module Mindee + module Product + module US + module BankCheck + class BankCheckV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def account_number: -> (Parsing::Standard::StringField) + def amount: -> (Parsing::Standard::AmountField) + def check_number: -> (Parsing::Standard::StringField) + def date: -> (Parsing::Standard::DateField) + def payees: -> (Array[Parsing::Standard::StringField]) + def routing_number: -> (Parsing::Standard::StringField) + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/bank_check/bank_check_v1_page.rbs b/sig/mindee/product/us/bank_check/bank_check_v1_page.rbs new file mode 100644 index 00000000..baba8e1a --- /dev/null +++ b/sig/mindee/product/us/bank_check/bank_check_v1_page.rbs @@ -0,0 +1,19 @@ +# lib/mindee/product/../bank_check/bank_check_v1_page.rb + +module Mindee + module Product + module US + module BankCheck + class BankCheckV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class BankCheckV1PagePrediction < BankCheckV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def check_position: -> Parsing::Standard::PositionField + def signatures_positions: -> Array[Parsing::Standard::PositionField] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/healthcare_card/healthcare_card_v1.rbs b/sig/mindee/product/us/healthcare_card/healthcare_card_v1.rbs new file mode 100644 index 00000000..8a1e3284 --- /dev/null +++ b/sig/mindee/product/us/healthcare_card/healthcare_card_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../healthcare_card/healthcare_card_v1.rb + +module Mindee + module Product + module US + module HealthcareCard + class HealthcareCardV1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rbs b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rbs new file mode 100644 index 00000000..d6fbe188 --- /dev/null +++ b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rbs @@ -0,0 +1,17 @@ +module Mindee + module Product + module US + module HealthcareCard + class HealthcareCardV1Copay < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def service_fees: -> Float + def service_name: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/healthcare_card/healthcare_card_v1_copays.rbs b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_copays.rbs new file mode 100644 index 00000000..ae6f3d46 --- /dev/null +++ b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_copays.rbs @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mindee + module Product + module US + module HealthcareCard + class HealthcareCardV1Copays < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/healthcare_card/healthcare_card_v1_document.rbs b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_document.rbs new file mode 100644 index 00000000..9dccc1c5 --- /dev/null +++ b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_document.rbs @@ -0,0 +1,28 @@ +# lib/mindee/product/../healthcare_card/healthcare_card_v1_document.rb + +module Mindee + module Product + module US + module HealthcareCard + class HealthcareCardV1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def company_name: -> (Parsing::Standard::StringField) + def copays: -> (Product::US::HealthcareCard::HealthcareCardV1Copays) + def dependents: -> (Array[Parsing::Standard::StringField]) + def enrollment_date: -> (Parsing::Standard::DateField) + def group_number: -> (Parsing::Standard::StringField) + def issuer80840: -> (Parsing::Standard::StringField) + def member_id: -> (Parsing::Standard::StringField) + def member_name: -> (Parsing::Standard::StringField) + def payer_id: -> (Parsing::Standard::StringField) + def rx_bin: -> (Parsing::Standard::StringField) + def rx_grp: -> (Parsing::Standard::StringField) + def rx_pcn: -> (Parsing::Standard::StringField) + def copays_separator: (String) -> String + def copays_to_s: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/healthcare_card/healthcare_card_v1_page.rbs b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_page.rbs new file mode 100644 index 00000000..50d3ea42 --- /dev/null +++ b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../healthcare_card/healthcare_card_v1_page.rb + +module Mindee + module Product + module US + module HealthcareCard + class HealthcareCardV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class HealthcareCardV1PagePrediction < HealthcareCardV1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/us_mail/us_mail_v3.rbs b/sig/mindee/product/us/us_mail/us_mail_v3.rbs new file mode 100644 index 00000000..9cb95c95 --- /dev/null +++ b/sig/mindee/product/us/us_mail/us_mail_v3.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../us_mail/us_mail_v3.rb + +module Mindee + module Product + module US + module UsMail + class UsMailV3 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/us/us_mail/us_mail_v3_document.rbs b/sig/mindee/product/us/us_mail/us_mail_v3_document.rbs new file mode 100644 index 00000000..e3d27171 --- /dev/null +++ b/sig/mindee/product/us/us_mail/us_mail_v3_document.rbs @@ -0,0 +1,21 @@ +# lib/mindee/product/../us_mail/us_mail_v3_document.rb + +module Mindee + module Product + module US + module UsMail + class UsMailV3Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def is_return_to_sender: -> (Parsing::Standard::BooleanField) + def recipient_addresses: -> (Product::US::UsMail::UsMailV3RecipientAddresses) + def recipient_names: -> (Array[Parsing::Standard::StringField]) + def sender_address: -> (Product::US::UsMail::UsMailV3SenderAddress) + def sender_name: -> (Parsing::Standard::StringField) + def recipient_addresses_separator: (String) -> String + def recipient_addresses_to_s: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/us_mail/us_mail_v3_page.rbs b/sig/mindee/product/us/us_mail/us_mail_v3_page.rbs new file mode 100644 index 00000000..78581df8 --- /dev/null +++ b/sig/mindee/product/us/us_mail/us_mail_v3_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../us_mail/us_mail_v3_page.rb + +module Mindee + module Product + module US + module UsMail + class UsMailV3Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class UsMailV3PagePrediction < UsMailV3Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/us_mail/us_mail_v3_recipient_address.rbs b/sig/mindee/product/us/us_mail/us_mail_v3_recipient_address.rbs new file mode 100644 index 00000000..88846fed --- /dev/null +++ b/sig/mindee/product/us/us_mail/us_mail_v3_recipient_address.rbs @@ -0,0 +1,23 @@ +module Mindee + module Product + module US + module UsMail + class UsMailV3RecipientAddress < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def city: -> String + def complete: -> String + def is_address_change: -> bool + def postal_code: -> String + def private_mailbox_number: -> String + def state: -> String + def street: -> String + def unit: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def table_printable_values: -> Hash[Symbol | String, untyped] + def to_table_line: -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/us_mail/us_mail_v3_recipient_addresses.rbs b/sig/mindee/product/us/us_mail/us_mail_v3_recipient_addresses.rbs new file mode 100644 index 00000000..e51db331 --- /dev/null +++ b/sig/mindee/product/us/us_mail/us_mail_v3_recipient_addresses.rbs @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mindee + module Product + module US + module UsMail + class UsMailV3RecipientAddresses < Array[untyped] + def initialize: (Array[untyped], Integer?) -> void + def self.line_items_separator: (String) -> String + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/us_mail/us_mail_v3_sender_address.rbs b/sig/mindee/product/us/us_mail/us_mail_v3_sender_address.rbs new file mode 100644 index 00000000..e70c60c4 --- /dev/null +++ b/sig/mindee/product/us/us_mail/us_mail_v3_sender_address.rbs @@ -0,0 +1,18 @@ +module Mindee + module Product + module US + module UsMail + class UsMailV3SenderAddress < Parsing::Standard::FeatureField + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def city: -> String + def complete: -> String + def postal_code: -> String + def state: -> String + def street: -> String + def printable_values: -> Hash[Symbol | String, untyped] + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/w9/w9_v1.rbs b/sig/mindee/product/us/w9/w9_v1.rbs new file mode 100644 index 00000000..e70c580b --- /dev/null +++ b/sig/mindee/product/us/w9/w9_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../w9/w9_v1.rb + +module Mindee + module Product + module US + module W9 + class W9V1 < Parsing::Common::Inference + def initialize: (Hash[Symbol | String, untyped]) -> void + end + end + end + end +end diff --git a/sig/mindee/product/us/w9/w9_v1_document.rbs b/sig/mindee/product/us/w9/w9_v1_document.rbs new file mode 100644 index 00000000..73c19733 --- /dev/null +++ b/sig/mindee/product/us/w9/w9_v1_document.rbs @@ -0,0 +1,14 @@ +# lib/mindee/product/../w9/w9_v1_document.rb + +module Mindee + module Product + module US + module W9 + class W9V1Document < Parsing::Common::Prediction + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/product/us/w9/w9_v1_page.rbs b/sig/mindee/product/us/w9/w9_v1_page.rbs new file mode 100644 index 00000000..b007d99d --- /dev/null +++ b/sig/mindee/product/us/w9/w9_v1_page.rbs @@ -0,0 +1,29 @@ +# lib/mindee/product/../w9/w9_v1_page.rb + +module Mindee + module Product + module US + module W9 + class W9V1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class W9V1PagePrediction < W9V1Document + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def address: -> Parsing::Standard::StringField + def business_name: -> Parsing::Standard::StringField + def city_state_zip: -> Parsing::Standard::StringField + def ein: -> Parsing::Standard::StringField + def name: -> Parsing::Standard::StringField + def signature_date_position: -> Parsing::Standard::PositionField + def signature_position: -> Parsing::Standard::PositionField + def ssn: -> Parsing::Standard::StringField + def tax_classification: -> Parsing::Standard::StringField + def tax_classification_llc: -> Parsing::Standard::StringField + def tax_classification_other_details: -> Parsing::Standard::StringField + def w9_revision_date: -> Parsing::Standard::StringField + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/version.rbs b/sig/mindee/version.rbs new file mode 100644 index 00000000..cf67f15d --- /dev/null +++ b/sig/mindee/version.rbs @@ -0,0 +1,6 @@ +# lib/mindee/version.rb +module Mindee + VERSION: String + def self.find_platform: -> (Symbol | Hash[Symbol | String, Regexp])? + PLATFORM: (Hash[Symbol | String, Regexp] | Symbol) +end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 51c3479f..1de4573c 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -10,46 +10,46 @@ it 'should open PDF files from a path' do input_source = mindee_client.source_from_path("#{DATA_DIR}/products/invoices/invoice.pdf") - expect(input_source).to respond_to(:read_document) + expect(input_source).to respond_to(:read_contents) input_source = mindee_client.source_from_path("#{DATA_DIR}/products/invoices/invoice_10p.pdf") - expect(input_source).to respond_to(:read_document) + expect(input_source).to respond_to(:read_contents) end it 'should open PDF files from a file handle' do file = File.open("#{DATA_DIR}/products/invoices/invoice_10p.pdf", 'rb') input_source = mindee_client.source_from_file(file, 'invoice_10p.pdf') - expect(input_source).to respond_to(:read_document) + expect(input_source).to respond_to(:read_contents) end it 'should open PDF files from raw bytes' do file_data = File.binread("#{DATA_DIR}/products/invoices/invoice_10p.pdf") input_source = mindee_client.source_from_bytes(file_data, 'invoice_10p.pdf') - expect(input_source).to respond_to(:read_document) + expect(input_source).to respond_to(:read_contents) end it 'should open PDF files from a base64 string' do file_data = File.read("#{DATA_DIR}/products/invoices/invoice_10p.txt") input_source = mindee_client.source_from_b64string(file_data, 'invoice_10p.txt') - expect(input_source).to respond_to(:read_document) + expect(input_source).to respond_to(:read_contents) end it 'should open JPG files from a path' do input_source = mindee_client.source_from_path("#{DATA_DIR}/file_types/receipt.jpg") - expect(input_source).to respond_to(:read_document) + expect(input_source).to respond_to(:read_contents) input_source = mindee_client.source_from_path("#{DATA_DIR}/file_types/receipt.jpga") - expect(input_source).to respond_to(:read_document) + expect(input_source).to respond_to(:read_contents) end it 'should open JPG files from a file handle' do file = File.open("#{DATA_DIR}/file_types/receipt.jpg", 'rb') input_source = mindee_client.source_from_file(file, 'receipt.jpg') - expect(input_source).to respond_to(:read_document) + expect(input_source).to respond_to(:read_contents) end it 'should open JPG files from raw bytes' do file_data = File.binread("#{DATA_DIR}/file_types/receipt.jpg") input_source = mindee_client.source_from_bytes(file_data, 'receipt.jpg') - expect(input_source).to respond_to(:read_document) + expect(input_source).to respond_to(:read_contents) end it 'should not open an invalid file' do @@ -63,5 +63,60 @@ mindee_client.load_prediction(Mindee::Product::Invoice::InvoiceV4, local_resp) expect(mindee_client).to_not be_nil end + + it 'should not load an invalid local response' do + local_resp = Mindee::Input::LocalResponse.new("#{DATA_DIR}/geometry/polygon.json") + expect do + mindee_client.load_prediction(Mindee::Product::Invoice::InvoiceV4, local_resp) + end.to raise_error Mindee::Errors::MindeeInputError + end + + it 'should not validate improper async parameters' do + file_data = File.binread("#{DATA_DIR}/file_types/receipt.jpg") + input_source = mindee_client.source_from_bytes(file_data, 'receipt.jpg') + expect do + mindee_client.parse( + input_source, + Mindee::Product::Invoice::InvoiceV4, + options: { max_retries: 0 } + ) + end.to raise_error ArgumentError + expect do + mindee_client.parse( + input_source, + Mindee::Product::Invoice::InvoiceV4, + options: { initial_delay_sec: 0.5 } + ) + end.to raise_error ArgumentError + expect do + mindee_client.parse( + input_source, + Mindee::Product::Invoice::InvoiceV4, + options: { delay_sec: 0.5 } + ) + end.to raise_error ArgumentError + end + + it 'should not initialize an invalid endpoint' do + expect do + mindee_client.send( + :initialize_endpoint, + Mindee::Product::Universal::Universal, + endpoint_name: '', + account_name: 'account_name', + version: 'version' + ) + end.to raise_error Mindee::Errors::MindeeConfigurationError + + expect do + mindee_client.send( + :initialize_endpoint, + Mindee::Product::Universal::Universal, + endpoint_name: '', + account_name: 'account_name', + version: 'version' + ) + end.to raise_error Mindee::Errors::MindeeConfigurationError + end end end diff --git a/spec/document/custom_v1_spec.rb b/spec/document/custom_v1_spec.rb deleted file mode 100644 index 38ec187b..00000000 --- a/spec/document/custom_v1_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require 'mindee/product' -require 'mindee/parsing' - -require_relative '../data' - -DIR_CUSTOM_V1 = File.join(DATA_DIR, 'products', 'custom', 'response_v1').freeze - -describe Mindee::Product::Custom::CustomV1 do - context 'A custom document V1' do - it 'should load an empty document prediction' do - response = load_json(DIR_CUSTOM_V1, 'empty.json') - inference = Mindee::Parsing::Common::Document.new(Mindee::Product::Custom::CustomV1, - response['document']).inference - expect(inference.product.type).to eq('constructed') - expect(inference.prediction.fields.length).to eq(10) - expect(inference.prediction.classifications.length).to eq(1) - end - - it 'should load a complete document prediction' do - to_string = read_file(DIR_CUSTOM_V1, 'summary_full.rst') - response = load_json(DIR_CUSTOM_V1, 'complete.json') - document = Mindee::Parsing::Common::Document.new(Mindee::Product::Custom::CustomV1, response['document']) - expect(document.to_s).to eq(to_string) - prediction = document.inference.prediction - - prediction.fields.each do |field_name, field_data| - expect(field_name).to be_kind_of(Symbol) - expect(field_data.values).to be_kind_of(Array) - expect(field_data.contents_str).to be_kind_of(String) - end - - expect(prediction.fields[:string_all].values.size).to eq(3) - expect(prediction.fields['string_all']).to be_nil - expect(prediction.fields[:string_all].contents_str).to eq('Mindee is awesome') - expect(prediction.fields[:string_all].contents_list).to eq(['Mindee', 'is', 'awesome']) - - expect(prediction.classifications[:doc_type].value).to eq('type_b') - end - - it 'should load a complete page 0 prediction' do - to_string = read_file(DIR_CUSTOM_V1, 'summary_page0.rst') - response = load_json(DIR_CUSTOM_V1, 'complete.json') - inference = Mindee::Parsing::Common::Document.new(Mindee::Product::Custom::CustomV1, - response['document']).inference - expect(inference.pages[0].prediction.fields[:string_all].contents_str(separator: '_')).to eq('Jenny_is_great') - expect(inference.pages[0].prediction.fields[:string_all].contents_list).to eq(['Jenny', 'is', 'great']) - expect(inference.pages[0].to_s).to eq(to_string) - end - - it 'should load a complete page 1 prediction' do - to_string = read_file(DIR_CUSTOM_V1, 'summary_page1.rst') - response = load_json(DIR_CUSTOM_V1, 'complete.json') - inference = Mindee::Parsing::Common::Document.new(Mindee::Product::Custom::CustomV1, - response['document']).inference - expect(inference.pages[1].to_s).to eq(to_string) - end - end -end diff --git a/spec/document/eu/driver_license_v1_spec.rb b/spec/document/eu/driver_license_v1_spec.rb deleted file mode 100644 index 4d0df5f5..00000000 --- a/spec/document/eu/driver_license_v1_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require 'mindee/product' -require 'mindee/parsing' - -require_relative '../../data' - -DIR_EU_DRIVER_LICENSE_V1 = File.join(DATA_DIR, 'products', 'eu_driver_license', 'response_v1').freeze - -describe Mindee::Product::EU::DriverLicense::DriverLicenseV1 do - context 'A Driver License V1' do - it 'should load an empty document prediction' do - response = load_json(DIR_EU_DRIVER_LICENSE_V1, 'empty.json') - inference = Mindee::Parsing::Common::Document.new( - Mindee::Product::EU::DriverLicense::DriverLicenseV1, - response['document'] - ).inference - expect(inference.product.type).to eq('standard') - end - - it 'should load a complete document prediction' do - to_string = read_file(DIR_EU_DRIVER_LICENSE_V1, 'summary_full.rst') - response = load_json(DIR_EU_DRIVER_LICENSE_V1, 'complete.json') - document = Mindee::Parsing::Common::Document.new( - Mindee::Product::EU::DriverLicense::DriverLicenseV1, - response['document'] - ) - expect(document.to_s).to eq(to_string) - end - it 'should load a complete page 0 prediction' do - to_string = read_file(DIR_EU_DRIVER_LICENSE_V1, 'summary_page0.rst') - response = load_json(DIR_EU_DRIVER_LICENSE_V1, 'complete.json') - document = Mindee::Parsing::Common::Document.new( - Mindee::Product::EU::DriverLicense::DriverLicenseV1, - response['document'] - ) - page = document.inference.pages[0] - expect(page.to_s).to eq(to_string) - end - end -end diff --git a/spec/document/fr/bank_statement_v1_spec.rb b/spec/document/fr/bank_statement_v1_spec.rb deleted file mode 100644 index 21c66fb6..00000000 --- a/spec/document/fr/bank_statement_v1_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require 'mindee/product' -require 'mindee/parsing' - -require_relative '../../data' - -DIR_FR_BANK_STATEMENT_V1 = File.join(DATA_DIR, 'products', 'bank_statement_fr', 'response_v1').freeze - -describe Mindee::Product::FR::BankStatement::BankStatementV1 do - context 'A Bank Statement (FR) V1' do - it 'should load an empty document prediction' do - response = load_json(DIR_FR_BANK_STATEMENT_V1, 'empty.json') - inference = Mindee::Parsing::Common::Document.new( - Mindee::Product::FR::BankStatement::BankStatementV1, - response['document'] - ).inference - expect(inference.product.type).to eq('standard') - end - - it 'should load a complete document prediction' do - to_string = read_file(DIR_FR_BANK_STATEMENT_V1, 'summary_full.rst') - response = load_json(DIR_FR_BANK_STATEMENT_V1, 'complete.json') - document = Mindee::Parsing::Common::Document.new( - Mindee::Product::FR::BankStatement::BankStatementV1, - response['document'] - ) - expect(document.to_s).to eq(to_string) - end - end -end diff --git a/spec/document/proof_of_address_v1_spec.rb b/spec/document/proof_of_address_v1_spec.rb deleted file mode 100644 index 23ec7e5d..00000000 --- a/spec/document/proof_of_address_v1_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require 'mindee/product' -require 'mindee/parsing' - -require_relative '../data' - -DIR_PROOF_OF_ADDRESS_V1 = File.join(DATA_DIR, 'products', 'proof_of_address', 'response_v1').freeze - -describe Mindee::Product::ProofOfAddress::ProofOfAddressV1 do - context 'A Proof of Address V1' do - it 'should load an empty document prediction' do - response = load_json(DIR_PROOF_OF_ADDRESS_V1, 'empty.json') - inference = Mindee::Parsing::Common::Document.new( - Mindee::Product::ProofOfAddress::ProofOfAddressV1, - response['document'] - ).inference - expect(inference.product.type).to eq('standard') - end - - it 'should load a complete document prediction' do - to_string = read_file(DIR_PROOF_OF_ADDRESS_V1, 'summary_full.rst') - response = load_json(DIR_PROOF_OF_ADDRESS_V1, 'complete.json') - document = Mindee::Parsing::Common::Document.new( - Mindee::Product::ProofOfAddress::ProofOfAddressV1, - response['document'] - ) - expect(document.to_s).to eq(to_string) - end - end -end diff --git a/spec/document/receipt_v4_spec.rb b/spec/document/receipt_v4_spec.rb deleted file mode 100644 index 247d7ee8..00000000 --- a/spec/document/receipt_v4_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require 'mindee/product' -require 'mindee/parsing' - -require_relative '../data' - -DIR_RECEIPT_V4 = File.join(DATA_DIR, 'products', 'expense_receipts', 'response_v4').freeze - -describe Mindee::Product::Receipt::ReceiptV4 do - context 'A Receipt V4' do - it 'should load an empty document prediction' do - response = load_json(DIR_RECEIPT_V4, 'empty.json') - inference = Mindee::Parsing::Common::Document.new(Mindee::Product::Receipt::ReceiptV4, - response['document']).inference - expect(inference.product.type).to eq('standard') - expect(inference.prediction.date.value).to be_nil - expect(inference.prediction.date.page_id).to be_nil - expect(inference.prediction.time.value).to be_nil - end - - it 'should load a complete document prediction' do - to_string = read_file(DIR_RECEIPT_V4, 'summary_full.rst') - response = load_json(DIR_RECEIPT_V4, 'complete.json') - document = Mindee::Parsing::Common::Document.new(Mindee::Product::Receipt::ReceiptV4, response['document']) - expect(document.inference.prediction.date.page_id).to eq(0) - expect(document.inference.prediction.date.value).to eq('2014-07-07') - expect(document.to_s).to eq(to_string) - end - - it 'should load a complete page 0 prediction' do - to_string = read_file(DIR_RECEIPT_V4, 'summary_page0.rst') - response = load_json(DIR_RECEIPT_V4, 'complete.json') - document = Mindee::Parsing::Common::Document.new(Mindee::Product::Receipt::ReceiptV4, response['document']) - page = document.inference.pages[0] - expect(page.prediction.date.page_id).to eq(0) - expect(page.to_s).to eq(to_string) - end - end -end diff --git a/spec/document/us/driver_license_v1_spec.rb b/spec/document/us/driver_license_v1_spec.rb deleted file mode 100644 index cbefb131..00000000 --- a/spec/document/us/driver_license_v1_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require 'mindee/product' -require 'mindee/parsing' - -require_relative '../../data' - -DIR_US_DRIVER_LICENSE_V1 = File.join(DATA_DIR, 'products', 'us_driver_license', 'response_v1').freeze - -describe Mindee::Product::US::DriverLicense::DriverLicenseV1 do - context 'A Driver License V1' do - it 'should load an empty document prediction' do - response = load_json(DIR_US_DRIVER_LICENSE_V1, 'empty.json') - inference = Mindee::Parsing::Common::Document.new( - Mindee::Product::US::DriverLicense::DriverLicenseV1, - response['document'] - ).inference - expect(inference.product.type).to eq('standard') - end - - it 'should load a complete document prediction' do - to_string = read_file(DIR_US_DRIVER_LICENSE_V1, 'summary_full.rst') - response = load_json(DIR_US_DRIVER_LICENSE_V1, 'complete.json') - document = Mindee::Parsing::Common::Document.new( - Mindee::Product::US::DriverLicense::DriverLicenseV1, - response['document'] - ) - expect(document.to_s).to eq(to_string) - end - it 'should load a complete page 0 prediction' do - to_string = read_file(DIR_US_DRIVER_LICENSE_V1, 'summary_page0.rst') - response = load_json(DIR_US_DRIVER_LICENSE_V1, 'complete.json') - document = Mindee::Parsing::Common::Document.new( - Mindee::Product::US::DriverLicense::DriverLicenseV1, - response['document'] - ) - page = document.inference.pages[0] - expect(page.to_s).to eq(to_string) - end - end -end diff --git a/spec/document/us/us_mail_v2_spec.rb b/spec/document/us/us_mail_v2_spec.rb deleted file mode 100644 index c560b813..00000000 --- a/spec/document/us/us_mail_v2_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require 'mindee/product' -require 'mindee/parsing' - -require_relative '../../data' - -DIR_US_US_MAIL_V2 = File.join(DATA_DIR, 'products', 'us_mail', 'response_v2').freeze - -describe Mindee::Product::US::UsMail::UsMailV2 do - context 'A US Mail V2' do - it 'should load an empty document prediction' do - response = load_json(DIR_US_US_MAIL_V2, 'empty.json') - inference = Mindee::Parsing::Common::Document.new( - Mindee::Product::US::UsMail::UsMailV2, - response['document'] - ).inference - expect(inference.product.type).to eq('standard') - end - - it 'should load a complete document prediction' do - to_string = read_file(DIR_US_US_MAIL_V2, 'summary_full.rst') - response = load_json(DIR_US_US_MAIL_V2, 'complete.json') - document = Mindee::Parsing::Common::Document.new( - Mindee::Product::US::UsMail::UsMailV2, - response['document'] - ) - expect(document.to_s).to eq(to_string) - end - end -end diff --git a/spec/extraction/invoice_splitter_extraction_integration.rb b/spec/extraction/invoice_splitter_extraction_integration.rb index f6401d32..a067717c 100644 --- a/spec/extraction/invoice_splitter_extraction_integration.rb +++ b/spec/extraction/invoice_splitter_extraction_integration.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'mindee' -require 'rspec' require_relative '../data' require_relative '../test_utilities' @@ -25,12 +24,12 @@ def prepare_invoice_return(rst_file_path, invoice_prediction) invoice_splitter_input = Mindee::Input::Source::PathInputSource.new( File.join(product_data_dir, 'invoice_splitter', 'default_sample.pdf') ) - response = client.enqueue_and_parse( - invoice_splitter_input, Mindee::Product::InvoiceSplitter::InvoiceSplitterV1, close_file: false + response = client.parse( + invoice_splitter_input, Mindee::Product::InvoiceSplitter::InvoiceSplitterV1, options: { close_file: false } ) inference = response.document.inference - pdf_extractor = Mindee::Extraction::PdfExtractor::PdfExtractor.new(invoice_splitter_input) + pdf_extractor = Mindee::PDF::PDFExtractor::PDFExtractor.new(invoice_splitter_input) expect(pdf_extractor.page_count).to eq(2) extracted_pdfs_strict = pdf_extractor.extract_invoices(inference.prediction.invoice_page_groups, strict: true) diff --git a/spec/extraction/multi_receipts_extractor_spec.rb b/spec/extraction/multi_receipts_extractor_spec.rb index 654e4c57..b2da5094 100644 --- a/spec/extraction/multi_receipts_extractor_spec.rb +++ b/spec/extraction/multi_receipts_extractor_spec.rb @@ -5,8 +5,18 @@ require 'mindee/extraction' require_relative '../data' -describe Mindee::Extraction do - include Mindee::Extraction +describe 'multi-receipts extraction' do + let(:empty_inference) do + double('Inference', prediction: double('Prediction', receipts: nil), pages: []) + end + + let(:valid_inference_with_no_receipts) do + double('Inference', prediction: double('Prediction', receipts: []), pages: []) + end + + let(:empty_input_source) do + double('InputSource', count_pages: 0) + end let(:multi_receipts_single_page_path) do File.join(DATA_DIR, 'products', 'multi_receipts_detector', 'default_sample.jpg') end @@ -28,7 +38,7 @@ input_sample = Mindee::Input::Source::PathInputSource.new(multi_receipts_single_page_path) response = load_json(multi_receipts_single_page_json_path, 'complete.json') doc = Mindee::Product::MultiReceiptsDetector::MultiReceiptsDetectorV1.new(response['document']['inference']) - extracted_receipts = Mindee::Extraction::MultiReceiptsExtractor.extract_receipts(input_sample, doc) + extracted_receipts = Mindee::Extraction.extract_receipts(input_sample, doc) expect(extracted_receipts.size).to eq(6) @@ -76,7 +86,7 @@ input_sample = Mindee::Input::Source::PathInputSource.new(multi_receipts_multi_page_path) response = load_json(multi_receipts_multi_page_json_path, 'multipage_sample.json') doc = Mindee::Product::MultiReceiptsDetector::MultiReceiptsDetectorV1.new(response['document']['inference']) - extracted_receipts = Mindee::Extraction::MultiReceiptsExtractor.extract_receipts(input_sample, doc) + extracted_receipts = Mindee::Extraction.extract_receipts(input_sample, doc) expect(extracted_receipts.size).to eq(5) @@ -111,4 +121,21 @@ expect(extracted_receipts[4].as_source.filename).to end_with('jpg') end end + + context 'when no receipts are found in inference' do + it 'raises a MindeeInputError' do + expect do + Mindee::Extraction.extract_receipts(empty_input_source, empty_inference) + end.to raise_error(Mindee::Errors::MindeeInputError, + 'No possible receipts candidates found for Multi-Receipts extraction.') + end + end + + context 'when input source has no pages' do + it 'returns an empty array' do + extracted_receipts = Mindee::Extraction.extract_receipts(empty_input_source, + valid_inference_with_no_receipts) + expect(extracted_receipts).to eq([]) + end + end end diff --git a/spec/extraction/tax_extractor_spec.rb b/spec/extraction/tax_extractor_spec.rb deleted file mode 100644 index 285a975e..00000000 --- a/spec/extraction/tax_extractor_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require 'mindee/product' -require 'mindee/parsing' - -require_relative '../data' - -describe Mindee::Product::Cropper::CropperV1 do - context 'A custom tax extraction' do - it 'should properly extract the tax from a document.' do - response = load_json(DIR_OCR, 'complete.json') - ocr = Mindee::Parsing::Common::Ocr::Ocr.new( - response['document']['ocr'] - ) - found_tax = Mindee::Extraction::TaxExtractor.extract_custom_tax(ocr, ['Tax'], 0, 20) - expect(found_tax.code).to eq('Tax') - expect(found_tax.rate).to eq(8) - expect(found_tax.value).to eq(nil) - expect(found_tax.base).to be_nil - end - end -end diff --git a/spec/extras/extras_integration.rb b/spec/extras/extras_integration.rb index ac8dbf57..415d4fb0 100644 --- a/spec/extras/extras_integration.rb +++ b/spec/extras/extras_integration.rb @@ -13,7 +13,8 @@ cropper_extra = Mindee::Input::Source::PathInputSource.new( File.join(invoice_path) ) - cropper_result = client.parse(cropper_extra, Mindee::Product::Invoice::InvoiceV4, cropper: true) + cropper_result = client.parse(cropper_extra, Mindee::Product::Invoice::InvoiceV4, options: { cropper: true }, + enqueue: false) expect(cropper_result.document.inference.pages[0].extras.cropper).to_not be_nil end end @@ -25,10 +26,10 @@ full_text_ocr_input = Mindee::Input::Source::PathInputSource.new( File.join(invoice_path) ) - full_text_ocr_result = client.enqueue_and_parse( + full_text_ocr_result = client.parse( full_text_ocr_input, Mindee::Product::InternationalId::InternationalIdV2, - full_text: true + options: { full_text: true } ) expect(full_text_ocr_result.document.extras.full_text_ocr).to_not be_nil end diff --git a/spec/extras/full_text_ocr_spec.rb b/spec/extras/full_text_ocr_spec.rb index f41a81c3..e2f62ee9 100644 --- a/spec/extras/full_text_ocr_spec.rb +++ b/spec/extras/full_text_ocr_spec.rb @@ -1,20 +1,18 @@ # frozen_string_literal: true require 'json' -require 'rspec' require_relative 'extras_utils' -# NOTE: Implementing extras per pages without content (like the Java library) -# would be a breaking change for the Ruby SDK. -# This fixture is left here as a reminder that next major version should probably implement it. - -# shared_context "load pages" do -# let(:load_pages) do -# prediction_data = JSON.parse(File.read(File.join(EXTRAS_DIR, 'full_text_ocr', 'complete.json'))) -# Mindee::Parsing::Common::ApiResponse.new(InternationalIdV2, prediction_data, prediction_data). -# document.inference.pages -# end -# end +shared_context 'load pages' do + let(:load_pages) do + prediction_data = JSON.parse(File.read(File.join(EXTRAS_DIR, 'full_text_ocr', 'complete.json'))) + Mindee::Parsing::Common::ApiResponse.new( + Mindee::Product::InternationalId::InternationalIdV2, + prediction_data, + prediction_data + ).document.inference.pages + end +end shared_context 'load document' do let(:load_document) do @@ -27,10 +25,10 @@ end let(:load_invalid_document) do prediction_data = JSON.parse( - File.read(File.join(DIR_PRODUCTS, 'bank_statement_fr', 'response_v1', 'complete.json')) + File.read(File.join(DIR_PRODUCTS, 'bank_statement_fr', 'response_v2', 'complete.json')) ) Mindee::Parsing::Common::ApiResponse.new( - Mindee::Product::FR::BankStatement::BankStatementV1, + Mindee::Product::FR::BankStatement::BankStatementV2, prediction_data, prediction_data ).document @@ -39,16 +37,16 @@ describe 'FullTextOCR' do include_context 'load document' - # include_context "load pages" + include_context 'load pages' it 'gets full text OCR result' do expected_text = File.read(File.join(EXTRAS_DIR, 'full_text_ocr', 'full_text_ocr.txt')) full_text_ocr = load_document.extras.full_text_ocr - # page0_ocr = load_pages[0].extras.full_text_ocr.content + page0_ocr = load_pages[0].extras.full_text_ocr.contents expect(full_text_ocr.to_s.strip).to eq(expected_text.strip) - # expect(page0_ocr).to eq(expected_text.split("\n").join("\n")) + expect(page0_ocr).to eq(expected_text.split("\n").join("\n")) end it "doesn't get full text when the payload is empty" do @@ -70,12 +68,11 @@ 'version' => 'mock_version', }, 'pages' => [ - {}, { 'extras' => {}, 'id' => 0, 'orientation' => { - 'value' => nil, + 'value' => 0, }, 'prediction' => {}, }, @@ -97,10 +94,10 @@ 'value' => nil, 'confidence' => 0, }, - 'client_name' => { + 'client_names' => [{ 'value' => nil, 'confidence' => 0, - }, + }], 'closing_balance' => { 'value' => nil, 'confidence' => 0, @@ -130,8 +127,10 @@ 'confidence' => 0, }, 'transactions' => [ - 'value' => nil, - 'confidence' => 0, + { + 'value' => nil, + 'confidence' => 0, + }, ], }, }, @@ -139,7 +138,7 @@ 'n_pages' => 0, } built_doc = Mindee::Parsing::Common::Document.new( - Mindee::Product::FR::BankStatement::BankStatementV1, + Mindee::Product::FR::BankStatement::BankStatementV2, synthetic_response ) expect(built_doc.extras).to be_nil diff --git a/spec/http/error_spec.rb b/spec/http/error_handler_spec.rb similarity index 79% rename from spec/http/error_spec.rb rename to spec/http/error_handler_spec.rb index 45154587..34a7462f 100644 --- a/spec/http/error_spec.rb +++ b/spec/http/error_handler_spec.rb @@ -4,7 +4,7 @@ require 'json' require_relative 'mock_http_response' -describe Mindee::HTTP::Error do +describe Mindee::HTTP::ErrorHandler do context 'An HTTP call' do it 'should make an invalid API sync parse call raising an exception' do mindee_client1 = Mindee::Client.new(api_key: 'invalid-api-key') @@ -12,8 +12,8 @@ input_source = mindee_client1.source_from_file(file, 'receipt.jpg') doc_class = Mindee::Product::Receipt::ReceiptV5 expect do - mindee_client1.parse(input_source, doc_class, all_words: false, close_file: true) - end.to raise_error Mindee::HTTP::Error::MindeeHttpClientError + mindee_client1.parse(input_source, doc_class, options: { all_words: false, close_file: true }) + end.to raise_error Mindee::Errors::MindeeHTTPClientError end it 'should make an invalid API async enqueue call raising an exception' do @@ -23,7 +23,7 @@ doc_class = Mindee::Product::Invoice::InvoiceV4 expect do mindee_client1.enqueue(input_source, doc_class) - end.to raise_error Mindee::HTTP::Error::MindeeHttpClientError + end.to raise_error Mindee::Errors::MindeeHTTPClientError end it 'should make an invalid API async parse call raising an exception' do @@ -31,7 +31,7 @@ doc_class = Mindee::Product::InvoiceSplitter::InvoiceSplitterV1 expect do mindee_client1.parse_queued('invalid-job-id', doc_class) - end.to raise_error Mindee::HTTP::Error::MindeeHttpClientError + end.to raise_error Mindee::Errors::MindeeHTTPClientError end # NOTE: No reliable UT each HTTP error for ruby as the only semi-reliable http mock lib (Webmock) isn't compatible @@ -41,10 +41,10 @@ it 'should fail on a 400 response with object' do file = File.read("#{DATA_DIR}/errors/error_400_no_details.json") error_obj = MockHTTPResponse.new('1.0', '400', 'Some scary message here', file) - error400 = Mindee::HTTP::Error.handle_error('dummy-url', error_obj) + error400 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do raise error400 - end.to raise_error Mindee::HTTP::Error::MindeeHttpClientError + end.to raise_error Mindee::Errors::MindeeHTTPClientError expect(error400.status_code).to eq(400) expect(error400.api_code).to eq('SomeCode') expect(error400.api_message).to eq('Some scary message here') @@ -54,10 +54,10 @@ it 'should fail on a 401 response with object' do file = File.read("#{DATA_DIR}/errors/error_401_invalid_token.json") error_obj = MockHTTPResponse.new('1.0', '401', 'Authorization required', file) - error401 = Mindee::HTTP::Error.handle_error('dummy-url', error_obj) + error401 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do raise error401 - end.to raise_error Mindee::HTTP::Error::MindeeHttpClientError + end.to raise_error Mindee::Errors::MindeeHTTPClientError expect(error401.status_code).to eq(401) expect(error401.api_code).to eq('Unauthorized') expect(error401.api_message).to eq('Authorization required') @@ -67,10 +67,10 @@ it 'should fail on a 429 response with object' do file = File.read("#{DATA_DIR}/errors/error_429_too_many_requests.json") error_obj = MockHTTPResponse.new('1.0', '429', 'Too many requests', file) - error429 = Mindee::HTTP::Error.handle_error('dummy-url', error_obj) + error429 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do raise error429 - end.to raise_error Mindee::HTTP::Error::MindeeHttpClientError + end.to raise_error Mindee::Errors::MindeeHTTPClientError expect(error429.status_code).to eq(429) expect(error429.api_code).to eq('TooManyRequests') expect(error429.api_message).to eq('Too many requests') @@ -80,10 +80,10 @@ it 'should fail on a 500 response with object' do file = File.read("#{DATA_DIR}/errors/error_500_inference_fail.json") error_obj = MockHTTPResponse.new('1.0', '500', 'Inference failed', file) - error500 = Mindee::HTTP::Error.handle_error('dummy-url', error_obj) + error500 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do raise error500 - end.to raise_error Mindee::HTTP::Error::MindeeHttpServerError + end.to raise_error Mindee::Errors::MindeeHTTPServerError expect(error500.status_code).to eq(500) expect(error500.api_code).to eq('failure') expect(error500.api_message).to eq('Inference failed') @@ -93,10 +93,10 @@ it 'should fail on a 500 HTML response' do file = File.read("#{DATA_DIR}/errors/error_50x.html") error_obj = MockHTTPResponse.new('1.0', '500', '', file) - error500 = Mindee::HTTP::Error.handle_error('dummy-url', error_obj) + error500 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do raise error500 - end.to raise_error Mindee::HTTP::Error::MindeeHttpServerError + end.to raise_error Mindee::Errors::MindeeHTTPServerError expect(error500.status_code).to eq(500) expect(error500.api_code).to eq('UnknownError') expect(error500.api_message).to eq('Server sent back an unexpected reply.') @@ -111,10 +111,10 @@ expect(hashed_obj.dig('job', 'status')).to eq('failed') expect(Mindee::HTTP::ResponseValidation.valid_async_response?(error_obj)).to be(false) Mindee::HTTP::ResponseValidation.clean_request! error_obj - error500 = Mindee::HTTP::Error.handle_error('dummy-url', error_obj) + error500 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do raise error500 - end.to raise_error Mindee::HTTP::Error::MindeeHttpServerError + end.to raise_error Mindee::Errors::MindeeHTTPServerError expect(error500.status_code).to eq(500) expect(error500.api_code).to eq('ServerError') expect(error500.api_message).to eq('An error occurred') diff --git a/spec/image/extracted_image_spec.rb b/spec/image/extracted_image_spec.rb new file mode 100644 index 00000000..d01d7d67 --- /dev/null +++ b/spec/image/extracted_image_spec.rb @@ -0,0 +1,119 @@ +# frozen_string_literal: true + +require 'mindee' +require 'pathname' +require 'fileutils' +require 'mini_magick' +require_relative '../data' + +describe Mindee::Image::ExtractedImage do + let(:file_path) do + File.join(DATA_DIR, 'products', 'invoices', 'default_sample.jpg') + end + let(:input_source) do + Mindee::Input::Source::PathInputSource.new(file_path) + end + let(:page_id) { 1 } + let(:element_id) { 42 } + let(:output_dir) { "#{DATA_DIR}/output" } + + describe '#initialize' do + it 'initializes with correct attributes' do + extracted_image = described_class.new(input_source, page_id, element_id) + + expect(extracted_image.page_id).to eq(page_id) + expect(extracted_image.element_id).to eq(element_id) + expect(extracted_image.internal_file_name).to eq('default_sample_p1_42.jpg') + + # NOTE: ruby messes up the formatting of binary strings, I don't think it worth it to correct this behavior, but + # the result is that we have to remove them from the comparisons. + input_source.io_stream.rewind + source_content = extracted_image.buffer.read.gsub("\r", '').gsub("\n", '') + input_content = input_source.io_stream.read.gsub("\r", '').gsub("\n", '') + + expect(source_content).to eq(input_content) + + input_source.io_stream.rewind + end + + it 'defaults element_id to 0 if nil is provided' do + extracted_image = described_class.new(input_source, page_id, nil) + + expect(extracted_image.element_id).to eq(0) + end + + it 'appends .jpg extension for PDF input sources' do + allow(input_source).to receive(:pdf?).and_return(true) + + extracted_image = described_class.new(input_source, page_id, element_id) + + expect(extracted_image.internal_file_name).to eq('default_sample_p1_42.jpg') + end + end + + describe '#write_to_file' do + it 'saves the buffer to a file with the correct format' do + extracted_image = described_class.new(input_source, page_id, element_id) + output_path = "#{output_dir}/output_test.jpg" + + extracted_image.write_to_file(output_path) + + expect(File.exist?(output_path)).to be true + expect(File.size(output_path)).to be > 0 + end + + it 'raises an error if file format is invalid' do + extracted_image = described_class.new(input_source, page_id, element_id) + invalid_output_path = "#{output_dir}/output_test" + + expect do + extracted_image.write_to_file(invalid_output_path) + end.to raise_error(Mindee::Errors::MindeeImageError, %r{Invalid file format}) + end + + it 'raises an error if the file cannot be saved' do + extracted_image = described_class.new(input_source, page_id, element_id) + invalid_output_path = '/invalid/path/output_test.jpg' + + expect do + extracted_image.write_to_file(invalid_output_path) + end.to raise_error(Mindee::Errors::MindeeImageError) + end + end + + describe '#as_source' do + it 'returns a BytesInputSource with the correct content and filename' do + extracted_image = described_class.new(input_source, page_id, element_id) + + source = extracted_image.as_source + + expect(source).to be_a(Mindee::Input::Source::BytesInputSource) + expect(source.filename).to eq('default_sample_p1_42.jpg') + source.io_stream.rewind + + input_source.io_stream.rewind + source_content = source.io_stream.read.gsub("\r", '').gsub("\n", '') + input_content = input_source.io_stream.read.gsub("\r", '').gsub("\n", '') + + expect(source_content).to eq(input_content) + + input_source.io_stream.rewind + end + + it 'should raise an error when MiniMagick fails during save' do + allow(MiniMagick::Image).to receive(:read).and_raise(StandardError) + + extracted_image = Mindee::Image::ExtractedImage.new(input_source, 1, 2) + + Tempfile.create(['output', '.jpg']) do |tempfile| + expect do + extracted_image.write_to_file(tempfile.path, 'jpg') + end.to raise_error(Mindee::Errors::MindeeImageError, %r{Could not save file}) + end + end + + after(:each) do + FileUtils.rm_f("#{output_dir}/output_test.jpg") + end + end +end diff --git a/spec/image/image_compressor_spec.rb b/spec/image/image_compressor_spec.rb new file mode 100644 index 00000000..81c1b134 --- /dev/null +++ b/spec/image/image_compressor_spec.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require 'mindee' + +require_relative '../data' + +describe Mindee::Image::ImageCompressor do + describe 'Image Quality Compression' do + let(:input_receipt_path) { "#{DATA_DIR}/file_types/receipt.jpg" } + let(:output_dir) { "#{DATA_DIR}/output/" } + + it 'should compress the image from input source' do + receipt_input = Mindee::Input::Source::PathInputSource.new(input_receipt_path) + receipt_input.compress!(quality: 80) # NOTE: base jpg quality is ~81 + + FileUtils.mkdir_p(File.dirname("#{output_dir}compress_indirect.jpg")) + File.write("#{output_dir}compress_indirect.jpg", receipt_input.io_stream.read) + + initial_file_size = File.size(input_receipt_path) + compressed_file_size = File.size(output_dir) + + expect(compressed_file_size).to be < initial_file_size + end + + it 'should compress the image with various quality levels' do + receipt_input = Mindee::Input::Source::PathInputSource.new(input_receipt_path) + + compresses = [ + Mindee::Image::ImageCompressor.compress_image(receipt_input.io_stream, quality: 100), + Mindee::Image::ImageCompressor.compress_image(receipt_input.io_stream), # default quality + Mindee::Image::ImageCompressor.compress_image(receipt_input.io_stream, quality: 50), + Mindee::Image::ImageCompressor.compress_image(receipt_input.io_stream, quality: 10), + Mindee::Image::ImageCompressor.compress_image(receipt_input.io_stream, quality: 1), + ] + + output_files = [ + "#{output_dir}/compress100.jpg", + "#{output_dir}/compress85.jpg", + "#{output_dir}/compress50.jpg", + "#{output_dir}/compress10.jpg", + "#{output_dir}/compress1.jpg", + ] + + compresses.zip(output_files).each do |compressed, output_file| + File.write(output_file, compressed.read) + end + + initial_file_size = File.size(input_receipt_path) + rendered_file_sizes = output_files.map { |file| File.size(file) } + + expect(initial_file_size).to be < rendered_file_sizes[0] + expect(initial_file_size).to be < rendered_file_sizes[1] + expect(rendered_file_sizes[1]).to be > rendered_file_sizes[2] + expect(rendered_file_sizes[2]).to be > rendered_file_sizes[3] + expect(rendered_file_sizes[3]).to be > rendered_file_sizes[4] + end + + after(:each) do + FileUtils.rm_f("#{output_dir}/compress100.jpg") + FileUtils.rm_f("#{output_dir}/compress85.jpg") + FileUtils.rm_f("#{output_dir}/compress50.jpg") + FileUtils.rm_f("#{output_dir}/compress10.jpg") + FileUtils.rm_f("#{output_dir}/compress1.jpg") + FileUtils.rm_f("#{output_dir}/compress_indirect.jpg") + end + end +end diff --git a/spec/extraction/image_extractor_spec.rb b/spec/image/image_extractor_spec.rb similarity index 71% rename from spec/extraction/image_extractor_spec.rb rename to spec/image/image_extractor_spec.rb index 8ce0f391..98515925 100644 --- a/spec/extraction/image_extractor_spec.rb +++ b/spec/image/image_extractor_spec.rb @@ -2,11 +2,10 @@ require 'mindee/product' require 'mindee/input/sources' -require 'mindee/extraction' require_relative '../data' -describe Mindee::Extraction do - include Mindee::Extraction +describe Mindee::Image do + include Mindee::Image let(:barcode_path) do File.join(DATA_DIR, 'products', 'barcode_reader', 'default_sample.jpg') end @@ -19,20 +18,14 @@ it 'extracts barcode images correctly' do json_data = JSON.parse(File.read(barcode_json_path)) inference = Mindee::Product::BarcodeReader::BarcodeReaderV1.new(json_data['document']['inference']) - barcodes1 = [] - inference.prediction.codes_1d.each do |barcode| - barcodes1.push(barcode.polygon) - end - barcodes2 = [] - inference.prediction.codes_2d.each do |barcode| - barcodes2.push(barcode.polygon) - end + barcodes1 = inference.prediction.codes_1d.map(&:polygon) + barcodes2 = inference.prediction.codes_2d.map(&:polygon) input_source = Mindee::Input::Source::PathInputSource.new(barcode_path) - extracted_barcodes_1d = Mindee::Extraction::ImageExtractor.extract_multiple_images_from_source(input_source, 1, - barcodes1) - extracted_barcodes_2d = Mindee::Extraction::ImageExtractor.extract_multiple_images_from_source(input_source, 1, - barcodes2) + extracted_barcodes_1d = Mindee::Image::ImageExtractor.extract_multiple_images_from_source(input_source, 1, + barcodes1) + extracted_barcodes_2d = Mindee::Image::ImageExtractor.extract_multiple_images_from_source(input_source, 1, + barcodes2) expect(extracted_barcodes_1d.size).to eq(1) expect(extracted_barcodes_2d.size).to eq(2) diff --git a/spec/image/image_utils_spec.rb b/spec/image/image_utils_spec.rb new file mode 100644 index 00000000..0fb7f27a --- /dev/null +++ b/spec/image/image_utils_spec.rb @@ -0,0 +1,76 @@ +# frozen_string_literal: true + +# spec/image_utils_spec.rb +require 'mini_magick' +require 'stringio' +require 'mindee' + +describe Mindee::Image::ImageUtils do + let(:sample_image_path) { "#{DATA_DIR}/file_types/receipt.jpg" } + let(:sample_image) { MiniMagick::Image.open(sample_image_path) } + + describe 'Image utility module' do + it 'Should convert StringIO to MiniMagick::Image' do + string_io = StringIO.new(File.read(sample_image_path)) + result = Mindee::Image::ImageUtils.to_image(string_io) + expect(result).to be_a(MiniMagick::Image) + end + + it 'Should return the same MiniMagick::Image object if passed as input' do + result = Mindee::Image::ImageUtils.to_image(sample_image) + expect(result).to eq(sample_image) + end + + it 'Should raise an error for invalid input types' do + expect do + Mindee::Image::ImageUtils.to_image(123) + end.to raise_error(Mindee::Errors::MindeeImageError, %r{Expected an I/O object or a MiniMagick::Image}) + end + + it 'Should convert MiniMagick image to StringIO' do + result = Mindee::Image::ImageUtils.image_to_stringio(sample_image) + expect(result).to be_a(StringIO) + end + + it 'Should set the format of the image correctly' do + result = Mindee::Image::ImageUtils.image_to_stringio(sample_image, 'PNG') + expect(result.string[1..3]).to eq('PNG') + end + + it 'Should return original dimensions if no max_width or max_height is provided' do + result = Mindee::Image::ImageUtils.calculate_new_dimensions(sample_image) + expect(result).to eq([sample_image.width, sample_image.height]) + end + + it 'Should calculate new dimensions based on max_width and max_height' do + result = Mindee::Image::ImageUtils.calculate_new_dimensions(sample_image, max_width: 100, max_height: 100) + expect(result[0]).to be <= 100 + expect(result[1]).to be <= 100 + end + + it 'Should raise an error if the original image is nil' do + expect do + Mindee::Image::ImageUtils.calculate_new_dimensions(nil) + end.to raise_error(Mindee::Errors::MindeeImageError, %r{Provided image could not be processed for resizing}) + end + + it 'Should return dimensions from media box if provided' do + media_box = [0, 0, 300, 400] + result = Mindee::Image::ImageUtils.calculate_dimensions_from_media_box(sample_image, media_box) + expect(result).to eq([300, 400]) + end + + it 'Should fall back to image dimensions if media box is nil or empty' do + result = Mindee::Image::ImageUtils.calculate_dimensions_from_media_box(sample_image, nil) + expect(result).to eq([sample_image.width.to_i, sample_image.height.to_i]) + end + + it 'Should raise an error if the PDF stream is invalid' do + invalid_pdf_stream = StringIO.new('invalid data') + # Adjust based on actual error raised by MiniMagick for invalid data. + expect do + Mindee::Image::ImageUtils.pdf_to_magick_image(invalid_pdf_stream, 75) + end.to raise_error(MiniMagick::Error) + end + end +end diff --git a/spec/input/local_response_spec.rb b/spec/input/local_response_spec.rb index 31b3b132..058973c2 100644 --- a/spec/input/local_response_spec.rb +++ b/spec/input/local_response_spec.rb @@ -53,5 +53,18 @@ expect(response.get_hmac_signature(dummy_secret_key)).to eq(signature) end end + + it 'should trigger an error when something invalid is passed' do + expect do + Mindee::Input::LocalResponse.new(123) + end.to raise_error Mindee::Errors::MindeeInputError + end + + it 'should trigger an error when the payload is not hashable' do + local_response = Mindee::Input::LocalResponse.new('Your mother was a hamster.') + expect do + local_response.as_hash + end.to raise_error Mindee::Errors::MindeeInputError + end end end diff --git a/spec/input/pdf_processing_spec.rb b/spec/input/pdf_processing_spec.rb deleted file mode 100644 index 4feae54c..00000000 --- a/spec/input/pdf_processing_spec.rb +++ /dev/null @@ -1,112 +0,0 @@ -# frozen_string_literal: true - -require 'mindee/pdf' - -require_relative '../data' - -describe Mindee::PDF do - def open_pdf(io_stream) - pdf_parser = Origami::PDF::LinearParser.new({}) - io_stream.seek(0) - pdf_parser.parse(io_stream) - end - - context 'A single page PDF' do - filepath = File.join(DATA_DIR, 'file_types/pdf/blank.pdf').freeze - - it 'Should grab the first page' do - io_stream = File.open(filepath, 'rb') - io_stream.seek(0) - options = { - page_indexes: [0], - operation: :KEEP_ONLY, - on_min_pages: 0, - } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) - new_pdf = open_pdf(new_stream) - expect(new_pdf.pages.size).to eq(1) - end - - it 'Should grab the last page' do - io_stream = File.open(filepath, 'rb') - io_stream.seek(0) - options = { - page_indexes: [-1], - operation: :KEEP_ONLY, - on_min_pages: 0, - } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) - new_pdf = open_pdf(new_stream) - expect(new_pdf.pages.size).to eq(1) - end - end - - context 'A multi-page PDF' do - filepath = File.join(DATA_DIR, 'file_types/pdf/multipage.pdf').freeze - - it 'Should grab the first page' do - io_stream = File.open(filepath, 'rb') - io_stream.seek(0) - options = { - page_indexes: [0], - operation: :KEEP_ONLY, - on_min_pages: 0, - } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) - new_pdf = open_pdf(new_stream) - expect(new_pdf.pages.size).to eq(1) - end - - it 'Should grab the last page' do - io_stream = File.open(filepath, 'rb') - io_stream.seek(0) - options = { - page_indexes: [-1], - operation: :KEEP_ONLY, - on_min_pages: 0, - } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) - new_pdf = open_pdf(new_stream) - expect(new_pdf.pages.size).to eq(1) - end - - it 'Should grab the first 2, and the last page' do - io_stream = File.open(filepath, 'rb') - io_stream.seek(0) - options = { - page_indexes: [0, 1, -1], - operation: :KEEP_ONLY, - on_min_pages: 0, - } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) - new_pdf = open_pdf(new_stream) - expect(new_pdf.pages.size).to eq(3) - end - - it 'Should grab the first 5 pages' do - io_stream = File.open(filepath, 'rb') - io_stream.seek(0) - options = { - page_indexes: [0, 1, 2, 3, 4], - operation: :KEEP_ONLY, - on_min_pages: 0, - } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) - new_pdf = open_pdf(new_stream) - expect(new_pdf.pages.size).to eq(5) - end - - it 'Should remove the first 3 pages' do - io_stream = File.open(filepath, 'rb') - io_stream.seek(0) - options = { - page_indexes: [0, 1, 2], - operation: :REMOVE, - on_min_pages: 0, - } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) - new_pdf = open_pdf(new_stream) - expect(new_pdf.pages.size).to eq(9) - end - end -end diff --git a/spec/input/files_handling_spec.rb b/spec/input/sources/files_handling_spec.rb similarity index 90% rename from spec/input/files_handling_spec.rb rename to spec/input/sources/files_handling_spec.rb index b38da352..46786d59 100644 --- a/spec/input/files_handling_spec.rb +++ b/spec/input/sources/files_handling_spec.rb @@ -2,14 +2,14 @@ require 'mindee/input/sources' require 'base64' -require_relative '../data' +require_relative '../../data' describe Mindee::Input::Source::LocalInputSource do context 'An jpg input file' do it 'should be readable as raw bytes' do file = File.join(DATA_DIR, 'file_types/receipt.jpg') input = Mindee::Input::Source::PathInputSource.new(file) - read_f = input.read_document + read_f = input.read_contents expect(read_f.length).to eq(3) expect(read_f[1]).to eq(File.read(file, mode: 'rb')) end @@ -19,7 +19,7 @@ it 'should be readable as raw bytes' do file = File.join(DATA_DIR, 'file_types/receipt.jpga') input = Mindee::Input::Source::PathInputSource.new(file) - read_f = input.read_document + read_f = input.read_contents expect(read_f.length).to eq(3) expect(read_f[1]).to eq(File.read(file, mode: 'rb')) end @@ -29,7 +29,7 @@ it 'should be readable as raw bytes' do file = File.join(DATA_DIR, 'file_types/receipt.heic') input = Mindee::Input::Source::PathInputSource.new(file) - read_f = input.read_document + read_f = input.read_contents expect(read_f.length).to eq(3) expect(read_f[1]).to eq(File.read(file, mode: 'rb')) end @@ -39,7 +39,7 @@ it 'should be readable as raw bytes' do file = File.join(DATA_DIR, 'file_types/receipt.tif') input = Mindee::Input::Source::PathInputSource.new(file) - read_f = input.read_document + read_f = input.read_contents expect(read_f.length).to eq(3) expect(read_f[1]).to eq(File.read(file, mode: 'rb')) end @@ -49,7 +49,7 @@ it 'should be readable as raw bytes' do file = File.join(DATA_DIR, 'file_types/receipt.tiff') input = Mindee::Input::Source::PathInputSource.new(file) - read_f = input.read_document + read_f = input.read_contents expect(read_f.length).to eq(3) expect(read_f[1]).to eq(File.read(file, mode: 'rb')) end @@ -59,7 +59,7 @@ it 'should stay in base64' do file = File.join(DATA_DIR, 'file_types/receipt.txt') input = Mindee::Input::Source::Base64InputSource.new(File.read(file), 'receipt.txt') - read_f = input.read_document + read_f = input.read_contents expect(read_f.length).to eq(3) expect(read_f[1].gsub("\n", '')).to eq(File.read(file).gsub("\n", '')) end @@ -69,7 +69,7 @@ it 'should not be converted' do file = File.join(DATA_DIR, 'file_types/pdf/not_blank_image_only.pdf') input = Mindee::Input::Source::PathInputSource.new(file) - read_f = input.read_document + read_f = input.read_contents file_contents = File.read(file) expect(read_f[1]).to_not eq(Base64.encode64(file_contents)) expect(read_f.length).to eq(3) @@ -81,7 +81,7 @@ it 'should not be converted' do file = File.join(DATA_DIR, 'file_types/pdf/valid_exported.pdf') input = Mindee::Input::Source::PathInputSource.new(file) - read_f = input.read_document + read_f = input.read_contents file_contents = File.read(file) expect(read_f[1]).to_not eq(Base64.encode64(file_contents)) expect(read_f.length).to eq(3) diff --git a/spec/input/sources/local_input_source_spec.rb b/spec/input/sources/local_input_source_spec.rb new file mode 100644 index 00000000..5a270e83 --- /dev/null +++ b/spec/input/sources/local_input_source_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'mindee' + +describe Mindee::Input::Source::PathInputSource do + let(:input_file) { "#{DATA_DIR}/products/invoices/default_sample.jpg" } + let(:output_dir) { "#{DATA_DIR}/output/" } + + describe '#write_to_file' do + let(:local_input_source) { described_class.new(input_file) } + + context 'when a local input source is properly loaded' do + it 'saves the file without a provided filename' do + local_input_source.write_to_file(output_dir) + rendered_file = "#{output_dir}/default_sample.jpg" + expect(File.exist?(output_dir)).to be true + expect(FileUtils.compare_file(rendered_file, input_file)).to be true + end + + it 'saves the file with a provided filename' do + local_input_source.write_to_file("#{output_dir}/custom_filename.jpg") + custom_file = "#{output_dir}/custom_filename.jpg" + expect(File.exist?(custom_file)).to be true + expect(FileUtils.compare_file(custom_file, input_file)).to be true + end + end + + after(:each) do + FileUtils.rm_f("#{output_dir}/default_sample.jpg") + FileUtils.rm_f("#{output_dir}/custom_filename.jpg") + end + end +end diff --git a/spec/input/sources/sources_spec.rb b/spec/input/sources/sources_spec.rb new file mode 100644 index 00000000..3ea20f04 --- /dev/null +++ b/spec/input/sources/sources_spec.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +require 'mindee' +require 'mindee/input/sources' +require 'mindee/errors' +require 'pdf-reader' + +require_relative '../../data' + +describe Mindee::Input::Source do + context 'An image input file' do + it 'should load a JPEG from a path' do + input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.jpg')) + expect(input.file_mimetype).to eq('image/jpeg') + + input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.jpga')) + expect(input.file_mimetype).to eq('image/jpeg') + end + + it 'should load a TIFF from a path' do + input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.tif')) + expect(input.file_mimetype).to eq('image/tiff') + + input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.tiff')) + expect(input.file_mimetype).to eq('image/tiff') + end + + it 'should load a HEIC from a path' do + input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.heic')) + expect(input.file_mimetype).to eq('image/heic') + end + end + + context 'A PDF input file' do + it 'should load a multi-page PDF from a path' do + input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice.pdf')) + expect(input.file_mimetype).to eq('application/pdf') + expect(input.pdf?).to eq(true) + + input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice.pdf')) + expect(input.file_mimetype).to eq('application/pdf') + expect(input.pdf?).to eq(true) + + input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice_10p.pdf')) + expect(input.file_mimetype).to eq('application/pdf') + expect(input.pdf?).to eq(true) + + input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice_10p.pdf')) + expect(input.file_mimetype).to eq('application/pdf') + expect(input.pdf?).to eq(true) + end + end + + context 'A broken fixable PDF' do + mindee_client = Mindee::Client.new(api_key: 'invalid-api-key') + it 'Should not raise a mime error' do + expect do + mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_fixable.pdf", repair_pdf: true) + end.not_to raise_error + end + end + + context 'A broken unfixable PDF' do + mindee_client = Mindee::Client.new(api_key: 'invalid-api-key') + it 'Should raise an error' do + expect do + mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_unfixable.pdf", repair_pdf: true) + end.to raise_error Mindee::Errors::MindeePDFError + end + end + + context 'A broken fixable invoice PDF' do + mindee_client = Mindee::Client.new(api_key: 'invalid-api-key') + it 'Should send correct results' do + source_doc_original = mindee_client.source_from_path("#{DATA_DIR}/products/invoices/invoice.pdf") + expect do + source_doc_fixed = mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_invoice.pdf", + repair_pdf: true) + expect(source_doc_fixed.read_contents[1].to_s).to eq(source_doc_original.read_contents[1].to_s) + end.not_to raise_error + end + end +end diff --git a/spec/input/url_input_source_integration.rb b/spec/input/sources/url_input_source_integration.rb similarity index 80% rename from spec/input/url_input_source_integration.rb rename to spec/input/sources/url_input_source_integration.rb index 0719d875..9f8d25cd 100644 --- a/spec/input/url_input_source_integration.rb +++ b/spec/input/sources/url_input_source_integration.rb @@ -1,13 +1,12 @@ # frozen_string_literal: true -require 'rspec' require 'mindee' -describe Mindee::Input::Source::UrlInputSource do +describe Mindee::Input::Source::URLInputSource do it 'retrieves response from a remote file' do api_key = ENV.fetch('MINDEE_API_KEY', nil) client = Mindee::Client.new(api_key: api_key) - remote_input = Mindee::Input::Source::UrlInputSource.new('https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/invoice_5p.pdf?raw=true') + remote_input = Mindee::Input::Source::URLInputSource.new('https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/invoice_5p.pdf?raw=true') local_input = remote_input.as_local_input_source expect(local_input.filename).to eq('invoice_5p.pdf') diff --git a/spec/input/url_input_source_spec.rb b/spec/input/sources/url_input_source_spec.rb similarity index 80% rename from spec/input/url_input_source_spec.rb rename to spec/input/sources/url_input_source_spec.rb index 12cc4b8d..3a0db99c 100644 --- a/spec/input/url_input_source_spec.rb +++ b/spec/input/sources/url_input_source_spec.rb @@ -1,10 +1,9 @@ # frozen_string_literal: true -require 'rspec' require 'mindee' -require_relative '../http/mock_http_response' +require_relative '../../http/mock_http_response' -RSpec.describe Mindee::Input::Source::UrlInputSource do +describe Mindee::Input::Source::URLInputSource do let(:valid_url) { 'https://validurl/some/file.jpg' } let(:valid_url_no_filename) { 'https://validurl/some/' } let(:invalid_url) { 'http://invalidurl/some/file.jpg' } @@ -20,7 +19,7 @@ context 'with invalid URL' do it 'raises an error for invalid URLs' do - expect { described_class.new(invalid_url) }.to raise_error('URL must be HTTPS') + expect { described_class.new(invalid_url) }.to raise_error(Mindee::Errors::MindeeInputError) end end end @@ -59,12 +58,14 @@ let(:mock_response) { MockHTTPResponse.new('1.1', '404', 'Not Found', '') } it 'raises an error' do - expect { url_input_source.as_local_input_source }.to raise_error(RuntimeError, %r{Failed to download file}) + expect do + url_input_source.as_local_input_source + end.to raise_error(Mindee::Errors::MindeeAPIError, %r{Failed to download file}) end end end - describe '#save_to_file' do + describe '#write_to_file' do let(:url_input_source) { described_class.new(valid_url) } let(:url_input_source_no_filename) { described_class.new(valid_url_no_filename) } @@ -77,23 +78,23 @@ let(:mock_response) { MockHTTPResponse.new('1.1', '200', 'OK', 'file content') } it 'generates a valid filename when not provided' do - output_file_path = url_input_source_no_filename.save_to_file(output_dir) + output_file_path = url_input_source_no_filename.write_to_file(output_dir) expect(output_file_path).to match(%r{mindee_temp_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}_[a-z0-9]{8}\.tmp}) end it 'saves the file with the provided filename' do - result = url_input_source.save_to_file('/tmp', filename: 'file.pdf') + result = url_input_source.write_to_file('/tmp', filename: 'file.pdf') expect(result).to eq('/tmp/file.pdf') expect(File).to have_received(:write).with('/tmp/file.pdf', 'file content') end it 'uses a custom filename when provided' do - result = url_input_source.save_to_file('/tmp', filename: 'custom.pdf') + result = url_input_source.write_to_file('/tmp', filename: 'custom.pdf') expect(result).to eq('/tmp/custom.pdf') end it 'handles authentication' do - result = url_input_source_no_filename.save_to_file('/tmp', username: 'user', password: 'pass') + result = url_input_source_no_filename.write_to_file('/tmp', username: 'user', password: 'pass') expect(result).to match(%r{/tmp/mindee_temp_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}_[a-z0-9]{8}\.tmp}) end end @@ -102,7 +103,9 @@ let(:mock_response) { MockHTTPResponse.new('1.1', '404', 'Not Found', '') } it 'raises an error' do - expect { url_input_source.save_to_file('/tmp') }.to raise_error(RuntimeError, %r{Failed to download file}) + expect do + url_input_source.write_to_file('/tmp') + end.to raise_error(Mindee::Errors::MindeeAPIError, %r{Failed to download file}) end end end diff --git a/spec/input/sources_spec.rb b/spec/input/sources_spec.rb deleted file mode 100644 index 72c2244b..00000000 --- a/spec/input/sources_spec.rb +++ /dev/null @@ -1,231 +0,0 @@ -# frozen_string_literal: true - -require 'mindee' -require 'mindee/input/sources' -require 'pdf-reader' - -require_relative '../data' - -describe Mindee::Input::Source do - context 'An image input file' do - it 'should load a JPEG from a path' do - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.jpg')) - expect(input.file_mimetype).to eq('image/jpeg') - - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.jpga')) - expect(input.file_mimetype).to eq('image/jpeg') - end - - it 'should load a TIFF from a path' do - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.tif')) - expect(input.file_mimetype).to eq('image/tiff') - - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.tiff')) - expect(input.file_mimetype).to eq('image/tiff') - end - - it 'should load a HEIC from a path' do - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.heic')) - expect(input.file_mimetype).to eq('image/heic') - end - end - - context 'A PDF input file' do - it 'should load a multi-page PDF from a path' do - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice.pdf')) - expect(input.file_mimetype).to eq('application/pdf') - expect(input.pdf?).to eq(true) - - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice.pdf')) - expect(input.file_mimetype).to eq('application/pdf') - expect(input.pdf?).to eq(true) - - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice_10p.pdf')) - expect(input.file_mimetype).to eq('application/pdf') - expect(input.pdf?).to eq(true) - - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice_10p.pdf')) - expect(input.file_mimetype).to eq('application/pdf') - expect(input.pdf?).to eq(true) - end - end - - context 'A broken fixable PDF' do - mindee_client = Mindee::Client.new(api_key: 'invalid-api-key') - it 'Should not raise a mime error' do - expect do - mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_fixable.pdf", fix_pdf: true) - end.not_to raise_error - end - end - - context 'A broken unfixable PDF' do - mindee_client = Mindee::Client.new(api_key: 'invalid-api-key') - it 'Should raise an error' do - expect do - mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_unfixable.pdf", fix_pdf: true) - end.to raise_error Mindee::Input::Source::UnfixablePDFError - end - end - - context 'A broken fixable invoice PDF' do - mindee_client = Mindee::Client.new(api_key: 'invalid-api-key') - it 'Should send correct results' do - source_doc_original = mindee_client.source_from_path("#{DATA_DIR}/products/invoices/invoice.pdf") - expect do - source_doc_fixed = mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_invoice.pdf", - fix_pdf: true) - expect(source_doc_fixed.read_document[1].to_s).to eq(source_doc_original.read_document[1].to_s) - end.not_to raise_error - end - end - - describe 'Image Quality Compression' do - let(:input_receipt_path) { "#{DATA_DIR}/file_types/receipt.jpg" } - let(:output_dir) { "#{DATA_DIR}/output/" } - - it 'should compress the image from input source' do - receipt_input = Mindee::Input::Source::PathInputSource.new(input_receipt_path) - receipt_input.compress!(quality: 80) # NOTE: base jpg quality is ~81 - - FileUtils.mkdir_p(File.dirname("#{output_dir}compress_indirect.jpg")) - File.write("#{output_dir}compress_indirect.jpg", receipt_input.io_stream.read) - - initial_file_size = File.size(input_receipt_path) - compressed_file_size = File.size(output_dir) - - expect(compressed_file_size).to be < initial_file_size - end - - it 'should compress the image with various quality levels' do - receipt_input = Mindee::Input::Source::PathInputSource.new(input_receipt_path) - - compresses = [ - Mindee::Image::ImageCompressor.compress_image(receipt_input.io_stream, quality: 100), - Mindee::Image::ImageCompressor.compress_image(receipt_input.io_stream), # default quality - Mindee::Image::ImageCompressor.compress_image(receipt_input.io_stream, quality: 50), - Mindee::Image::ImageCompressor.compress_image(receipt_input.io_stream, quality: 10), - Mindee::Image::ImageCompressor.compress_image(receipt_input.io_stream, quality: 1), - ] - - output_files = [ - "#{output_dir}/compress100.jpg", - "#{output_dir}/compress85.jpg", - "#{output_dir}/compress50.jpg", - "#{output_dir}/compress10.jpg", - "#{output_dir}/compress1.jpg", - ] - - compresses.zip(output_files).each do |compressed, output_file| - File.write(output_file, compressed.read) - end - - initial_file_size = File.size(input_receipt_path) - rendered_file_sizes = output_files.map { |file| File.size(file) } - - expect(initial_file_size).to be < rendered_file_sizes[0] - expect(initial_file_size).to be < rendered_file_sizes[1] - expect(rendered_file_sizes[1]).to be > rendered_file_sizes[2] - expect(rendered_file_sizes[2]).to be > rendered_file_sizes[3] - expect(rendered_file_sizes[3]).to be > rendered_file_sizes[4] - end - - after(:each) do - FileUtils.rm_f("#{output_dir}/compress100.jpg") - FileUtils.rm_f("#{output_dir}/compress85.jpg") - FileUtils.rm_f("#{output_dir}/compress50.jpg") - FileUtils.rm_f("#{output_dir}/compress10.jpg") - FileUtils.rm_f("#{output_dir}/compress1.jpg") - FileUtils.rm_f("#{output_dir}/compress_indirect.jpg") - end - end - - describe 'The PDF text detection method' do - it 'should detect text pdf in a PDF file.' do - text_input = Mindee::Input::Source::PathInputSource.new("#{DATA_DIR}/file_types/pdf/multipage.pdf") - expect(Mindee::PDF::PDFTools.source_text?(text_input.io_stream)).to be(true) - end - - it 'should not detect text pdf in an empty PDF file.' do - no_text_input = Mindee::Input::Source::PathInputSource.new( - "#{DATA_DIR}/file_types/pdf/blank_1.pdf" - ) - expect(Mindee::PDF::PDFTools.source_text?(no_text_input.io_stream)).to be(false) - end - - it 'should not detect text pdf in an image file.' do - image_input = Mindee::Input::Source::PathInputSource.new("#{DATA_DIR}/file_types/receipt.jpg") - expect(Mindee::PDF::PDFTools.source_text?(image_input.io_stream)).to be(false) - end - end - - describe 'PDF compression' do - it 'should compress from an input source' do - input_file_path = "#{DATA_DIR}/products/invoice_splitter/default_sample.pdf" - output_file_path = "#{DATA_DIR}/output/compress_indirect.pdf" - pdf_input = Mindee::Input::Source::PathInputSource.new("#{DATA_DIR}/products/invoice_splitter/default_sample.pdf") - pdf_input.compress!(quality: 50) - File.write(output_file_path, pdf_input.io_stream.read) - expect(File.size(output_file_path)).to be < File.size(input_file_path) - end - - it 'should compress from the compressor' do - input_file_path = "#{DATA_DIR}/products/invoice_splitter/default_sample.pdf" - output_file_paths = { - 85 => "#{DATA_DIR}/output/compressed_direct_85.pdf", - 75 => "#{DATA_DIR}/output/compressed_direct_75.pdf", - 50 => "#{DATA_DIR}/output/compressed_direct_50.pdf", - 10 => "#{DATA_DIR}/output/compressed_direct_10.pdf", - } - pdf = File.open(input_file_path) - output_file_paths.each_pair do |key, value| - compressed_pdf = Mindee::PDF::PDFCompressor.compress_pdf(pdf, quality: key) - compressed_pdf.rewind - File.write(value, compressed_pdf.read) - end - expect(File.size(input_file_path)).to be > File.size(output_file_paths[85]) - expect(File.size(output_file_paths[75])).to be < File.size(output_file_paths[85]) - expect(File.size(output_file_paths[50])).to be < File.size(output_file_paths[75]) - expect(File.size(output_file_paths[10])).to be < File.size(output_file_paths[50]) - end - - after(:each) do - output_dir = "#{DATA_DIR}/output" - FileUtils.rm_f("#{output_dir}/compressed_direct_85.pdf") - FileUtils.rm_f("#{output_dir}/compressed_direct_75.pdf") - FileUtils.rm_f("#{output_dir}/compressed_direct_50.pdf") - FileUtils.rm_f("#{output_dir}/compressed_direct_10.pdf") - FileUtils.rm_f("#{output_dir}/compress_indirect.pdf") - end - end - - describe 'source text PDF compression' do - it 'should compress if forced' do - input_file_path = "#{DATA_DIR}/file_types/pdf/multipage.pdf" - output_file_path = "#{DATA_DIR}/output/compress_with_text.pdf" - pdf_input = Mindee::Input::Source::PathInputSource.new(input_file_path) - pdf_input.compress!(quality: 50, force_source_text: true, disable_source_text: false) - File.write(output_file_path, pdf_input.io_stream.read) - expect(File.size(output_file_path)).to be > File.size(input_file_path) - - pdf_input.io_stream.rewind - reader = PDFReader::Reader.new(pdf_input.io_stream) - - text = '' - reader.pages.each do |original_page| - receiver = PDFReader::Reader::PageTextReceiver.new - original_page.walk(receiver) - - receiver.runs.each do |text_run| - text += text_run.text - end - end - expect(text).to eq('*' * 650) - end - - after(:each) do - output_dir = "#{DATA_DIR}/output" - FileUtils.rm_f("#{output_dir}/compress_with_text.pdf") - end - end -end diff --git a/spec/ocr_spec.rb b/spec/ocr_spec.rb index 7fe42b28..287439d8 100644 --- a/spec/ocr_spec.rb +++ b/spec/ocr_spec.rb @@ -13,7 +13,7 @@ json_data = load_json(DIR_OCR, 'complete.json') it 'should extract ocr data from a document' do expected_text = read_file(DIR_OCR, 'ocr.txt') - ocr = Mindee::Parsing::Common::Ocr::Ocr.new(json_data['document']['ocr']) + ocr = Mindee::Parsing::Common::OCR::OCR.new(json_data['document']['ocr']) expect(ocr.to_s).to eq(expected_text) expect(ocr.mvision_v1.pages[0].to_s).to eq(expected_text) end diff --git a/spec/fields/date_field_spec.rb b/spec/parsing/standard/date_field_spec.rb similarity index 100% rename from spec/fields/date_field_spec.rb rename to spec/parsing/standard/date_field_spec.rb diff --git a/spec/fields/string_field_spec.rb b/spec/parsing/standard/string_field_spec.rb similarity index 100% rename from spec/fields/string_field_spec.rb rename to spec/parsing/standard/string_field_spec.rb diff --git a/spec/parsing/universal/universal_list_field_spec.rb b/spec/parsing/universal/universal_list_field_spec.rb new file mode 100644 index 00000000..eb8ff92e --- /dev/null +++ b/spec/parsing/universal/universal_list_field_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'mindee' + +describe Mindee::Parsing::Universal::UniversalListField do + let(:raw_prediction) { [{ 'value' => 'Item1' }, { 'value' => 'Item2' }] } + subject(:universal_list_field) { described_class.new(raw_prediction) } + + describe '#contents_list' do + it 'returns an array with the string representations of each value' do + expect(universal_list_field.contents_list).to eq(['Item1', 'Item2']) + end + + context 'when initialized with an empty array' do + let(:raw_prediction) { [] } + it 'returns an empty array' do + expect(universal_list_field.contents_list).to be_empty + end + end + end + + describe '#contents_string' do + it 'returns a space-separated string of the values by default' do + expect(universal_list_field.contents_string).to eq('Item1 Item2') + end + + it 'returns a string with a custom separator when provided' do + expect(universal_list_field.contents_string(',')).to eq('Item1,Item2') + end + end + + describe '#to_s' do + it 'returns the same output as the default contents_string' do + expect(universal_list_field.to_s).to eq(universal_list_field.contents_string) + end + end +end diff --git a/spec/parsing/universal/universal_object_field_spec.rb b/spec/parsing/universal/universal_object_field_spec.rb new file mode 100644 index 00000000..22c1e4f9 --- /dev/null +++ b/spec/parsing/universal/universal_object_field_spec.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +require 'mindee' + +describe Mindee::Parsing::Universal::UniversalObjectField do + let(:raw_prediction) do + { + 'page_id' => 3, + 'confidence' => 0.85, + 'raw_value' => { 'info' => 'raw' }, + 'custom_field' => 'TestValue', + 'extra_field' => 'Extra', + } + end + subject(:object_field) { described_class.new(raw_prediction) } + + describe '#initialize' do + it 'sets the page_id from the raw prediction' do + expect(object_field.page_id).to eq(3) + end + + it 'sets the confidence value' do + expect(object_field.confidence).to eq(0.85) + end + + it 'stores the raw_value correctly' do + expect(object_field.raw_value).to eq({ 'info' => 'raw' }) + end + end + + describe 'handling default fields' do + it 'converts non-special fields to strings and makes them accessible' do + expect(object_field.custom_field).to eq('TestValue') + expect(object_field.extra_field).to eq('Extra') + end + + it 'responds to dynamic methods for available fields' do + expect(object_field.respond_to?(:custom_field)).to be true + expect(object_field.respond_to?(:extra_field)).to be true + end + + it 'does not respond to undefined fields' do + expect(object_field.respond_to?(:undefined_field)).to be false + end + end + + describe '#str_level' do + it 'returns a formatted string with the stored fields and proper indentation' do + output = object_field.str_level(1) + expect(output).to be_a(String) + expect(output).to include(':custom_field: TestValue') + expect(output).to include(':extra_field: Extra') + end + end + + describe 'method_missing behavior' do + it 'raises NoMethodError for missing fields' do + expect { object_field.nonexistent_field }.to raise_error(NoMethodError) + end + end + + context 'when raw_prediction includes a position field' do + let(:rect_prediction) do + { + 'page_id' => 5, + 'rectangle' => [[0.1, 0.2], [0.1, 0.3], [0.2, 0.1], [0.2, 0.3]], + 'useless_field' => 'ToCheckForNoErrors', + } + end + subject(:object_field_with_rect) { described_class.new(rect_prediction) } + + it 'handles the position key by setting it as a PositionField instance' do + position_field = object_field_with_rect.rectangle + expect(position_field).to be_a(Mindee::Parsing::Standard::PositionField) + end + end + + describe '#to_s' do + it 'returns the same output as calling str_level without arguments' do + expect(object_field.to_s).to eq(object_field.str_level) + end + end +end diff --git a/spec/pdf/extracted_pdf_spec.rb b/spec/pdf/extracted_pdf_spec.rb new file mode 100644 index 00000000..4056b339 --- /dev/null +++ b/spec/pdf/extracted_pdf_spec.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true + +require 'mindee' + +describe Mindee::PDF::PDFExtractor::ExtractedPDF do + let(:product_data_dir) { File.join(DATA_DIR, 'products') } + let(:output_dir) { File.join(DATA_DIR, 'output') } + let(:file_types_dir) { File.join(DATA_DIR, 'file_types') } + let(:valid_pdf_path) { "#{product_data_dir}/invoices/invoice.pdf" } + let(:invalid_pdf_path) { "#{file_types_dir}/receipt.txt" } + let(:output_path) { "#{output_dir}/sample_output.pdf" } + + before do + allow(File).to receive(:directory?).and_return(false) + allow(File).to receive(:exist?).and_return(true) + allow(File).to receive(:extname).and_return('.pdf') + allow(File).to receive(:write) + end + + describe '#initialize' do + it 'initializes with valid pdf bytes and filename' do + pdf_stream = File.open(valid_pdf_path, 'r') + extracted_pdf = described_class.new(pdf_stream, 'invoice.pdf') + + expect(extracted_pdf.pdf_bytes).to eq(pdf_stream) + expect(extracted_pdf.filename).to eq('invoice.pdf') + end + end + + describe '#page_count' do + it 'raises an error for invalid PDF content' do + jpg_stream = File.open(invalid_pdf_path, 'r') + pdf_wrapper = described_class.new(jpg_stream, 'dummy.pdf') + + expect do + pdf_wrapper.page_count + end.to raise_error Mindee::Errors::MindeePDFError, %r{Could not retrieve page count} + end + + it 'returns the correct page count for a valid PDF' do + pdf_stream = File.open(valid_pdf_path, 'r') + allow(Mindee::PDF::PDFProcessor).to receive(:open_pdf).and_return(double(pages: [1, 2, 3])) + pdf_wrapper = described_class.new(pdf_stream, 'invoice.pdf') + + expect(pdf_wrapper.page_count).to eq(3) + end + end + + describe '#write_to_file' do + it 'writes the PDF bytes to a specified file path' do + pdf_stream = File.open(valid_pdf_path, 'r') + pdf_wrapper = described_class.new(pdf_stream, 'invoice.pdf') + + expect { pdf_wrapper.write_to_file(output_path) }.not_to raise_error + expect(File).to have_received(:write).with(output_path, pdf_stream) + end + + it 'raises an error if the output path is a directory' do + allow(File).to receive(:directory?).and_return(true) + pdf_stream = File.open(valid_pdf_path, 'r') + pdf_wrapper = described_class.new(pdf_stream, 'invoice.pdf') + + expect do + pdf_wrapper.write_to_file(output_path) + end.to raise_error Mindee::Errors::MindeePDFError, %r{Provided path is not a file} + end + + it 'raises an error if the save path is invalid' do + allow(File).to receive(:exist?).and_return(false) + pdf_stream = File.open(valid_pdf_path, 'r') + pdf_wrapper = described_class.new(pdf_stream, 'invoice.pdf') + + expect do + pdf_wrapper.write_to_file(output_path) + end.to raise_error Mindee::Errors::MindeePDFError, %r{Invalid save path provided} + end + end + + describe '#as_input_source' do + it 'returns a BytesInputSource object with correct attributes' do + pdf_stream = StringIO.new('pdf content') + input_source_double = double('BytesInputSource', content: 'pdf content', filename: 'invoice.pdf') + + allow(Mindee::Input::Source::BytesInputSource).to receive(:new).and_return(input_source_double) + + pdf_wrapper = described_class.new(pdf_stream, 'invoice.pdf') + input_source = pdf_wrapper.as_input_source + + expect(input_source.content).to eq('pdf content') + expect(input_source.filename).to eq('invoice.pdf') + end + end +end diff --git a/spec/pdf/pdf_compressor_spec.rb b/spec/pdf/pdf_compressor_spec.rb new file mode 100644 index 00000000..bb36d87c --- /dev/null +++ b/spec/pdf/pdf_compressor_spec.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true + +require 'mindee' + +require_relative '../data' + +describe Mindee::PDF::PDFCompressor do + describe 'The PDF text detection method' do + it 'should detect text pdf in a PDF file.' do + text_input = Mindee::Input::Source::PathInputSource.new("#{DATA_DIR}/file_types/pdf/multipage.pdf") + expect(Mindee::PDF::PDFTools.source_text?(text_input.io_stream)).to be(true) + end + + it 'should not detect text pdf in an empty PDF file.' do + no_text_input = Mindee::Input::Source::PathInputSource.new( + "#{DATA_DIR}/file_types/pdf/blank_1.pdf" + ) + expect(Mindee::PDF::PDFTools.source_text?(no_text_input.io_stream)).to be(false) + end + + it 'should not detect text pdf in an image file.' do + image_input = Mindee::Input::Source::PathInputSource.new("#{DATA_DIR}/file_types/receipt.jpg") + expect(Mindee::PDF::PDFTools.source_text?(image_input.io_stream)).to be(false) + end + end + + describe 'PDF compression' do + it 'should compress from an input source' do + input_file_path = "#{DATA_DIR}/products/invoice_splitter/default_sample.pdf" + output_file_path = "#{DATA_DIR}/output/compress_indirect.pdf" + pdf_input = Mindee::Input::Source::PathInputSource.new("#{DATA_DIR}/products/invoice_splitter/default_sample.pdf") + pdf_input.compress!(quality: 50) + File.write(output_file_path, pdf_input.io_stream.read) + expect(File.size(output_file_path)).to be < File.size(input_file_path) + end + + it 'should compress from the compressor' do + input_file_path = "#{DATA_DIR}/products/invoice_splitter/default_sample.pdf" + output_file_paths = { + 85 => "#{DATA_DIR}/output/compressed_direct_85.pdf", + 75 => "#{DATA_DIR}/output/compressed_direct_75.pdf", + 50 => "#{DATA_DIR}/output/compressed_direct_50.pdf", + 10 => "#{DATA_DIR}/output/compressed_direct_10.pdf", + } + pdf = File.open(input_file_path) + output_file_paths.each_pair do |key, value| + compressed_pdf = Mindee::PDF::PDFCompressor.compress_pdf(pdf, quality: key) + compressed_pdf.rewind + File.write(value, compressed_pdf.read) + end + expect(File.size(input_file_path)).to be > File.size(output_file_paths[85]) + expect(File.size(output_file_paths[75])).to be < File.size(output_file_paths[85]) + expect(File.size(output_file_paths[50])).to be < File.size(output_file_paths[75]) + expect(File.size(output_file_paths[10])).to be < File.size(output_file_paths[50]) + end + + after(:each) do + output_dir = "#{DATA_DIR}/output" + FileUtils.rm_f("#{output_dir}/compressed_direct_85.pdf") + FileUtils.rm_f("#{output_dir}/compressed_direct_75.pdf") + FileUtils.rm_f("#{output_dir}/compressed_direct_50.pdf") + FileUtils.rm_f("#{output_dir}/compressed_direct_10.pdf") + FileUtils.rm_f("#{output_dir}/compress_indirect.pdf") + end + end + + describe 'source text PDF compression' do + it 'should compress if forced' do + input_file_path = "#{DATA_DIR}/file_types/pdf/multipage.pdf" + output_file_path = "#{DATA_DIR}/output/compress_with_text.pdf" + pdf_input = Mindee::Input::Source::PathInputSource.new(input_file_path) + pdf_input.compress!(quality: 50, force_source_text: true, disable_source_text: false) + File.write(output_file_path, pdf_input.io_stream.read) + expect(File.size(output_file_path)).to be > File.size(input_file_path) + + pdf_input.io_stream.rewind + reader = PDFReader::Reader.new(pdf_input.io_stream) + + text = '' + reader.pages.each do |original_page| + receiver = PDFReader::Reader::PageTextReceiver.new + original_page.walk(receiver) + + receiver.runs.each do |text_run| + text += text_run.text + end + end + expect(text).to eq('*' * 650) + end + + after(:each) do + output_dir = "#{DATA_DIR}/output" + FileUtils.rm_f("#{output_dir}/compress_with_text.pdf") + end + end +end diff --git a/spec/extraction/pdf_extractor_spec.rb b/spec/pdf/pdf_extractor_spec.rb similarity index 90% rename from spec/extraction/pdf_extractor_spec.rb rename to spec/pdf/pdf_extractor_spec.rb index e8ca5e2c..19c208e0 100644 --- a/spec/extraction/pdf_extractor_spec.rb +++ b/spec/pdf/pdf_extractor_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'mindee' -require 'rspec' describe 'Invoice extraction' do let(:product_data_dir) { File.join(DATA_DIR, 'products') } @@ -20,13 +19,13 @@ jpg_input = Mindee::Input::Source::PathInputSource.new(invoice_default_sample_path) expect(jpg_input.pdf?).to eq(false) - extractor = Mindee::Extraction::PdfExtractor::PdfExtractor.new(jpg_input) + extractor = Mindee::PDF::PDFExtractor::PDFExtractor.new(jpg_input) expect(extractor.page_count).to eq(1) end it 'should extract invoices from a PDF (no strict mode)' do pdf_input = Mindee::Input::Source::PathInputSource.new(invoice_splitter_5p_path) - extractor = Mindee::Extraction::PdfExtractor::PdfExtractor.new(pdf_input) + extractor = Mindee::PDF::PDFExtractor::PDFExtractor.new(pdf_input) expect(extractor.page_count).to eq(5) @@ -45,7 +44,7 @@ it 'should extract invoices from a PDF (strict mode)' do pdf_input = Mindee::Input::Source::PathInputSource.new(invoice_splitter_5p_path) - extractor = Mindee::Extraction::PdfExtractor::PdfExtractor.new(pdf_input) + extractor = Mindee::PDF::PDFExtractor::PDFExtractor.new(pdf_input) expect(extractor.page_count).to eq(5) expect(loaded_prediction.invoice_page_groups.length).to eq(3) diff --git a/spec/pdf/pdf_processor_spec.rb b/spec/pdf/pdf_processor_spec.rb new file mode 100644 index 00000000..63eda9b4 --- /dev/null +++ b/spec/pdf/pdf_processor_spec.rb @@ -0,0 +1,125 @@ +# frozen_string_literal: true + +require 'mindee' + +require_relative '../data' + +describe Mindee::PDF do + def open_pdf(io_stream) + pdf_parser = Origami::PDF::LinearParser.new({}) + io_stream.seek(0) + pdf_parser.parse(io_stream) + end + + context 'A single page PDF' do + filepath = File.join(DATA_DIR, 'file_types/pdf/blank.pdf').freeze + + it 'Should grab the first page' do + io_stream = File.open(filepath, 'rb') + io_stream.seek(0) + options = Mindee::PageOptions.new(params: { + page_indexes: [0], + operation: :KEEP_ONLY, + on_min_pages: 0, + }) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) + new_pdf = open_pdf(new_stream) + expect(new_pdf.pages.size).to eq(1) + end + + it 'Should grab the last page' do + io_stream = File.open(filepath, 'rb') + io_stream.seek(0) + options = Mindee::PageOptions.new(params: { + page_indexes: [-1], + operation: :KEEP_ONLY, + on_min_pages: 0, + }) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) + new_pdf = open_pdf(new_stream) + expect(new_pdf.pages.size).to eq(1) + end + end + + context 'A multi-page PDF' do + filepath = File.join(DATA_DIR, 'file_types/pdf/multipage.pdf').freeze + + it 'Should grab the first page' do + io_stream = File.open(filepath, 'rb') + io_stream.seek(0) + options = Mindee::PageOptions.new(params: { + page_indexes: [0], + operation: :KEEP_ONLY, + on_min_pages: 0, + }) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) + new_pdf = open_pdf(new_stream) + expect(new_pdf.pages.size).to eq(1) + end + + it 'Should grab the last page' do + io_stream = File.open(filepath, 'rb') + io_stream.seek(0) + options = Mindee::PageOptions.new(params: { + page_indexes: [-1], + operation: :KEEP_ONLY, + on_min_pages: 0, + }) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) + new_pdf = open_pdf(new_stream) + expect(new_pdf.pages.size).to eq(1) + end + + it 'Should grab the first 2, and the last page' do + io_stream = File.open(filepath, 'rb') + io_stream.seek(0) + options = Mindee::PageOptions.new(params: { + page_indexes: [0, 1, -1], + operation: :KEEP_ONLY, + on_min_pages: 0, + }) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) + new_pdf = open_pdf(new_stream) + expect(new_pdf.pages.size).to eq(3) + end + + it 'Should grab the first 5 pages' do + io_stream = File.open(filepath, 'rb') + io_stream.seek(0) + options = Mindee::PageOptions.new(params: { + page_indexes: [0, 1, 2, 3, 4], + operation: :KEEP_ONLY, + on_min_pages: 0, + }) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) + new_pdf = open_pdf(new_stream) + expect(new_pdf.pages.size).to eq(5) + end + + it 'Should remove the first 3 pages' do + io_stream = File.open(filepath, 'rb') + io_stream.seek(0) + options = Mindee::PageOptions.new(params: { + page_indexes: [0, 1, 2], + operation: :REMOVE, + on_min_pages: 0, + }) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) + new_pdf = open_pdf(new_stream) + expect(new_pdf.pages.size).to eq(9) + end + + it 'Should fail on invalid operation' do + io_stream = File.open(filepath, 'rb') + io_stream.seek(0) + options = Mindee::PageOptions.new(params: { + page_indexes: [1], + operation: :broken, + on_min_pages: 0, + }) + expect do + Mindee::PDF::PDFProcessor.parse(io_stream, options) + end.to raise_error ArgumentError + end + end +end diff --git a/spec/document/barcode_reader_v1_spec.rb b/spec/product/barcode_reader_v1_spec.rb similarity index 100% rename from spec/document/barcode_reader_v1_spec.rb rename to spec/product/barcode_reader_v1_spec.rb diff --git a/spec/document/bill_of_lading_v1_spec.rb b/spec/product/bill_of_lading_v1_spec.rb similarity index 100% rename from spec/document/bill_of_lading_v1_spec.rb rename to spec/product/bill_of_lading_v1_spec.rb diff --git a/spec/document/business_card_v1_spec.rb b/spec/product/business_card_v1_spec.rb similarity index 100% rename from spec/document/business_card_v1_spec.rb rename to spec/product/business_card_v1_spec.rb diff --git a/spec/document/cropper_v1_spec.rb b/spec/product/cropper_v1_spec.rb similarity index 100% rename from spec/document/cropper_v1_spec.rb rename to spec/product/cropper_v1_spec.rb diff --git a/spec/document/delivery_note_v1_spec.rb b/spec/product/delivery_note_v1_spec.rb similarity index 100% rename from spec/document/delivery_note_v1_spec.rb rename to spec/product/delivery_note_v1_spec.rb diff --git a/spec/document/driver_license_v1_spec.rb b/spec/product/driver_license_v1_spec.rb similarity index 100% rename from spec/document/driver_license_v1_spec.rb rename to spec/product/driver_license_v1_spec.rb diff --git a/spec/document/eu/license_plate_v1_spec.rb b/spec/product/eu/license_plate_v1_spec.rb similarity index 100% rename from spec/document/eu/license_plate_v1_spec.rb rename to spec/product/eu/license_plate_v1_spec.rb diff --git a/spec/document/financial_document_v1_spec.rb b/spec/product/financial_document_v1_spec.rb similarity index 100% rename from spec/document/financial_document_v1_spec.rb rename to spec/product/financial_document_v1_spec.rb diff --git a/spec/document/fr/bank_account_details_v1_spec.rb b/spec/product/fr/bank_account_details_v1_spec.rb similarity index 100% rename from spec/document/fr/bank_account_details_v1_spec.rb rename to spec/product/fr/bank_account_details_v1_spec.rb diff --git a/spec/document/fr/bank_account_details_v2_spec.rb b/spec/product/fr/bank_account_details_v2_spec.rb similarity index 100% rename from spec/document/fr/bank_account_details_v2_spec.rb rename to spec/product/fr/bank_account_details_v2_spec.rb diff --git a/spec/document/fr/bank_statement_v2_spec.rb b/spec/product/fr/bank_statement_v2_spec.rb similarity index 100% rename from spec/document/fr/bank_statement_v2_spec.rb rename to spec/product/fr/bank_statement_v2_spec.rb diff --git a/spec/document/fr/carte_grise_v1_spec.rb b/spec/product/fr/carte_grise_v1_spec.rb similarity index 100% rename from spec/document/fr/carte_grise_v1_spec.rb rename to spec/product/fr/carte_grise_v1_spec.rb diff --git a/spec/document/fr/energy_bill_v1_spec.rb b/spec/product/fr/energy_bill_v1_spec.rb similarity index 100% rename from spec/document/fr/energy_bill_v1_spec.rb rename to spec/product/fr/energy_bill_v1_spec.rb diff --git a/spec/document/fr/health_card_v1_spec.rb b/spec/product/fr/health_card_v1_spec.rb similarity index 100% rename from spec/document/fr/health_card_v1_spec.rb rename to spec/product/fr/health_card_v1_spec.rb diff --git a/spec/document/fr/id_card_v1_spec.rb b/spec/product/fr/id_card_v1_spec.rb similarity index 100% rename from spec/document/fr/id_card_v1_spec.rb rename to spec/product/fr/id_card_v1_spec.rb diff --git a/spec/document/fr/id_card_v2_spec.rb b/spec/product/fr/id_card_v2_spec.rb similarity index 100% rename from spec/document/fr/id_card_v2_spec.rb rename to spec/product/fr/id_card_v2_spec.rb diff --git a/spec/document/fr/payslip_v2_spec.rb b/spec/product/fr/payslip_v2_spec.rb similarity index 100% rename from spec/document/fr/payslip_v2_spec.rb rename to spec/product/fr/payslip_v2_spec.rb diff --git a/spec/document/fr/payslip_v3_spec.rb b/spec/product/fr/payslip_v3_spec.rb similarity index 100% rename from spec/document/fr/payslip_v3_spec.rb rename to spec/product/fr/payslip_v3_spec.rb diff --git a/spec/document/ind/indian_passport_v1_spec.rb b/spec/product/ind/indian_passport_v1_spec.rb similarity index 100% rename from spec/document/ind/indian_passport_v1_spec.rb rename to spec/product/ind/indian_passport_v1_spec.rb diff --git a/spec/document/international_id_v2_spec.rb b/spec/product/international_id_v2_spec.rb similarity index 100% rename from spec/document/international_id_v2_spec.rb rename to spec/product/international_id_v2_spec.rb diff --git a/spec/document/invoice_splitter_v1_spec.rb b/spec/product/invoice_splitter_v1_spec.rb similarity index 100% rename from spec/document/invoice_splitter_v1_spec.rb rename to spec/product/invoice_splitter_v1_spec.rb diff --git a/spec/document/invoice_v4_spec.rb b/spec/product/invoice_v4_spec.rb similarity index 100% rename from spec/document/invoice_v4_spec.rb rename to spec/product/invoice_v4_spec.rb diff --git a/spec/document/multi_receipts_detector_v1_spec.rb b/spec/product/multi_receipts_detector_v1_spec.rb similarity index 100% rename from spec/document/multi_receipts_detector_v1_spec.rb rename to spec/product/multi_receipts_detector_v1_spec.rb diff --git a/spec/document/nutrition_facts_label_v1_spec.rb b/spec/product/nutrition_facts_label_v1_spec.rb similarity index 100% rename from spec/document/nutrition_facts_label_v1_spec.rb rename to spec/product/nutrition_facts_label_v1_spec.rb diff --git a/spec/document/passport_v1_spec.rb b/spec/product/passport_v1_spec.rb similarity index 100% rename from spec/document/passport_v1_spec.rb rename to spec/product/passport_v1_spec.rb diff --git a/spec/document/receipt_v5_spec.rb b/spec/product/receipt_v5_spec.rb similarity index 100% rename from spec/document/receipt_v5_spec.rb rename to spec/product/receipt_v5_spec.rb diff --git a/spec/document/resume_v1_spec.rb b/spec/product/resume_v1_spec.rb similarity index 100% rename from spec/document/resume_v1_spec.rb rename to spec/product/resume_v1_spec.rb diff --git a/spec/document/generated_v1_spec.rb b/spec/product/universal_spec.rb similarity index 91% rename from spec/document/generated_v1_spec.rb rename to spec/product/universal_spec.rb index 89f38c42..5430ed1a 100644 --- a/spec/document/generated_v1_spec.rb +++ b/spec/product/universal_spec.rb @@ -1,27 +1,26 @@ # frozen_string_literal: true require 'json' -require 'mindee/product' -require 'mindee/parsing' +require 'mindee' require_relative '../data' StringField = Mindee::Parsing::Standard.const_get(:StringField) PositionField = Mindee::Parsing::Standard.const_get(:PositionField) -GeneratedListField = Mindee::Parsing::Generated.const_get(:GeneratedListField) -GeneratedObjectField = Mindee::Parsing::Generated.const_get(:GeneratedObjectField) -GeneratedV1 = Mindee::Product::Generated.const_get(:GeneratedV1) -GeneratedV1Page = Mindee::Product::Generated.const_get(:GeneratedV1Page) +UniversalListField = Mindee::Parsing::Universal.const_get(:UniversalListField) +UniversalObjectField = Mindee::Parsing::Universal.const_get(:UniversalObjectField) +Universal = Mindee::Product::Universal.const_get(:Universal) +UniversalPage = Mindee::Product::Universal.const_get(:UniversalPage) Document = Mindee::Parsing::Common.const_get(:Document) -RSpec.describe 'International ID v1 document' do +describe 'International ID v1 document' do let(:international_id_v1_complete_doc) do parsed_file = JSON.parse(File.read(File.join(DATA_DIR, 'products', 'generated', 'response_v1', 'complete_international_id_v1.json'))) - Document.new(GeneratedV1, + Document.new(Universal, parsed_file['document']) end @@ -29,7 +28,7 @@ parsed_file = JSON.parse(File.read(File.join(DATA_DIR, 'products', 'generated', 'response_v1', 'empty_international_id_v1.json'))) - Document.new(GeneratedV1, + Document.new(Universal, parsed_file['document']) end @@ -54,10 +53,10 @@ expect(prediction.fields['country_of_issue']).to be_an_instance_of(StringField) expect(prediction.fields['country_of_issue'].value).to be_nil - expect(prediction.fields['surnames']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['surnames']).to be_an_instance_of(UniversalListField) expect(prediction.fields['surnames'].values.length).to eq(0) - expect(prediction.fields['given_names']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['given_names']).to be_an_instance_of(UniversalListField) expect(prediction.fields['given_names'].values.length).to eq(0) expect(prediction.fields['sex']).to be_an_instance_of(StringField) @@ -131,7 +130,7 @@ expect( prediction.fields['surnames'] - ).to be_an_instance_of(GeneratedListField) + ).to be_an_instance_of(UniversalListField) expect( prediction.fields['surnames'] .values[0] @@ -145,7 +144,7 @@ expect( prediction.fields['given_names'] - ).to be_an_instance_of(GeneratedListField) + ).to be_an_instance_of(UniversalListField) expect( prediction.fields['given_names'] .values[0] @@ -231,14 +230,14 @@ end end -RSpec.describe 'Invoice V4 document' do +describe 'Invoice V4 document' do let(:invoice_v4_complete_doc) do parsed_file = JSON.parse(File.read(File.join(DATA_DIR, 'products', 'generated', 'response_v1', 'complete_invoice_v4.json'))) - Document.new(GeneratedV1, + Document.new(Universal, parsed_file['document']) end let(:invoice_v4_page0_doc) do @@ -247,14 +246,14 @@ 'generated', 'response_v1', 'complete_invoice_v4.json'))) - GeneratedV1Page.new(parsed_file['document']['inference']['pages'][0]) + UniversalPage.new(parsed_file['document']['inference']['pages'][0]) end let(:invoice_v4_empty_doc) do parsed_file = JSON.parse(File.read(File.join(DATA_DIR, 'products', 'generated', 'response_v1', 'empty_invoice_v4.json'))) - Document.new(GeneratedV1, + Document.new(Universal, parsed_file['document']) end @@ -271,7 +270,7 @@ File.read(File.join(DATA_DIR, 'products', 'generated', 'response_v1', 'summary_empty_invoice_v4.rst')) end - describe 'Empty generated Invoice' do + describe 'Empty universal Invoice' do it 'ensures all fields are empty' do expect( invoice_v4_empty_doc.inference.prediction.fields['customer_address'] @@ -283,7 +282,7 @@ invoice_v4_empty_doc.inference.prediction.fields[ 'customer_company_registrations' ] - ).to be_an_instance_of(GeneratedListField) + ).to be_an_instance_of(UniversalListField) expect( invoice_v4_empty_doc.inference.prediction.fields[ 'customer_company_registrations' @@ -323,18 +322,18 @@ expect( invoice_v4_empty_doc.inference.prediction.fields['line_items'] - ).to be_an_instance_of(GeneratedListField) + ).to be_an_instance_of(UniversalListField) expect(invoice_v4_empty_doc.inference.prediction.fields['line_items'].values.length).to eq(0) expect( invoice_v4_empty_doc.inference.prediction.fields['locale'] - ).to be_an_instance_of(GeneratedObjectField) + ).to be_an_instance_of(UniversalObjectField) expect(invoice_v4_empty_doc.inference.prediction.fields['locale'].currency).to be_nil expect(invoice_v4_empty_doc.inference.prediction.fields['locale'].language).to be_nil expect( invoice_v4_empty_doc.inference.prediction.fields['reference_numbers'] - ).to be_an_instance_of(GeneratedListField) + ).to be_an_instance_of(UniversalListField) expect( invoice_v4_empty_doc.inference.prediction.fields['reference_numbers'].values.length ).to eq(0) @@ -349,7 +348,7 @@ invoice_v4_empty_doc.inference.prediction.fields[ 'supplier_company_registrations' ] - ).to be_an_instance_of(GeneratedListField) + ).to be_an_instance_of(UniversalListField) expect( invoice_v4_empty_doc.inference.prediction.fields[ 'supplier_company_registrations'].values.length @@ -364,7 +363,7 @@ expect( invoice_v4_empty_doc.inference.prediction.fields['supplier_payment_details'] - ).to be_an_instance_of(GeneratedListField) + ).to be_an_instance_of(UniversalListField) expect( invoice_v4_empty_doc.inference.prediction.fields[ 'supplier_payment_details' @@ -373,7 +372,7 @@ expect( invoice_v4_empty_doc.inference.prediction.fields['taxes'] - ).to be_an_instance_of(GeneratedListField) + ).to be_an_instance_of(UniversalListField) expect(invoice_v4_empty_doc.inference.prediction.fields['taxes'].values.length).to eq(0) expect( @@ -391,13 +390,13 @@ end end - describe 'Complete generated Invoice' do + describe 'Complete universal Invoice' do it 'ensures all fields are populated correctly' do prediction = invoice_v4_complete_doc.inference.prediction expect(prediction.fields['customer_address']).to be_an_instance_of(StringField) expect(prediction.fields['customer_address'].value).to eq('1954 Bloon Street West Toronto, ON, M6P 3K9 Canada') - expect(prediction.fields['customer_company_registrations']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['customer_company_registrations']).to be_an_instance_of(UniversalListField) expect(prediction.fields['customer_company_registrations'].values.length).to eq(0) expect(prediction.fields['customer_name']).to be_an_instance_of(StringField) @@ -415,8 +414,8 @@ expect(prediction.fields['invoice_number']).to be_an_instance_of(StringField) expect(prediction.fields['invoice_number'].value).to eq('0042004801351') - expect(prediction.fields['line_items']).to be_an_instance_of(GeneratedListField) - expect(prediction.fields['line_items'].values[0]).to be_an_instance_of(GeneratedObjectField) + expect(prediction.fields['line_items']).to be_an_instance_of(UniversalListField) + expect(prediction.fields['line_items'].values[0]).to be_an_instance_of(UniversalObjectField) expect(prediction.fields['line_items'].values[0].description).to eq('S)BOIE 5X500 FEUILLES A4') expect(prediction.fields['line_items'].values[0].product_code).to be_nil expect(prediction.fields['line_items'].values[0].quantity).to be_nil @@ -427,25 +426,25 @@ expect(prediction.fields['line_items'].values[0].unit_price).to be_nil expect(prediction.fields['line_items'].values[6].unit_price).to eq('65.0') - expect(prediction.fields['locale']).to be_an_instance_of(GeneratedObjectField) + expect(prediction.fields['locale']).to be_an_instance_of(UniversalObjectField) expect(prediction.fields['locale'].currency).to eq('EUR') expect(prediction.fields['locale'].language).to eq('fr') - expect(prediction.fields['reference_numbers']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['reference_numbers']).to be_an_instance_of(UniversalListField) expect(prediction.fields['reference_numbers'].values[0].value).to eq('AD29094') expect(prediction.fields['supplier_address']).to be_an_instance_of(StringField) expect(prediction.fields['supplier_address'].value).to eq('156 University Ave, Toronto ON, Canada M5H 2H7') - expect(prediction.fields['supplier_company_registrations']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['supplier_company_registrations']).to be_an_instance_of(UniversalListField) expect(prediction.fields['supplier_company_registrations'].values.length).to eq(0) expect(prediction.fields['supplier_name']).to be_an_instance_of(StringField) expect(prediction.fields['supplier_name'].value).to eq('TURNPIKE DESIGNS CO.') - expect(prediction.fields['supplier_payment_details']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['supplier_payment_details']).to be_an_instance_of(UniversalListField) expect(prediction.fields['supplier_payment_details'].values[0].iban).to eq('FR7640254025476501124705368') - expect(prediction.fields['taxes']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['taxes']).to be_an_instance_of(UniversalListField) expect(prediction.fields['taxes'].values[0].polygon).to be_an_instance_of(PositionField) expect( prediction.fields['taxes'].values[0].polygon.value.map do |point| @@ -466,7 +465,7 @@ prediction = invoice_v4_page0_doc.prediction expect(prediction.fields['customer_address']).to be_an_instance_of(StringField) expect(prediction.fields['customer_address'].value).to be_nil - expect(prediction.fields['customer_company_registrations']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['customer_company_registrations']).to be_an_instance_of(UniversalListField) expect(prediction.fields['customer_company_registrations'].values.length).to eq(0) expect(prediction.fields['customer_name']).to be_an_instance_of(StringField) @@ -484,8 +483,8 @@ expect(prediction.fields['invoice_number']).to be_an_instance_of(StringField) expect(prediction.fields['invoice_number'].value).to eq('0042004801351') - expect(prediction.fields['line_items']).to be_an_instance_of(GeneratedListField) - expect(prediction.fields['line_items'].values[0]).to be_an_instance_of(GeneratedObjectField) + expect(prediction.fields['line_items']).to be_an_instance_of(UniversalListField) + expect(prediction.fields['line_items'].values[0]).to be_an_instance_of(UniversalObjectField) expect(prediction.fields['line_items'].values[0].description).to eq('S)BOIE 5X500 FEUILLES A4') expect(prediction.fields['line_items'].values[0].product_code).to be_nil expect(prediction.fields['line_items'].values[0].quantity).to be_nil @@ -494,25 +493,25 @@ expect(prediction.fields['line_items'].values[0].total_amount).to eq('2.63') expect(prediction.fields['line_items'].values[0].unit_price).to be_nil - expect(prediction.fields['locale']).to be_an_instance_of(GeneratedObjectField) + expect(prediction.fields['locale']).to be_an_instance_of(UniversalObjectField) expect(prediction.fields['locale'].currency).to eq('EUR') expect(prediction.fields['locale'].language).to eq('fr') - expect(prediction.fields['reference_numbers']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['reference_numbers']).to be_an_instance_of(UniversalListField) expect(prediction.fields['reference_numbers'].values.length).to eq(0) expect(prediction.fields['supplier_address']).to be_an_instance_of(StringField) expect(prediction.fields['supplier_address'].value).to be_nil - expect(prediction.fields['supplier_company_registrations']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['supplier_company_registrations']).to be_an_instance_of(UniversalListField) expect(prediction.fields['supplier_company_registrations'].values.length).to eq(0) expect(prediction.fields['supplier_name']).to be_an_instance_of(StringField) expect(prediction.fields['supplier_name'].value).to be_nil - expect(prediction.fields['supplier_payment_details']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['supplier_payment_details']).to be_an_instance_of(UniversalListField) expect(prediction.fields['supplier_payment_details'].values[0].iban).to eq('FR7640254025476501124705368') - expect(prediction.fields['taxes']).to be_an_instance_of(GeneratedListField) + expect(prediction.fields['taxes']).to be_an_instance_of(UniversalListField) expect(prediction.fields['taxes'].values[0].polygon).to be_an_instance_of(PositionField) expect(prediction.fields['taxes'].values[0].polygon.value.map do |point| [point.x, point.y] diff --git a/spec/document/us/bank_check_v1_spec.rb b/spec/product/us/bank_check_v1_spec.rb similarity index 100% rename from spec/document/us/bank_check_v1_spec.rb rename to spec/product/us/bank_check_v1_spec.rb diff --git a/spec/document/us/healthcare_card_v1_spec.rb b/spec/product/us/healthcare_card_v1_spec.rb similarity index 100% rename from spec/document/us/healthcare_card_v1_spec.rb rename to spec/product/us/healthcare_card_v1_spec.rb diff --git a/spec/document/us/us_mail_v3_spec.rb b/spec/product/us/us_mail_v3_spec.rb similarity index 100% rename from spec/document/us/us_mail_v3_spec.rb rename to spec/product/us/us_mail_v3_spec.rb diff --git a/spec/document/us/w9_v1_spec.rb b/spec/product/us/w9_v1_spec.rb similarity index 100% rename from spec/document/us/w9_v1_spec.rb rename to spec/product/us/w9_v1_spec.rb diff --git a/spec/workflow/workflow_integration.rb b/spec/workflow/workflow_integration.rb index 3ec77bd5..3903acf3 100644 --- a/spec/workflow/workflow_integration.rb +++ b/spec/workflow/workflow_integration.rb @@ -20,8 +20,8 @@ response = client.execute_workflow( invoice_splitter_input, ENV.fetch('WORKFLOW_ID'), - document_alias: document_alias, - priority: priority + options: { document_alias: document_alias, + priority: priority } ) expect(response.execution.file.alias).to eq(document_alias) diff --git a/spec/workflow/workflow_spec.rb b/spec/workflow/workflow_spec.rb index 3b96908a..4655e9d0 100644 --- a/spec/workflow/workflow_spec.rb +++ b/spec/workflow/workflow_spec.rb @@ -15,7 +15,7 @@ allow(Net::HTTP).to receive(:start).and_return(mocked_response) mocked_execution = Mindee::Parsing::Common::WorkflowResponse.new( - GeneratedV1, + Universal, JSON.parse(mocked_response.body, object_class: Hash), mocked_response.body ) @@ -47,7 +47,7 @@ allow(Net::HTTP).to receive(:start).and_return(mocked_response) mocked_execution = Mindee::Parsing::Common::WorkflowResponse.new( - GeneratedV1, + Universal, JSON.parse(mocked_response.body, object_class: Hash), mocked_response.body )