From c828ab68739d79ad9fe653f86753b9ab9d825482 Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Tue, 21 Jan 2025 11:10:03 +0100 Subject: [PATCH 01/17] :boom: drop support for ruby versions < 3.0 --- .rubocop.yml | 2 +- lib/mindee/http/endpoint.rb | 2 +- mindee.gemspec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c8b7a7fa..08564255 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,7 +9,7 @@ AllCops: - _test.rb - local_test/* - TargetRubyVersion: 2.6 + TargetRubyVersion: 3.0 SuggestExtensions: false Gemspec/DevelopmentDependencies: diff --git a/lib/mindee/http/endpoint.rb b/lib/mindee/http/endpoint.rb index a1c91352..7b2cfe75 100644 --- a/lib/mindee/http/endpoint.rb +++ b/lib/mindee/http/endpoint.rb @@ -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 diff --git a/mindee.gemspec b/mindee.gemspec index a1f43493..d6f87648 100644 --- a/mindee.gemspec +++ b/mindee.gemspec @@ -27,7 +27,7 @@ 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.required_ruby_version = Gem::Requirement.new('>= 3.0') spec.add_runtime_dependency 'marcel', '~> 1.0.2' spec.add_runtime_dependency 'mini_magick', '>=4', '< 6' From 3e8388e75a5f3ede4938a914633f83eed7fa5df6 Mon Sep 17 00:00:00 2001 From: sebastianMindee Date: Tue, 21 Jan 2025 15:21:44 +0100 Subject: [PATCH 02/17] :arrow_up: bump dependencies, update lint --- .github/workflows/_test-code-samples.yml | 1 - .github/workflows/cron.yml | 2 +- .github/workflows/publish-release.yml | 6 +++--- .github/workflows/pull-request.yml | 8 ++++---- .github/workflows/push-main-branch.yml | 6 +++--- README.md | 2 +- docs/getting_started.md | 2 +- lib/mindee/parsing/common/api_response.rb | 2 +- .../barcode_reader/barcode_reader_v1_page.rb | 2 +- .../bill_of_lading_v1_carrier.rb | 2 +- .../bill_of_lading_v1_carrier_item.rb | 2 +- .../bill_of_lading_v1_consignee.rb | 2 +- .../bill_of_lading_v1_notify_party.rb | 2 +- .../bill_of_lading/bill_of_lading_v1_page.rb | 2 +- .../bill_of_lading_v1_shipper.rb | 2 +- .../business_card/business_card_v1_page.rb | 2 +- lib/mindee/product/cropper/cropper_v1_page.rb | 2 +- lib/mindee/product/custom/custom_v1_page.rb | 2 +- .../delivery_note/delivery_note_v1_page.rb | 2 +- .../driver_license/driver_license_v1_page.rb | 2 +- .../driver_license/driver_license_v1_page.rb | 4 ++-- .../eu/license_plate/license_plate_v1_page.rb | 2 +- .../financial_document_v1_line_item.rb | 2 +- .../financial_document_v1_page.rb | 2 +- .../bank_account_details_v1_page.rb | 2 +- .../bank_account_details_v2_bban.rb | 2 +- .../bank_account_details_v2_page.rb | 2 +- .../bank_statement/bank_statement_v1_page.rb | 2 +- .../bank_statement_v1_transaction.rb | 2 +- .../fr/carte_grise/carte_grise_v1_page.rb | 2 +- .../energy_bill_v1_energy_consumer.rb | 2 +- .../energy_bill_v1_energy_supplier.rb | 2 +- .../energy_bill/energy_bill_v1_energy_usage.rb | 2 +- .../energy_bill/energy_bill_v1_meter_detail.rb | 2 +- .../fr/energy_bill/energy_bill_v1_page.rb | 2 +- .../energy_bill/energy_bill_v1_subscription.rb | 2 +- .../energy_bill_v1_taxes_and_contribution.rb | 2 +- .../fr/health_card/health_card_v1_page.rb | 2 +- .../product/fr/id_card/id_card_v1_page.rb | 4 ++-- .../product/fr/id_card/id_card_v2_page.rb | 4 ++-- .../payslip/payslip_v2_bank_account_detail.rb | 2 +- .../product/fr/payslip/payslip_v2_employee.rb | 2 +- .../product/fr/payslip/payslip_v2_employer.rb | 2 +- .../fr/payslip/payslip_v2_employment.rb | 2 +- .../product/fr/payslip/payslip_v2_page.rb | 2 +- .../fr/payslip/payslip_v2_pay_detail.rb | 2 +- .../fr/payslip/payslip_v2_pay_period.rb | 2 +- .../product/fr/payslip/payslip_v2_pto.rb | 2 +- .../fr/payslip/payslip_v2_salary_detail.rb | 2 +- .../payslip/payslip_v3_bank_account_detail.rb | 2 +- .../product/fr/payslip/payslip_v3_employee.rb | 2 +- .../product/fr/payslip/payslip_v3_employer.rb | 2 +- .../fr/payslip/payslip_v3_employment.rb | 2 +- .../product/fr/payslip/payslip_v3_page.rb | 2 +- .../fr/payslip/payslip_v3_paid_time_off.rb | 2 +- .../fr/payslip/payslip_v3_pay_detail.rb | 2 +- .../fr/payslip/payslip_v3_pay_period.rb | 2 +- .../fr/payslip/payslip_v3_salary_detail.rb | 2 +- .../product/generated/generated_v1_page.rb | 2 +- .../generated/generated_v1_prediction.rb | 2 +- .../indian_passport/indian_passport_v1_page.rb | 2 +- .../international_id_v2_page.rb | 2 +- .../product/invoice/invoice_v4_line_item.rb | 2 +- lib/mindee/product/invoice/invoice_v4_page.rb | 2 +- .../invoice_splitter_v1_page.rb | 2 +- .../multi_receipts_detector_v1_page.rb | 2 +- .../nutrition_facts_label_v1_added_sugar.rb | 2 +- .../nutrition_facts_label_v1_calorie.rb | 2 +- .../nutrition_facts_label_v1_cholesterol.rb | 2 +- .../nutrition_facts_label_v1_dietary_fiber.rb | 2 +- .../nutrition_facts_label_v1_nutrient.rb | 2 +- .../nutrition_facts_label_v1_page.rb | 2 +- .../nutrition_facts_label_v1_protein.rb | 2 +- .../nutrition_facts_label_v1_saturated_fat.rb | 2 +- .../nutrition_facts_label_v1_serving_size.rb | 2 +- .../nutrition_facts_label_v1_sodium.rb | 2 +- ...rition_facts_label_v1_total_carbohydrate.rb | 2 +- .../nutrition_facts_label_v1_total_fat.rb | 2 +- .../nutrition_facts_label_v1_total_sugar.rb | 2 +- .../nutrition_facts_label_v1_trans_fat.rb | 2 +- .../product/passport/passport_v1_page.rb | 2 +- .../proof_of_address_v1_page.rb | 2 +- lib/mindee/product/receipt/receipt_v4_page.rb | 2 +- .../product/receipt/receipt_v5_line_item.rb | 2 +- lib/mindee/product/receipt/receipt_v5_page.rb | 2 +- .../product/resume/resume_v1_certificate.rb | 2 +- .../product/resume/resume_v1_education.rb | 2 +- .../product/resume/resume_v1_language.rb | 2 +- lib/mindee/product/resume/resume_v1_page.rb | 2 +- .../resume_v1_professional_experience.rb | 2 +- .../resume/resume_v1_social_networks_url.rb | 2 +- .../us/bank_check/bank_check_v1_page.rb | 4 ++-- .../driver_license/driver_license_v1_page.rb | 4 ++-- .../healthcare_card_v1_copay.rb | 2 +- .../healthcare_card/healthcare_card_v1_page.rb | 2 +- .../product/us/us_mail/us_mail_v2_page.rb | 2 +- .../us/us_mail/us_mail_v2_recipient_address.rb | 2 +- .../us/us_mail/us_mail_v2_sender_address.rb | 2 +- .../product/us/us_mail/us_mail_v3_page.rb | 2 +- .../us/us_mail/us_mail_v3_recipient_address.rb | 2 +- .../us/us_mail/us_mail_v3_sender_address.rb | 2 +- lib/mindee/product/us/w9/w9_v1_page.rb | 2 +- mindee.gemspec | 18 +++++++++--------- spec/extraction/image_extractor_spec.rb | 10 ++-------- 104 files changed, 124 insertions(+), 131 deletions(-) diff --git a/.github/workflows/_test-code-samples.yml b/.github/workflows/_test-code-samples.yml index bbd5e8ce..87bd4b87 100644 --- a/.github/workflows/_test-code-samples.yml +++ b/.github/workflows/_test-code-samples.yml @@ -15,7 +15,6 @@ jobs: - "3.1" - "3.2" - "3.3" - - "3.4" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index e7f14660..b2ec9b72 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -6,5 +6,5 @@ on: jobs: test_code_samples: - uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@main + uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@develop/v4.0.0 secrets: inherit diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index a1178aeb..9af56316 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -6,12 +6,12 @@ on: jobs: publish_docs: - uses: mindee/mindee-api-ruby/.github/workflows/_publish-docs.yml@main + uses: mindee/mindee-api-ruby/.github/workflows/_publish-docs.yml@develop/v4.0.0 secrets: inherit publish_guide: - uses: mindee/mindee-api-ruby/.github/workflows/_publish-guide.yml@main + uses: mindee/mindee-api-ruby/.github/workflows/_publish-guide.yml@develop/v4.0.0 needs: publish_docs secrets: inherit publish_code: - uses: mindee/mindee-api-ruby/.github/workflows/_publish-code.yml@main + uses: mindee/mindee-api-ruby/.github/workflows/_publish-code.yml@develop/v4.0.0 secrets: inherit diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2690f22c..6bfe5f36 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,16 +5,16 @@ on: jobs: static_analysis: - uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@main + uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@develop/v4.0.0 test_units: - uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@main + uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@develop/v4.0.0 needs: static_analysis secrets: inherit test_integrations: - uses: mindee/mindee-api-ruby/.github/workflows/_test-integrations.yml@main + uses: mindee/mindee-api-ruby/.github/workflows/_test-integrations.yml@develop/v4.0.0 needs: test_units secrets: inherit test_code_samples: - uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@main + uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@develop/v4.0.0 needs: test_units secrets: inherit diff --git a/.github/workflows/push-main-branch.yml b/.github/workflows/push-main-branch.yml index f2cf102d..a5e23267 100644 --- a/.github/workflows/push-main-branch.yml +++ b/.github/workflows/push-main-branch.yml @@ -7,11 +7,11 @@ on: jobs: static_analysis: - uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@main + uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@develop/v4.0.0 test_units: - uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@main + uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@develop/v4.0.0 needs: static_analysis secrets: inherit tag: - uses: mindee/client-lib-actions/.github/workflows/tag-version.yml@main + uses: mindee/client-lib-actions/.github/workflows/tag-version.yml@develop/v4.0.0 needs: test_units diff --git a/README.md b/README.md index 14d81068..7a79e4ea 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 ## Quick Start diff --git a/docs/getting_started.md b/docs/getting_started.md index 796c128d..3ea76bca 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -9,7 +9,7 @@ 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: diff --git a/lib/mindee/parsing/common/api_response.rb b/lib/mindee/parsing/common/api_response.rb index 3a01184a..f8bfc3e5 100644 --- a/lib/mindee/parsing/common/api_response.rb +++ b/lib/mindee/parsing/common/api_response.rb @@ -138,7 +138,7 @@ class WorkflowResponse 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) + product_class ||= Product::Generated::GeneratedV1 @execution = Mindee::Parsing::Common::Execution.new(product_class, http_response['execution']) 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..508fc2e5 100644 --- a/lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb +++ b/lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb @@ -10,7 +10,7 @@ module BarcodeReader class BarcodeReaderV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = BarcodeReaderV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..82cec8c6 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'] 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_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..2d1479bc 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,7 +10,7 @@ module BillOfLading class BillOfLadingV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = BillOfLadingV1PagePrediction.new( prediction['prediction'], prediction['id'] 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_page.rb b/lib/mindee/product/business_card/business_card_v1_page.rb index 1e169dec..1c75a0f9 100644 --- a/lib/mindee/product/business_card/business_card_v1_page.rb +++ b/lib/mindee/product/business_card/business_card_v1_page.rb @@ -10,7 +10,7 @@ module BusinessCard class BusinessCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = BusinessCardV1PagePrediction.new( prediction['prediction'], prediction['id'] diff --git a/lib/mindee/product/cropper/cropper_v1_page.rb b/lib/mindee/product/cropper/cropper_v1_page.rb index 28410be3..ad5a778b 100644 --- a/lib/mindee/product/cropper/cropper_v1_page.rb +++ b/lib/mindee/product/cropper/cropper_v1_page.rb @@ -10,7 +10,7 @@ module Cropper class CropperV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = CropperV1PagePrediction.new( prediction['prediction'], prediction['id'] diff --git a/lib/mindee/product/custom/custom_v1_page.rb b/lib/mindee/product/custom/custom_v1_page.rb index 90fac855..df435220 100644 --- a/lib/mindee/product/custom/custom_v1_page.rb +++ b/lib/mindee/product/custom/custom_v1_page.rb @@ -10,7 +10,7 @@ module Custom class CustomV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = CustomV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..4a481e44 100644 --- a/lib/mindee/product/delivery_note/delivery_note_v1_page.rb +++ b/lib/mindee/product/delivery_note/delivery_note_v1_page.rb @@ -10,7 +10,7 @@ module DeliveryNote class DeliveryNoteV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = DeliveryNoteV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..5b06fceb 100644 --- a/lib/mindee/product/driver_license/driver_license_v1_page.rb +++ b/lib/mindee/product/driver_license/driver_license_v1_page.rb @@ -10,7 +10,7 @@ module DriverLicense class DriverLicenseV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = DriverLicenseV1PagePrediction.new( prediction['prediction'], prediction['id'] 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 index a9ee6b49..0a5c0a6c 100644 --- a/lib/mindee/product/eu/driver_license/driver_license_v1_page.rb +++ b/lib/mindee/product/eu/driver_license/driver_license_v1_page.rb @@ -11,7 +11,7 @@ module DriverLicense class DriverLicenseV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = DriverLicenseV1PagePrediction.new( prediction['prediction'], prediction['id'] @@ -35,7 +35,7 @@ class DriverLicenseV1PagePrediction < DriverLicenseV1Document def initialize(prediction, page_id) @photo = PositionField.new(prediction['photo'], page_id) @signature = PositionField.new(prediction['signature'], page_id) - super(prediction, page_id) + super end # @return [String] 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..b9697fff 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,7 +11,7 @@ module LicensePlate class LicensePlateV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = LicensePlateV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..5ce22614 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'] 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..557d451b 100644 --- a/lib/mindee/product/financial_document/financial_document_v1_page.rb +++ b/lib/mindee/product/financial_document/financial_document_v1_page.rb @@ -10,7 +10,7 @@ module FinancialDocument class FinancialDocumentV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = FinancialDocumentV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..fe6418a8 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,7 +11,7 @@ module BankAccountDetails class BankAccountDetailsV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = BankAccountDetailsV1PagePrediction.new( prediction['prediction'], prediction['id'] 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_page.rb b/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb index bdc59b9b..840fc6c2 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,7 +11,7 @@ module BankAccountDetails class BankAccountDetailsV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = BankAccountDetailsV2PagePrediction.new( prediction['prediction'], prediction['id'] 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 index 85d3cf59..3b7fad59 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_page.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v1_page.rb @@ -11,7 +11,7 @@ module BankStatement class BankStatementV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = BankStatementV1PagePrediction.new( prediction['prediction'], prediction['id'] 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 index 562f734f..5f5628dc 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb @@ -22,7 +22,7 @@ class BankStatementV1Transaction < 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'] 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..c67b1b43 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,7 +11,7 @@ module CarteGrise class CarteGriseV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = CarteGriseV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..9a567142 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'] 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..2abc8972 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,7 +11,7 @@ module EnergyBill class EnergyBillV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = EnergyBillV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..e02fe758 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'] 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..11a55404 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'] 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..890d2cf7 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,7 +11,7 @@ module HealthCard class HealthCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = HealthCardV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..a47d38b4 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,7 +11,7 @@ module IdCard class IdCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = IdCardV1PagePrediction.new( prediction['prediction'], prediction['id'] @@ -31,7 +31,7 @@ class IdCardV1PagePrediction < IdCardV1Document # @param page_id [Integer, nil] def initialize(prediction, page_id) @document_side = ClassificationField.new(prediction['document_side'], page_id) - super(prediction, page_id) + super 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..776e0be1 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,7 +11,7 @@ module IdCard class IdCardV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = IdCardV2PagePrediction.new( prediction['prediction'], prediction['id'] @@ -35,7 +35,7 @@ class IdCardV2PagePrediction < IdCardV2Document 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) + super end # @return [String] 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_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..0a8b5335 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'] diff --git a/lib/mindee/product/fr/payslip/payslip_v2_page.rb b/lib/mindee/product/fr/payslip/payslip_v2_page.rb index 8adcffd6..a526de22 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_page.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_page.rb @@ -11,7 +11,7 @@ module Payslip class PayslipV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = PayslipV2PagePrediction.new( prediction['prediction'], prediction['id'] 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..082ade2b 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'] 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..aabad119 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'] 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..b4ba04c5 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'] 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_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..a030b9ce 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_page.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_page.rb @@ -11,7 +11,7 @@ module Payslip class PayslipV3Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = PayslipV3PagePrediction.new( prediction['prediction'], prediction['id'] 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..eca6800e 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'] 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..83b5fb4b 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'] 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..799b3bf9 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'] diff --git a/lib/mindee/product/generated/generated_v1_page.rb b/lib/mindee/product/generated/generated_v1_page.rb index 0a252a7e..bfcc1578 100644 --- a/lib/mindee/product/generated/generated_v1_page.rb +++ b/lib/mindee/product/generated/generated_v1_page.rb @@ -10,7 +10,7 @@ module Generated class GeneratedV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = GeneratedV1PagePrediction.new( prediction['prediction'], prediction['id'] diff --git a/lib/mindee/product/generated/generated_v1_prediction.rb b/lib/mindee/product/generated/generated_v1_prediction.rb index 81810f7e..f86cc479 100644 --- a/lib/mindee/product/generated/generated_v1_prediction.rb +++ b/lib/mindee/product/generated/generated_v1_prediction.rb @@ -15,7 +15,7 @@ class GeneratedV1Prediction < Mindee::Parsing::Common::Prediction attr_reader :fields def initialize - super() + super @fields = {} end 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..fe0261e4 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,7 +11,7 @@ module IndianPassport class IndianPassportV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = IndianPassportV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..90fe0c58 100644 --- a/lib/mindee/product/international_id/international_id_v2_page.rb +++ b/lib/mindee/product/international_id/international_id_v2_page.rb @@ -10,7 +10,7 @@ module InternationalId class InternationalIdV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = InternationalIdV2PagePrediction.new( prediction['prediction'], prediction['id'] diff --git a/lib/mindee/product/invoice/invoice_v4_line_item.rb b/lib/mindee/product/invoice/invoice_v4_line_item.rb index 52870518..ff8b4a61 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'] diff --git a/lib/mindee/product/invoice/invoice_v4_page.rb b/lib/mindee/product/invoice/invoice_v4_page.rb index 438975e3..5c004298 100644 --- a/lib/mindee/product/invoice/invoice_v4_page.rb +++ b/lib/mindee/product/invoice/invoice_v4_page.rb @@ -10,7 +10,7 @@ module Invoice class InvoiceV4Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = InvoiceV4PagePrediction.new( prediction['prediction'], prediction['id'] 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_page.rb b/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb index cc34aac9..077287f5 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,7 +10,7 @@ module MultiReceiptsDetector class MultiReceiptsDetectorV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = MultiReceiptsDetectorV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..4b7ac1e8 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'] 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..7cc8546d 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'] 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..d80729b2 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'] 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..7032464b 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'] 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..9dcee678 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'] 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..a2bf5fd4 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,7 +10,7 @@ module NutritionFactsLabel class NutritionFactsLabelV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = NutritionFactsLabelV1PagePrediction.new( prediction['prediction'], prediction['id'] 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..548dd260 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'] 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..2a2cd06d 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'] 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..2615ce6a 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 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..0b521eeb 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'] 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..3a34bb3d 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'] 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..c5632119 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'] 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..2e7a323c 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'] 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..9a1cc35c 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'] diff --git a/lib/mindee/product/passport/passport_v1_page.rb b/lib/mindee/product/passport/passport_v1_page.rb index f42118f6..e68f1429 100644 --- a/lib/mindee/product/passport/passport_v1_page.rb +++ b/lib/mindee/product/passport/passport_v1_page.rb @@ -10,7 +10,7 @@ module Passport class PassportV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = PassportV1PagePrediction.new( prediction['prediction'], prediction['id'] 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 index ebce0c3b..93ff6aa1 100644 --- 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 @@ -10,7 +10,7 @@ module ProofOfAddress class ProofOfAddressV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = ProofOfAddressV1PagePrediction.new( prediction['prediction'], prediction['id'] diff --git a/lib/mindee/product/receipt/receipt_v4_page.rb b/lib/mindee/product/receipt/receipt_v4_page.rb index 180b3998..9e87c8f3 100644 --- a/lib/mindee/product/receipt/receipt_v4_page.rb +++ b/lib/mindee/product/receipt/receipt_v4_page.rb @@ -10,7 +10,7 @@ module Receipt class ReceiptV4Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = ReceiptV4PagePrediction.new( prediction['prediction'], prediction['id'] diff --git a/lib/mindee/product/receipt/receipt_v5_line_item.rb b/lib/mindee/product/receipt/receipt_v5_line_item.rb index 3d00d42c..4fc8fcf7 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'] diff --git a/lib/mindee/product/receipt/receipt_v5_page.rb b/lib/mindee/product/receipt/receipt_v5_page.rb index e5c97de1..83ab99a8 100644 --- a/lib/mindee/product/receipt/receipt_v5_page.rb +++ b/lib/mindee/product/receipt/receipt_v5_page.rb @@ -10,7 +10,7 @@ module Receipt class ReceiptV5Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = ReceiptV5PagePrediction.new( prediction['prediction'], prediction['id'] 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_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_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_page.rb b/lib/mindee/product/resume/resume_v1_page.rb index f5338afb..44aca387 100644 --- a/lib/mindee/product/resume/resume_v1_page.rb +++ b/lib/mindee/product/resume/resume_v1_page.rb @@ -10,7 +10,7 @@ module Resume class ResumeV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = ResumeV1PagePrediction.new( prediction['prediction'], prediction['id'] 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_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/us/bank_check/bank_check_v1_page.rb b/lib/mindee/product/us/bank_check/bank_check_v1_page.rb index f3fdc45b..9ad4ccd9 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,7 +11,7 @@ module BankCheck class BankCheckV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = BankCheckV1PagePrediction.new( prediction['prediction'], prediction['id'] @@ -38,7 +38,7 @@ def initialize(prediction, page_id) prediction['signatures_positions'].each do |item| @signatures_positions.push(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_page.rb b/lib/mindee/product/us/driver_license/driver_license_v1_page.rb index 15c9c9cb..85ae0944 100644 --- a/lib/mindee/product/us/driver_license/driver_license_v1_page.rb +++ b/lib/mindee/product/us/driver_license/driver_license_v1_page.rb @@ -11,7 +11,7 @@ module DriverLicense class DriverLicenseV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = DriverLicenseV1PagePrediction.new( prediction['prediction'], prediction['id'] @@ -35,7 +35,7 @@ class DriverLicenseV1PagePrediction < DriverLicenseV1Document def initialize(prediction, page_id) @photo = PositionField.new(prediction['photo'], page_id) @signature = PositionField.new(prediction['signature'], page_id) - super(prediction, page_id) + super end # @return [String] 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..44c51ae0 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 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..41e6e11f 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,7 +11,7 @@ module HealthcareCard class HealthcareCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = HealthcareCardV1PagePrediction.new( prediction['prediction'], prediction['id'] 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 index fbe123e1..f20c1613 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v2_page.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v2_page.rb @@ -11,7 +11,7 @@ module UsMail class UsMailV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = UsMailV2PagePrediction.new( prediction['prediction'], prediction['id'] 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 index 8c38e2e3..811574d1 100644 --- 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 @@ -34,7 +34,7 @@ class UsMailV2RecipientAddress < 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_v2_sender_address.rb b/lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb index cbbd7837..41439080 100644 --- 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 @@ -28,7 +28,7 @@ class UsMailV2SenderAddress < 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/us_mail/us_mail_v3_page.rb b/lib/mindee/product/us/us_mail/us_mail_v3_page.rb index 15bcb318..9fbd0a93 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,7 +11,7 @@ module UsMail class UsMailV3Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = UsMailV3PagePrediction.new( prediction['prediction'], prediction['id'] 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..9f59eecb 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 @@ -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_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_page.rb b/lib/mindee/product/us/w9/w9_v1_page.rb index 5f1b8521..2024ed7e 100644 --- a/lib/mindee/product/us/w9/w9_v1_page.rb +++ b/lib/mindee/product/us/w9/w9_v1_page.rb @@ -11,7 +11,7 @@ module W9 class W9V1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) - super(prediction) + super @prediction = W9V1PagePrediction.new( prediction['prediction'], prediction['id'] diff --git a/mindee.gemspec b/mindee.gemspec index d6f87648..d0633871 100644 --- a/mindee.gemspec +++ b/mindee.gemspec @@ -29,13 +29,13 @@ Gem::Specification.new do |spec| spec.required_ruby_version = Gem::Requirement.new('>= 3.0') - 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.add_dependency 'marcel', '~> 1.0.4' + spec.add_dependency 'mini_magick', '>=4', '< 6' + spec.add_dependency 'origamindee', '~> 3.1.0' + spec.add_dependency 'pdf-reader', '~> 2.13.0' + + spec.add_development_dependency 'rake', '~> 13.2.1' + spec.add_development_dependency 'rspec', '~> 3.13.0' + spec.add_development_dependency 'rubocop', '~> 1.70.0' + spec.add_development_dependency 'yard', '~> 0.9.37' end diff --git a/spec/extraction/image_extractor_spec.rb b/spec/extraction/image_extractor_spec.rb index 8ce0f391..ff4c9667 100644 --- a/spec/extraction/image_extractor_spec.rb +++ b/spec/extraction/image_extractor_spec.rb @@ -19,14 +19,8 @@ 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, From 8ee03e09df5ddde3e2cc763c2d4a2c5daf24c4ab Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:01:47 +0100 Subject: [PATCH 03/17] :boom: refactor error handling (#142) --- examples/auto_invoice_splitter_extraction.rb | 2 +- lib/mindee.rb | 12 +- lib/mindee/client.rb | 26 +- lib/mindee/errors.rb | 5 + lib/mindee/errors/mindee_error.rb | 17 ++ lib/mindee/errors/mindee_http_error.rb | 36 +++ lib/mindee/errors/mindee_input_error.rb | 30 +++ lib/mindee/extraction.rb | 2 - lib/mindee/extraction/common.rb | 4 - .../multi_receipts_extractor.rb | 11 +- lib/mindee/extraction/pdf_extractor.rb | 4 - lib/mindee/http.rb | 2 +- lib/mindee/http/endpoint.rb | 14 +- .../http/{error.rb => error_handler.rb} | 40 +-- lib/mindee/http/workflow_endpoint.rb | 10 +- lib/mindee/image.rb | 2 + .../common => image}/extracted_image.rb | 36 +-- .../common => image}/image_extractor.rb | 8 +- lib/mindee/image/image_utils.rb | 5 +- lib/mindee/input/local_response.rb | 6 +- .../input/sources/local_input_source.rb | 27 +- lib/mindee/input/sources/url_input_source.rb | 10 +- lib/mindee/parsing/common/api_response.rb | 2 +- lib/mindee/pdf.rb | 2 + .../pdf_extractor => pdf}/extracted_pdf.rb | 25 +- .../pdf_extractor => pdf}/pdf_extractor.rb | 25 +- lib/mindee/pdf/pdf_processor.rb | 7 +- spec/client_spec.rb | 55 +++++ ...invoice_splitter_extraction_integration.rb | 2 +- .../multi_receipts_extractor_spec.rb | 31 ++- .../{error_spec.rb => error_handler_spec.rb} | 32 +-- spec/image/extracted_image_spec.rb | 119 +++++++++ spec/image/image_compressor_spec.rb | 67 +++++ .../image_extractor_spec.rb | 12 +- spec/image/image_utils_spec.rb | 77 ++++++ spec/input/local_response_spec.rb | 13 + .../{ => sources}/files_handling_spec.rb | 2 +- spec/input/sources/sources_spec.rb | 83 +++++++ .../url_input_source_integration.rb | 0 .../{ => sources}/url_input_source_spec.rb | 22 +- spec/input/sources_spec.rb | 231 ------------------ .../standard}/date_field_spec.rb | 0 .../standard}/string_field_spec.rb | 0 spec/pdf/extracted_pdf_spec.rb | 94 +++++++ spec/pdf/pdf_compressor_spec.rb | 96 ++++++++ .../{extraction => pdf}/pdf_extractor_spec.rb | 6 +- .../pdf_processor_spec.rb} | 15 +- 47 files changed, 899 insertions(+), 428 deletions(-) create mode 100644 lib/mindee/errors.rb create mode 100644 lib/mindee/errors/mindee_error.rb create mode 100644 lib/mindee/errors/mindee_http_error.rb create mode 100644 lib/mindee/errors/mindee_input_error.rb delete mode 100644 lib/mindee/extraction/common.rb delete mode 100644 lib/mindee/extraction/pdf_extractor.rb rename lib/mindee/http/{error.rb => error_handler.rb} (74%) rename lib/mindee/{extraction/common => image}/extracted_image.rb (64%) rename lib/mindee/{extraction/common => image}/image_extractor.rb (97%) rename lib/mindee/{extraction/pdf_extractor => pdf}/extracted_pdf.rb (65%) rename lib/mindee/{extraction/pdf_extractor => pdf}/pdf_extractor.rb (82%) rename spec/http/{error_spec.rb => error_handler_spec.rb} (81%) create mode 100644 spec/image/extracted_image_spec.rb create mode 100644 spec/image/image_compressor_spec.rb rename spec/{extraction => image}/image_extractor_spec.rb (82%) create mode 100644 spec/image/image_utils_spec.rb rename spec/input/{ => sources}/files_handling_spec.rb (99%) create mode 100644 spec/input/sources/sources_spec.rb rename spec/input/{ => sources}/url_input_source_integration.rb (100%) rename spec/input/{ => sources}/url_input_source_spec.rb (81%) delete mode 100644 spec/input/sources_spec.rb rename spec/{fields => parsing/standard}/date_field_spec.rb (100%) rename spec/{fields => parsing/standard}/string_field_spec.rb (100%) create mode 100644 spec/pdf/extracted_pdf_spec.rb create mode 100644 spec/pdf/pdf_compressor_spec.rb rename spec/{extraction => pdf}/pdf_extractor_spec.rb (91%) rename spec/{input/pdf_processing_spec.rb => pdf/pdf_processor_spec.rb} (89%) diff --git a/examples/auto_invoice_splitter_extraction.rb b/examples/auto_invoice_splitter_extraction.rb index cd87989a..8955a3ff 100644 --- a/examples/auto_invoice_splitter_extraction.rb +++ b/examples/auto_invoice_splitter_extraction.rb @@ -22,7 +22,7 @@ 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) + pdf_extractor = Mindee::PDF::PDFExtractor::PDFExtractor.new(input_source) invoice_splitter_response = mindee_client.enqueue_and_parse( input_source, Mindee::Product::InvoiceSplitter::InvoiceSplitterV1, diff --git a/lib/mindee.rb b/lib/mindee.rb index ca57a06f..3dfe29ed 100644 --- a/lib/mindee.rb +++ b/lib/mindee.rb @@ -4,6 +4,14 @@ require 'mindee/extraction' module Mindee + # Mindee internal error module. + module Errors + end + + # Custom extraction module + module Extraction + end + # Mindee internal http module. module HTTP end @@ -29,10 +37,6 @@ module ImageCompressor end end - # Custom extraction module - module Extraction - end - # Parsing internals and fields. module Parsing # Common fields and functions. diff --git a/lib/mindee/client.rb b/lib/mindee/client.rb index 8ed4a69d..d83737dc 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -166,6 +166,7 @@ def enqueue_and_parse( delay_sec: 1.5, max_retries: 80 ) + validate_async_params(initial_delay_sec, delay_sec, max_retries) enqueue_res = enqueue( input_source, product_class, @@ -187,7 +188,8 @@ def enqueue_and_parse( 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)" + raise Errors::MindeeAPIError, + "Asynchronous parsing request timed out after #{elapsed} seconds (#{polling_attempts} tries)" end queue_res @@ -242,8 +244,8 @@ def execute_workflow( # @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.' + rescue KeyError, Errors::MindeeAPIError + raise Errors::MindeeInputError, 'No prediction found in local response.' end # Load a document from an absolute path, as a string. @@ -314,11 +316,18 @@ 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 + return unless max_retries < min_retries + + raise ArgumentError, + "Cannot set auto-poll retries to less than #{min_retries}" end # Creates an endpoint with the given values. Raises an error if the endpoint is invalid. @@ -333,8 +342,9 @@ 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?) && + [Mindee::Product::Custom::CustomV1, Mindee::Product::Generated::GeneratedV1].include?(product_class) + raise Errors::MindeeConfigurationError, 'Missing argument endpoint_name when using custom class' end endpoint_name = fix_endpoint_name(product_class, endpoint_name) 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..fddb170d 100644 --- a/lib/mindee/extraction.rb +++ b/lib/mindee/extraction.rb @@ -2,5 +2,3 @@ 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/multi_receipts_extractor.rb b/lib/mindee/extraction/multi_receipts_extractor/multi_receipts_extractor.rb index 6b5bc729..eff201b2 100644 --- a/lib/mindee/extraction/multi_receipts_extractor/multi_receipts_extractor.rb +++ b/lib/mindee/extraction/multi_receipts_extractor/multi_receipts_extractor.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../common/image_extractor' +require_relative '../../image/image_extractor' module Mindee # Image Extraction Module. @@ -15,13 +15,16 @@ def self.extract_receipts(input_source, 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 + unless inference.prediction.receipts + raise Errors::MindeeInputError, + 'No possible receipts candidates found for Multi-Receipts extraction.' + end (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) + Mindee::Image::ImageExtractor.extract_multiple_images_from_source(input_source, page_id + 1, + receipt_positions) ) 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/http.rb b/lib/mindee/http.rb index d4b3375e..649b58cb 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/error_handler' require_relative 'http/workflow_endpoint' diff --git a/lib/mindee/http/endpoint.rb b/lib/mindee/http/endpoint.rb index 7b2cfe75..e1e31c04 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 'error_handler' require_relative '../version' require_relative 'response_validation' @@ -65,7 +65,7 @@ def predict(input_source, all_words, full_text, close_file, cropper) return [hashed_response, response.body] if ResponseValidation.valid_sync_response?(response) ResponseValidation.clean_request!(response) - error = Error.handle_error(@url_name, response) + error = ErrorHandler.handle_error(@url_name, response) raise error end @@ -83,7 +83,7 @@ def predict_async(input_source, all_words, full_text, close_file, cropper) 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 @@ -97,7 +97,7 @@ 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 @@ -201,9 +201,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/error_handler.rb similarity index 74% rename from lib/mindee/http/error.rb rename to lib/mindee/http/error_handler.rb index 84a7368c..b4ade5ac 100644 --- a/lib/mindee/http/error.rb +++ b/lib/mindee/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/workflow_endpoint.rb b/lib/mindee/http/workflow_endpoint.rb index 79e08897..594b5acf 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 'error_handler' module Mindee module HTTP @@ -37,7 +37,7 @@ 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 = ErrorHandler.handle_error(@url_name, response) raise error end @@ -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 64% rename from lib/mindee/extraction/common/extracted_image.rb rename to lib/mindee/image/extracted_image.rb index 44a4fb07..9292ba2b 100644 --- a/lib/mindee/extraction/common/extracted_image.rb +++ b/lib/mindee/image/extracted_image.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -require_relative '../../input/sources' +require_relative '../input/sources' 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. @@ -28,11 +28,12 @@ def initialize(input_source, page_id, element_id) @buffer = StringIO.new(input_source.io_stream.read) @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 +44,22 @@ 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.downcase + image.write resolved_path.to_s + 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 97% rename from lib/mindee/extraction/common/image_extractor.rb rename to lib/mindee/image/image_extractor.rb index acd2bd7a..a360f906 100644 --- a/lib/mindee/extraction/common/image_extractor.rb +++ b/lib/mindee/image/image_extractor.rb @@ -4,12 +4,12 @@ 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 def self.attach_image_as_new_file(input_buffer, format: 'jpg') @@ -35,7 +35,7 @@ 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.seek(0) @@ -49,7 +49,7 @@ 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 = [] diff --git a/lib/mindee/image/image_utils.rb b/lib/mindee/image/image_utils.rb index d839cdf5..a7b970a9 100644 --- a/lib/mindee/image/image_utils.rb +++ b/lib/mindee/image/image_utils.rb @@ -36,7 +36,8 @@ def self.to_image(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? diff --git a/lib/mindee/input/local_response.rb b/lib/mindee/input/local_response.rb index 88736f97..fafe3fdf 100644 --- a/lib/mindee/input/local_response.rb +++ b/lib/mindee/input/local_response.rb @@ -27,7 +27,7 @@ def initialize(input_file) 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,7 +56,7 @@ 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 diff --git a/lib/mindee/input/sources/local_input_source.rb b/lib/mindee/input/sources/local_input_source.rb index 1d2dadea..48939cfc 100644 --- a/lib/mindee/input/sources/local_input_source.rb +++ b/lib/mindee/input/sources/local_input_source.rb @@ -20,29 +20,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] @@ -72,7 +49,7 @@ def initialize(io_stream, filename, fix_pdf: false) 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 +58,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 diff --git a/lib/mindee/input/sources/url_input_source.rb b/lib/mindee/input/sources/url_input_source.rb index 5b4a9b13..989e8461 100644 --- a/lib/mindee/input/sources/url_input_source.rb +++ b/lib/mindee/input/sources/url_input_source.rb @@ -13,7 +13,7 @@ class UrlInputSource 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://' @url = url end @@ -27,7 +27,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) @@ -72,9 +72,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 @@ -100,7 +100,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/parsing/common/api_response.rb b/lib/mindee/parsing/common/api_response.rb index f8bfc3e5..74fe3a24 100644 --- a/lib/mindee/parsing/common/api_response.rb +++ b/lib/mindee/parsing/common/api_response.rb @@ -108,7 +108,7 @@ class ApiResponse # @param raw_http [String] def initialize(product_class, http_response, raw_http) @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']) 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 65% rename from lib/mindee/extraction/pdf_extractor/extracted_pdf.rb rename to lib/mindee/pdf/extracted_pdf.rb index e8ade1e8..a8160bf1 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 @@ -26,17 +26,20 @@ def initialize(pdf_bytes, filename) def page_count 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 [Boolean] 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/extraction/pdf_extractor/pdf_extractor.rb b/lib/mindee/pdf/pdf_extractor.rb similarity index 82% rename from lib/mindee/extraction/pdf_extractor/pdf_extractor.rb rename to lib/mindee/pdf/pdf_extractor.rb index 14b429bb..39826c49 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) @@ -40,24 +40,27 @@ def cut_pages(page_indexes) # 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 @@ -69,9 +72,9 @@ def extract_sub_documents(page_indexes) # Extracts invoices as complete PDFs from the document. # @param page_indexes [Array, InvoiceSplitterV1PageGroup>] # @param strict [Boolean] - # @return [Array] + # @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..f5cf0400 100644 --- a/lib/mindee/pdf/pdf_processor.rb +++ b/lib/mindee/pdf/pdf_processor.rb @@ -28,13 +28,12 @@ def self.parse(io_stream, options) all_pages = (0..pages_count - 1).to_a - case options[:operation] - when :KEEP_ONLY + if options[:operation] == :KEEP_ONLY pages_to_remove = indexes_from_keep(options[:page_indexes], all_pages) - when :REMOVE + 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 diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 51c3479f..2e3716e2 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -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.enqueue_and_parse( + input_source, + Mindee::Product::Invoice::InvoiceV4, + max_retries: 0 + ) + end.to raise_error ArgumentError + expect do + mindee_client.enqueue_and_parse( + input_source, + Mindee::Product::Invoice::InvoiceV4, + initial_delay_sec: 0.5 + ) + end.to raise_error ArgumentError + expect do + mindee_client.enqueue_and_parse( + input_source, + Mindee::Product::Invoice::InvoiceV4, + 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::Generated::GeneratedV1, + endpoint_name: nil, + account_name: 'account_name', + version: 'version' + ) + end.to raise_error Mindee::Errors::MindeeConfigurationError + + expect do + mindee_client.send( + :initialize_endpoint, + Mindee::Product::Generated::GeneratedV1, + endpoint_name: '', + account_name: 'account_name', + version: 'version' + ) + end.to raise_error Mindee::Errors::MindeeConfigurationError + end end end diff --git a/spec/extraction/invoice_splitter_extraction_integration.rb b/spec/extraction/invoice_splitter_extraction_integration.rb index f6401d32..e32b8ad0 100644 --- a/spec/extraction/invoice_splitter_extraction_integration.rb +++ b/spec/extraction/invoice_splitter_extraction_integration.rb @@ -30,7 +30,7 @@ def prepare_invoice_return(rst_file_path, invoice_prediction) ) 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..a3876347 100644 --- a/spec/extraction/multi_receipts_extractor_spec.rb +++ b/spec/extraction/multi_receipts_extractor_spec.rb @@ -5,8 +5,19 @@ require 'mindee/extraction' require_relative '../data' -describe Mindee::Extraction do - include Mindee::Extraction +describe Mindee::Extraction::MultiReceiptsExtractor do + include Mindee::Image + 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_pdf_pages: 0) + end let(:multi_receipts_single_page_path) do File.join(DATA_DIR, 'products', 'multi_receipts_detector', 'default_sample.jpg') end @@ -111,4 +122,20 @@ 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 + described_class.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 = described_class.extract_receipts(empty_input_source, valid_inference_with_no_receipts) + expect(extracted_receipts).to eq([]) + end + end end diff --git a/spec/http/error_spec.rb b/spec/http/error_handler_spec.rb similarity index 81% rename from spec/http/error_spec.rb rename to spec/http/error_handler_spec.rb index 45154587..2b2c0a3b 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') @@ -13,7 +13,7 @@ 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 + 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 82% rename from spec/extraction/image_extractor_spec.rb rename to spec/image/image_extractor_spec.rb index ff4c9667..0fb4efac 100644 --- a/spec/extraction/image_extractor_spec.rb +++ b/spec/image/image_extractor_spec.rb @@ -5,8 +5,8 @@ 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 @@ -23,10 +23,10 @@ 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..7526e7c3 --- /dev/null +++ b/spec/image/image_utils_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +# spec/image_utils_spec.rb +require 'rspec' +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/files_handling_spec.rb b/spec/input/sources/files_handling_spec.rb similarity index 99% rename from spec/input/files_handling_spec.rb rename to spec/input/sources/files_handling_spec.rb index b38da352..4c068d89 100644 --- a/spec/input/files_handling_spec.rb +++ b/spec/input/sources/files_handling_spec.rb @@ -2,7 +2,7 @@ require 'mindee/input/sources' require 'base64' -require_relative '../data' +require_relative '../../data' describe Mindee::Input::Source::LocalInputSource do context 'An jpg input file' do diff --git a/spec/input/sources/sources_spec.rb b/spec/input/sources/sources_spec.rb new file mode 100644 index 00000000..885a768d --- /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", 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::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", + 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 +end diff --git a/spec/input/url_input_source_integration.rb b/spec/input/sources/url_input_source_integration.rb similarity index 100% rename from spec/input/url_input_source_integration.rb rename to spec/input/sources/url_input_source_integration.rb diff --git a/spec/input/url_input_source_spec.rb b/spec/input/sources/url_input_source_spec.rb similarity index 81% rename from spec/input/url_input_source_spec.rb rename to spec/input/sources/url_input_source_spec.rb index 12cc4b8d..d2a86f63 100644 --- a/spec/input/url_input_source_spec.rb +++ b/spec/input/sources/url_input_source_spec.rb @@ -2,7 +2,7 @@ require 'rspec' require 'mindee' -require_relative '../http/mock_http_response' +require_relative '../../http/mock_http_response' RSpec.describe Mindee::Input::Source::UrlInputSource do let(:valid_url) { 'https://validurl/some/file.jpg' } @@ -20,7 +20,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 +59,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 +79,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 +104,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/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/pdf/extracted_pdf_spec.rb b/spec/pdf/extracted_pdf_spec.rb new file mode 100644 index 00000000..afccf91c --- /dev/null +++ b/spec/pdf/extracted_pdf_spec.rb @@ -0,0 +1,94 @@ +# frozen_string_literal: true + +require 'mindee' +require 'rspec' + +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 91% rename from spec/extraction/pdf_extractor_spec.rb rename to spec/pdf/pdf_extractor_spec.rb index e8ca5e2c..6de412f0 100644 --- a/spec/extraction/pdf_extractor_spec.rb +++ b/spec/pdf/pdf_extractor_spec.rb @@ -20,13 +20,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 +45,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/input/pdf_processing_spec.rb b/spec/pdf/pdf_processor_spec.rb similarity index 89% rename from spec/input/pdf_processing_spec.rb rename to spec/pdf/pdf_processor_spec.rb index 4feae54c..0ef77fe1 100644 --- a/spec/input/pdf_processing_spec.rb +++ b/spec/pdf/pdf_processor_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'mindee/pdf' +require 'mindee' require_relative '../data' @@ -108,5 +108,18 @@ def open_pdf(io_stream) 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 = { + 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 From a7ebf687ebd91279c5e0ece3170307f885d5515d Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 28 Jan 2025 17:15:09 +0100 Subject: [PATCH 04/17] :boom: refactor extraction, image & pdf modules (#144) --- ...auto_multi_receipts_detector_extraction.rb | 5 +- lib/mindee.rb | 1 - lib/mindee/extraction.rb | 1 - .../extraction/multi_receipts_extractor.rb | 29 +- .../multi_receipts_extractor.rb | 35 -- lib/mindee/extraction/tax_extractor.rb | 3 - .../extraction/tax_extractor/ocr_extractor.rb | 110 ------ .../extraction/tax_extractor/tax_extractor.rb | 338 ------------------ lib/mindee/image/image_extractor.rb | 73 +--- lib/mindee/image/image_utils.rb | 57 +++ .../multi_receipts_extractor_spec.rb | 12 +- spec/extraction/tax_extractor_spec.rb | 23 -- spec/image/image_extractor_spec.rb | 1 - 13 files changed, 101 insertions(+), 587 deletions(-) delete mode 100644 lib/mindee/extraction/multi_receipts_extractor/multi_receipts_extractor.rb delete mode 100644 lib/mindee/extraction/tax_extractor.rb delete mode 100644 lib/mindee/extraction/tax_extractor/ocr_extractor.rb delete mode 100644 lib/mindee/extraction/tax_extractor/tax_extractor.rb delete mode 100644 spec/extraction/tax_extractor_spec.rb diff --git a/examples/auto_multi_receipts_detector_extraction.rb b/examples/auto_multi_receipts_detector_extraction.rb index 97d95930..63a5410b 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 ) - 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") diff --git a/lib/mindee.rb b/lib/mindee.rb index 3dfe29ed..61c8e97d 100644 --- a/lib/mindee.rb +++ b/lib/mindee.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'mindee/client' -require 'mindee/extraction' module Mindee # Mindee internal error module. diff --git a/lib/mindee/extraction.rb b/lib/mindee/extraction.rb index fddb170d..b10552bd 100644 --- a/lib/mindee/extraction.rb +++ b/lib/mindee/extraction.rb @@ -1,4 +1,3 @@ # frozen_string_literal: true -require_relative 'extraction/tax_extractor' require_relative 'extraction/multi_receipts_extractor' diff --git a/lib/mindee/extraction/multi_receipts_extractor.rb b/lib/mindee/extraction/multi_receipts_extractor.rb index fac4862d..7a4339c2 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_pdf_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 eff201b2..00000000 --- a/lib/mindee/extraction/multi_receipts_extractor/multi_receipts_extractor.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../image/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 = [] - unless inference.prediction.receipts - raise Errors::MindeeInputError, - 'No possible receipts candidates found for Multi-Receipts extraction.' - end - - (0...input_source.count_pdf_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 -end 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/image/image_extractor.rb b/lib/mindee/image/image_extractor.rb index a360f906..9be99c88 100644 --- a/lib/mindee/image/image_extractor.rb +++ b/lib/mindee/image/image_extractor.rb @@ -37,7 +37,7 @@ def self.attach_image_as_new_file(input_buffer, format: 'jpg') # to extract. # @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) @@ -54,8 +54,8 @@ def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygon 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,8 +69,8 @@ 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 @@ -78,7 +78,7 @@ def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygon 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,63 +87,6 @@ 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. @@ -163,8 +106,8 @@ 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) diff --git a/lib/mindee/image/image_utils.rb b/lib/mindee/image/image_utils.rb index a7b970a9..ce8cc4cf 100644 --- a/lib/mindee/image/image_utils.rb +++ b/lib/mindee/image/image_utils.rb @@ -100,6 +100,63 @@ 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) + 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 end end end diff --git a/spec/extraction/multi_receipts_extractor_spec.rb b/spec/extraction/multi_receipts_extractor_spec.rb index a3876347..abffe667 100644 --- a/spec/extraction/multi_receipts_extractor_spec.rb +++ b/spec/extraction/multi_receipts_extractor_spec.rb @@ -5,8 +5,7 @@ require 'mindee/extraction' require_relative '../data' -describe Mindee::Extraction::MultiReceiptsExtractor do - include Mindee::Image +describe 'multi-receipts extraction' do let(:empty_inference) do double('Inference', prediction: double('Prediction', receipts: nil), pages: []) end @@ -39,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) @@ -87,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) @@ -126,7 +125,7 @@ context 'when no receipts are found in inference' do it 'raises a MindeeInputError' do expect do - described_class.extract_receipts(empty_input_source, empty_inference) + 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 @@ -134,7 +133,8 @@ context 'when input source has no pages' do it 'returns an empty array' do - extracted_receipts = described_class.extract_receipts(empty_input_source, valid_inference_with_no_receipts) + extracted_receipts = Mindee::Extraction.extract_receipts(empty_input_source, + valid_inference_with_no_receipts) expect(extracted_receipts).to eq([]) 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/image/image_extractor_spec.rb b/spec/image/image_extractor_spec.rb index 0fb4efac..98515925 100644 --- a/spec/image/image_extractor_spec.rb +++ b/spec/image/image_extractor_spec.rb @@ -2,7 +2,6 @@ require 'mindee/product' require 'mindee/input/sources' -require 'mindee/extraction' require_relative '../data' describe Mindee::Image do From 39beb42be185591306add9e07898f2cc812b62b0 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 29 Jan 2025 09:57:50 +0100 Subject: [PATCH 05/17] :boom: deprecate custom & generated, replace with universal (#143) --- README.md | 9 +- bin/mindee.rb | 28 ++--- docs/code_samples/custom_v1.txt | 33 ------ docs/code_samples/default.txt | 2 +- docs/code_samples/default_async.txt | 2 +- docs/custom_v1.md | 111 ------------------ docs/getting_started.md | 10 +- docs/{generated_v1.md => universal.md} | 30 ++--- lib/mindee.rb | 8 +- lib/mindee/client.rb | 17 +-- lib/mindee/image/image_extractor.rb | 2 +- lib/mindee/parsing.rb | 3 +- lib/mindee/parsing/common/api_response.rb | 2 +- lib/mindee/parsing/common/execution.rb | 4 +- lib/mindee/parsing/common/page.rb | 2 +- lib/mindee/parsing/custom.rb | 4 - .../parsing/custom/classification_field.rb | 28 ----- lib/mindee/parsing/custom/list_field.rb | 78 ------------ lib/mindee/parsing/generated.rb | 4 - ..._list_field.rb => universal_list_field.rb} | 20 ++-- ...ect_field.rb => universal_object_field.rb} | 8 +- lib/mindee/parsing/universal.rb | 4 + lib/mindee/product.rb | 3 +- lib/mindee/product/custom/custom_v1.rb | 36 ------ .../product/custom/custom_v1_document.rb | 60 ---------- lib/mindee/product/custom/custom_v1_page.rb | 32 ----- .../bank_statement_v1_document.rb | 2 +- .../universal.rb} | 16 +-- .../universal_document.rb} | 16 +-- .../universal_page.rb} | 22 ++-- .../universal_prediction.rb} | 16 +-- spec/client_spec.rb | 6 +- spec/document/custom_v1_spec.rb | 61 ---------- ...generated_v1_spec.rb => universal_spec.rb} | 22 ++-- spec/workflow/workflow_spec.rb | 4 +- 35 files changed, 126 insertions(+), 579 deletions(-) delete mode 100644 docs/code_samples/custom_v1.txt delete mode 100644 docs/custom_v1.md rename docs/{generated_v1.md => universal.md} (75%) delete mode 100644 lib/mindee/parsing/custom.rb delete mode 100644 lib/mindee/parsing/custom/classification_field.rb delete mode 100644 lib/mindee/parsing/custom/list_field.rb delete mode 100644 lib/mindee/parsing/generated.rb rename lib/mindee/parsing/generated/{generated_list_field.rb => universal_list_field.rb} (71%) rename lib/mindee/parsing/generated/{generated_object_field.rb => universal_object_field.rb} (96%) create mode 100644 lib/mindee/parsing/universal.rb delete mode 100644 lib/mindee/product/custom/custom_v1.rb delete mode 100644 lib/mindee/product/custom/custom_v1_document.rb delete mode 100644 lib/mindee/product/custom/custom_v1_page.rb rename lib/mindee/product/{generated/generated_v1.rb => universal/universal.rb} (65%) rename lib/mindee/product/{generated/generated_v1_document.rb => universal/universal_document.rb} (61%) rename lib/mindee/product/{generated/generated_v1_page.rb => universal/universal_page.rb} (64%) rename lib/mindee/product/{generated/generated_v1_prediction.rb => universal/universal_prediction.rb} (87%) delete mode 100644 spec/document/custom_v1_spec.rb rename spec/document/{generated_v1_spec.rb => universal_spec.rb} (97%) diff --git a/README.md b/README.md index 7a79e4ea..6a9a2718 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,9 @@ result = mindee_client.parse( 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' @@ -133,7 +135,7 @@ input_source = mindee_client.source_from_path('/path/to/the/file.ext') result = mindee_client.enqueue_and_parse( input_source, - Mindee::Product::Generated::GeneratedV1, + Mindee::Product::Universal::Universal, endpoint: endpoint ) @@ -225,8 +227,7 @@ 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) +* [Universal API Ruby](https://developers.mindee.com/docs/ruby-universal-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) diff --git a/bin/mindee.rb b/bin/mindee.rb index 0622f4c3..6752fb01 100755 --- a/bin/mindee.rb +++ b/bin/mindee.rb @@ -7,15 +7,9 @@ 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, }, @@ -154,7 +148,7 @@ 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| @@ -183,10 +177,8 @@ def custom_subcommand(cli_parser, options) opts.on('-F', '--fix-pdf', "Attempts to fix broken PDF files before sending them to the server.") do |v| options[:fix_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 +198,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 +221,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]) end -if command == 'custom' || command == 'generated' +if command == 'universal' custom_endpoint = mindee_client.create_endpoint( endpoint_name: endpoint_name, account_name: options[:account_name], 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..18231fbd 100644 --- a/docs/code_samples/default.txt +++ b/docs/code_samples/default.txt @@ -16,7 +16,7 @@ custom_endpoint = mindee_client.create_endpoint( # Parse the file result = mindee_client.parse( input_source, - Mindee::Product::Generated::GeneratedV1, + Mindee::Product::Universal::Universal, endpoint: custom_endpoint ) diff --git a/docs/code_samples/default_async.txt b/docs/code_samples/default_async.txt index 85c645b2..a9dc6132 100644 --- a/docs/code_samples/default_async.txt +++ b/docs/code_samples/default_async.txt @@ -16,7 +16,7 @@ custom_endpoint = mindee_client.create_endpoint( # Parse the file result = mindee_client.enqueue_and_parse( input_source, - Mindee::Product::Generated::GeneratedV1, + Mindee::Product::Universal::Universal, endpoint: custom_endpoint ) 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 3ea76bca..cc90f734 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -75,7 +75,7 @@ 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). @@ -226,7 +226,7 @@ result = mindee_client.parse( ) ``` -### Custom Documents (docTI) +### Universal Documents (docTI) For custom documents, the endpoint to use must also be set, and it must take in an `endpoint_name`: ```ruby @@ -234,15 +234,15 @@ endpoint = mindee_client.create_endpoint(endpoint_name: 'wnine', account_name: ' result = mindee_client.enqueue_and_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 diff --git a/docs/generated_v1.md b/docs/universal.md similarity index 75% rename from docs/generated_v1.md rename to docs/universal.md index 46935222..f0211e52 100644 --- a/docs/generated_v1.md +++ b/docs/universal.md @@ -1,11 +1,11 @@ --- -title: Generated API Ruby +title: Universal API Ruby category: 622b805aaec68102ea7fcbc2 -slug: ruby-generated-ocr +slug: ruby-universal-ocr parentDoc: 6294d97ee723f1008d2ab28e --- -The Ruby OCR SDK supports generated APIs. -Generated APIs can theoretically support all APIs in a catch-all generic format. +The Ruby OCR SDK supports a universal wrapper class for all products. +Universal supports all product in a catch-all generic format. # Quick-Start @@ -28,7 +28,7 @@ custom_endpoint = mindee_client.create_endpoint( # Parse the file result = mindee_client.enqueue_and_parse( input_source, - Mindee::Product::Generated::GeneratedV1, + Mindee::Product::Universal::Universal, endpoint: custom_endpoint ) @@ -36,22 +36,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 +60,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,11 +78,11 @@ 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 puts result.document.inference.prediction.fields["my-field"].to_s diff --git a/lib/mindee.rb b/lib/mindee.rb index 61c8e97d..80c5434e 100644 --- a/lib/mindee.rb +++ b/lib/mindee.rb @@ -42,16 +42,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 diff --git a/lib/mindee/client.rb b/lib/mindee/client.rb index d83737dc..10d8d781 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -111,7 +111,7 @@ def enqueue( # 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. @@ -233,7 +233,7 @@ def execute_workflow( 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, + Mindee::Parsing::Common::WorkflowResponse.new(Product::Universal::Universal, prediction, raw_http) end @@ -302,8 +302,12 @@ 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 @@ -342,9 +346,8 @@ 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?) && - [Mindee::Product::Custom::CustomV1, Mindee::Product::Generated::GeneratedV1].include?(product_class) - raise Errors::MindeeConfigurationError, '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) diff --git a/lib/mindee/image/image_extractor.rb b/lib/mindee/image/image_extractor.rb index 9be99c88..c7420d3f 100644 --- a/lib/mindee/image/image_extractor.rb +++ b/lib/mindee/image/image_extractor.rb @@ -91,7 +91,7 @@ def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygon # # @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 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/api_response.rb b/lib/mindee/parsing/common/api_response.rb index 74fe3a24..eaaf0734 100644 --- a/lib/mindee/parsing/common/api_response.rb +++ b/lib/mindee/parsing/common/api_response.rb @@ -138,7 +138,7 @@ class WorkflowResponse 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::Generated::GeneratedV1 + product_class ||= Product::Universal::Universal @execution = Mindee::Parsing::Common::Execution.new(product_class, http_response['execution']) end end diff --git a/lib/mindee/parsing/common/execution.rb b/lib/mindee/parsing/common/execution.rb index d0e080e4..a9f678bd 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,7 @@ 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 = UniversalDocument.new(http_response['reviewed_prediction']) end @status = http_response['status'] @type = http_response['type'] diff --git a/lib/mindee/parsing/common/page.rb b/lib/mindee/parsing/common/page.rb index f784bb5b..e2bcca0a 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. 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/generated/generated_list_field.rb b/lib/mindee/parsing/generated/universal_list_field.rb similarity index 71% rename from lib/mindee/parsing/generated/generated_list_field.rb rename to lib/mindee/parsing/generated/universal_list_field.rb index 430e2da4..cd7d45f0 100644 --- a/lib/mindee/parsing/generated/generated_list_field.rb +++ b/lib/mindee/parsing/generated/universal_list_field.rb @@ -1,24 +1,24 @@ # 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) @@ -27,8 +27,8 @@ def initialize(raw_prediction, page_id = nil) 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.generated_object?(value) + @values.push(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? diff --git a/lib/mindee/parsing/generated/generated_object_field.rb b/lib/mindee/parsing/generated/universal_object_field.rb similarity index 96% rename from lib/mindee/parsing/generated/generated_object_field.rb rename to lib/mindee/parsing/generated/universal_object_field.rb index 1388a309..b8b52ff9 100644 --- a/lib/mindee/parsing/generated/generated_object_field.rb +++ b/lib/mindee/parsing/generated/universal_object_field.rb @@ -4,14 +4,14 @@ 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 + class UniversalObjectField include Mindee::Parsing::Standard attr_accessor :page_id, :confidence, :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. diff --git a/lib/mindee/parsing/universal.rb b/lib/mindee/parsing/universal.rb new file mode 100644 index 00000000..37f58225 --- /dev/null +++ b/lib/mindee/parsing/universal.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +require_relative 'generated/universal_object_field' +require_relative 'generated/universal_list_field' diff --git a/lib/mindee/product.rb b/lib/mindee/product.rb index 788d8518..eccad62b 100644 --- a/lib/mindee/product.rb +++ b/lib/mindee/product.rb @@ -3,7 +3,6 @@ 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' @@ -21,7 +20,7 @@ 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/universal/universal' require_relative 'product/ind/indian_passport/indian_passport_v1' require_relative 'product/invoice/invoice_v4' require_relative 'product/invoice_splitter/invoice_splitter_v1' 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 df435220..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 = 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/fr/bank_statement/bank_statement_v1_document.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb index 540784c4..c4ca7ce1 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb @@ -31,7 +31,7 @@ class BankStatementV1Document < Mindee::Parsing::Common::Prediction # 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. + # The date on which the bank statement was universal. # @return [Mindee::Parsing::Standard::DateField] attr_reader :statement_date # The date when the statement period ends. diff --git a/lib/mindee/product/generated/generated_v1.rb b/lib/mindee/product/universal/universal.rb similarity index 65% rename from lib/mindee/product/generated/generated_v1.rb rename to lib/mindee/product/universal/universal.rb index fd8bb242..74f51838 100644 --- a/lib/mindee/product/generated/generated_v1.rb +++ b/lib/mindee/product/universal/universal.rb @@ -1,25 +1,25 @@ # frozen_string_literal: true -require_relative 'generated_v1_document' -require_relative 'generated_v1_page' +require_relative 'universal_document' +require_relative 'universal_page' module Mindee module Product - # Generated product module. - module Generated - # Generated Document V1 prediction inference. - class GeneratedV1 < Mindee::Parsing::Common::Inference + # Universal product module. + module Universal + # Universal Document V1 prediction inference. + class Universal < Mindee::Parsing::Common::Inference @endpoint_name = '' @endpoint_version = '' # @param prediction [Hash] def initialize(prediction) super - @prediction = GeneratedV1Document.new(prediction['prediction']) + @prediction = UniversalDocument.new(prediction['prediction']) @pages = [] prediction['pages'].each do |page| if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty? - @pages.push(GeneratedV1Page.new(page)) + @pages.push(UniversalPage.new(page)) end end end diff --git a/lib/mindee/product/generated/generated_v1_document.rb b/lib/mindee/product/universal/universal_document.rb similarity index 61% rename from lib/mindee/product/generated/generated_v1_document.rb rename to lib/mindee/product/universal/universal_document.rb index 1f4d15af..37cbf4e6 100644 --- a/lib/mindee/product/generated/generated_v1_document.rb +++ b/lib/mindee/product/universal/universal_document.rb @@ -1,25 +1,25 @@ # 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 prediction - class GeneratedV1Document < Mindee::Product::Generated::GeneratedV1Prediction + module Universal + # Universal Document V1 prediction + class UniversalDocument < Mindee::Product::Universal::UniversalPrediction include Mindee::Parsing::Standard # @param raw_prediction [Hash] def initialize(raw_prediction) - # Generated document. + # Universal 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) + @fields[field_name] = Parsing::Universal::UniversalListField.new(field_contents) + elsif field_contents.is_a?(Hash) && Parsing::Universal.generated_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 diff --git a/lib/mindee/product/generated/generated_v1_page.rb b/lib/mindee/product/universal/universal_page.rb similarity index 64% rename from lib/mindee/product/generated/generated_v1_page.rb rename to lib/mindee/product/universal/universal_page.rb index bfcc1578..1c368533 100644 --- a/lib/mindee/product/generated/generated_v1_page.rb +++ b/lib/mindee/product/universal/universal_page.rb @@ -1,34 +1,34 @@ # 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 = GeneratedV1PagePrediction.new( + @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() 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] = UniversalListField.new(field_contents, page_id) + elsif field_contents.is_a?(Hash) && Parsing::Universal.generated_object?(field_contents) + @fields[field_name] = UniversalObjectField.new(field_contents, page_id) else field_contents_str = field_contents.dup if field_contents_str.key?('value') && !field_contents_str['value'].nil? diff --git a/lib/mindee/product/generated/generated_v1_prediction.rb b/lib/mindee/product/universal/universal_prediction.rb similarity index 87% rename from lib/mindee/product/generated/generated_v1_prediction.rb rename to lib/mindee/product/universal/universal_prediction.rb index f86cc479..73f2c7b5 100644 --- a/lib/mindee/product/generated/generated_v1_prediction.rb +++ b/lib/mindee/product/universal/universal_prediction.rb @@ -4,14 +4,14 @@ 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 @@ -24,7 +24,7 @@ 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?(UniversalListField) && field_value.values.length.positive? generate_field_string(field_name, field_value, pattern) else field_value.to_s @@ -42,13 +42,13 @@ def generate_field_string(field_name, field_value, pattern) return '' if field_value.values.empty? || field_value.values.nil? str_value = '' - str_value += if field_value.values[0].is_a?(Parsing::Generated::GeneratedObjectField) + str_value += if field_value.values[0].is_a?(Parsing::Universal::UniversalObjectField) field_value.values[0].str_level(1).sub(pattern, '\\1* :') else "#{field_value.values[0].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) + 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" diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 2e3716e2..b38e00b5 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -101,8 +101,8 @@ expect do mindee_client.send( :initialize_endpoint, - Mindee::Product::Generated::GeneratedV1, - endpoint_name: nil, + Mindee::Product::Universal::Universal, + endpoint_name: '', account_name: 'account_name', version: 'version' ) @@ -111,7 +111,7 @@ expect do mindee_client.send( :initialize_endpoint, - Mindee::Product::Generated::GeneratedV1, + Mindee::Product::Universal::Universal, endpoint_name: '', account_name: 'account_name', version: 'version' 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/generated_v1_spec.rb b/spec/document/universal_spec.rb similarity index 97% rename from spec/document/generated_v1_spec.rb rename to spec/document/universal_spec.rb index 89f38c42..4f0b7017 100644 --- a/spec/document/generated_v1_spec.rb +++ b/spec/document/universal_spec.rb @@ -8,10 +8,10 @@ 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) +GeneratedListField = Mindee::Parsing::Universal.const_get(:UniversalListField) +GeneratedObjectField = 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 @@ -21,7 +21,7 @@ 'generated', 'response_v1', 'complete_international_id_v1.json'))) - Document.new(GeneratedV1, + Document.new(Universal, parsed_file['document']) end @@ -29,7 +29,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 @@ -238,7 +238,7 @@ '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 +247,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 +271,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'] @@ -391,7 +391,7 @@ 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) 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 ) From 865cc2a7fc542c896faa115d89cee6dff517e9d9 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 29 Jan 2025 11:50:25 +0100 Subject: [PATCH 06/17] :sparkles: add support for logging (#145) --- lib/mindee.rb | 9 ++++++ lib/mindee/client.rb | 29 +++++++++++++++++-- lib/mindee/http/endpoint.rb | 7 +++-- lib/mindee/http/workflow_endpoint.rb | 2 +- lib/mindee/image/extracted_image.rb | 2 ++ .../input/sources/base64_input_source.rb | 2 +- .../input/sources/local_input_source.rb | 9 ++++-- lib/mindee/input/sources/url_input_source.rb | 3 ++ lib/mindee/logging.rb | 3 ++ lib/mindee/logging/logger.rb | 14 +++++++++ lib/mindee/parsing/common/api_response.rb | 2 ++ lib/mindee/pdf/pdf_compressor.rb | 9 +++--- spec/client_spec.rb | 18 ++++++------ spec/input/sources/files_handling_spec.rb | 16 +++++----- spec/input/sources/sources_spec.rb | 2 +- 15 files changed, 96 insertions(+), 31 deletions(-) create mode 100644 lib/mindee/logging.rb create mode 100644 lib/mindee/logging/logger.rb diff --git a/lib/mindee.rb b/lib/mindee.rb index 80c5434e..f44c9eaa 100644 --- a/lib/mindee.rb +++ b/lib/mindee.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'mindee/client' +require 'mindee/logging' module Mindee # Mindee internal error module. @@ -36,6 +37,10 @@ module ImageCompressor end end + # Logging + module Logging + end + # Parsing internals and fields. module Parsing # Common fields and functions. @@ -70,3 +75,7 @@ module US end end end + +def logger + Mindee::Logging.logger +end diff --git a/lib/mindee/client.rb b/lib/mindee/client.rb index 10d8d781..35d6c2f6 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -4,6 +4,9 @@ require_relative 'http' require_relative 'product' require_relative 'parsing/common/api_response' +require_relative 'logging' + +OTS_OWNER = 'mindee' module Mindee # Mindee API Client. @@ -57,6 +60,9 @@ def parse( input_source.process_pdf(page_options) end endpoint = initialize_endpoint(product_class) if endpoint.nil? + + logger.debug("Parsing document as '#{endpoint.url_root}'") + 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 @@ -104,6 +110,9 @@ def enqueue( input_source.process_pdf(page_options) end endpoint = initialize_endpoint(product_class) if endpoint.nil? + + logger.debug("Enqueueing document as '#{endpoint.url_root}'") + 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) @@ -123,6 +132,9 @@ def parse_queued( 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 @@ -177,11 +189,16 @@ def enqueue_and_parse( page_options: page_options, cropper: cropper ) + job_id = enqueue_res.job.id sleep(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 + logger.debug("Polling server for parsing result with job id: '#{job_id}. Attempt #{polling_attempts}'") sleep(delay_sec) queue_res = parse_queued(job_id, product_class, endpoint: endpoint) polling_attempts += 1 @@ -231,6 +248,9 @@ def execute_workflow( end workflow_endpoint = Mindee::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key) + + logger.debug("Sending document to workflow '#{workflow_id}'") + prediction, raw_http = workflow_endpoint.execute_workflow(input_source, full_text, document_alias, priority, public_url) Mindee::Parsing::Common::WorkflowResponse.new(Product::Universal::Universal, @@ -363,6 +383,7 @@ def fix_endpoint_name(product_class, endpoint_name) end def fix_account_name(account_name) + logger.info("No account name provided, #{OTS_OWNER} will be used by default.") return 'mindee' if account_name.nil? || account_name.empty? account_name @@ -370,7 +391,11 @@ def fix_account_name(account_name) 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 diff --git a/lib/mindee/http/endpoint.rb b/lib/mindee/http/endpoint.rb index e1e31c04..03255163 100644 --- a/lib/mindee/http/endpoint.rb +++ b/lib/mindee/http/endpoint.rb @@ -40,6 +40,9 @@ 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).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}" @@ -125,7 +128,7 @@ def predict_req_post(input_source, all_words: false, full_text: false, close_fil 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 @@ -159,7 +162,7 @@ def document_queue_req_get(input_source, all_words, full_text, close_file, cropp 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 diff --git a/lib/mindee/http/workflow_endpoint.rb b/lib/mindee/http/workflow_endpoint.rb index 594b5acf..d7274322 100644 --- a/lib/mindee/http/workflow_endpoint.rb +++ b/lib/mindee/http/workflow_endpoint.rb @@ -62,7 +62,7 @@ def workflow_execution_req_post(input_source, document_alias, priority, full_tex 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 diff --git a/lib/mindee/image/extracted_image.rb b/lib/mindee/image/extracted_image.rb index 9292ba2b..5c18705e 100644 --- a/lib/mindee/image/extracted_image.rb +++ b/lib/mindee/image/extracted_image.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative '../input/sources' +require_relative '../logging' module Mindee # Image Extraction Module. @@ -56,6 +57,7 @@ def write_to_file(output_path, file_format = nil) image = MiniMagick::Image.read(@buffer) image.format file_format.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?.' diff --git a/lib/mindee/input/sources/base64_input_source.rb b/lib/mindee/input/sources/base64_input_source.rb index 2cee59aa..0499fa9d 100644 --- a/lib/mindee/input/sources/base64_input_source.rb +++ b/lib/mindee/input/sources/base64_input_source.rb @@ -19,7 +19,7 @@ def initialize(base64_string, filename, fix_pdf: false) # Overload of the same function to prevent a base64 from being re-encoded. # @param close [Boolean] # @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/local_input_source.rb b/lib/mindee/input/sources/local_input_source.rb index 48939cfc..77dab457 100644 --- a/lib/mindee/input/sources/local_input_source.rb +++ b/lib/mindee/input/sources/local_input_source.rb @@ -40,12 +40,16 @@ def initialize(io_stream, filename, fix_pdf: false) 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 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 @@ -89,7 +93,8 @@ def process_pdf(options) # Reads a document. # @param close [Boolean] # @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 diff --git a/lib/mindee/input/sources/url_input_source.rb b/lib/mindee/input/sources/url_input_source.rb index 989e8461..b80dfc42 100644 --- a/lib/mindee/input/sources/url_input_source.rb +++ b/lib/mindee/input/sources/url_input_source.rb @@ -3,6 +3,7 @@ require 'net/http' require 'uri' require 'fileutils' +require_relative '../../logging' module Mindee module Input @@ -15,6 +16,8 @@ class UrlInputSource def initialize(url) raise Errors::MindeeInputError, 'URL must be HTTPS' unless url.start_with? 'https://' + logger.debug("URL input: #{url}") + @url = url end 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..fe0ffe2b --- /dev/null +++ b/lib/mindee/logging/logger.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'logger' + +module Mindee + # Mindee logging module. + module Logging + @logger = Logger.new($stdout) + + class << self + attr_accessor :logger + end + end +end diff --git a/lib/mindee/parsing/common/api_response.rb b/lib/mindee/parsing/common/api_response.rb index eaaf0734..be9f0b8e 100644 --- a/lib/mindee/parsing/common/api_response.rb +++ b/lib/mindee/parsing/common/api_response.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative 'document' +require_relative '../../logging' require 'time' module Mindee @@ -107,6 +108,7 @@ 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 Errors::MindeeAPIError, 'Invalid response format.' unless http_response.key?('api_request') diff --git a/lib/mindee/pdf/pdf_compressor.rb b/lib/mindee/pdf/pdf_compressor.rb index f33cc504..dada7d61 100644 --- a/lib/mindee/pdf/pdf_compressor.rb +++ b/lib/mindee/pdf/pdf_compressor.rb @@ -15,13 +15,13 @@ def self.compress_pdf(pdf_data, quality: 85, force_source_text_compression: fals 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 @@ -54,7 +54,6 @@ def self.process_pdf_pages(pdf, quality) # @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/spec/client_spec.rb b/spec/client_spec.rb index b38e00b5..4c888520 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 diff --git a/spec/input/sources/files_handling_spec.rb b/spec/input/sources/files_handling_spec.rb index 4c068d89..46786d59 100644 --- a/spec/input/sources/files_handling_spec.rb +++ b/spec/input/sources/files_handling_spec.rb @@ -9,7 +9,7 @@ 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/sources_spec.rb b/spec/input/sources/sources_spec.rb index 885a768d..927cabee 100644 --- a/spec/input/sources/sources_spec.rb +++ b/spec/input/sources/sources_spec.rb @@ -76,7 +76,7 @@ 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) + 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 From aa0879efcf6f31f554e61de23354b7b03f00b126 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 29 Jan 2025 16:58:38 +0100 Subject: [PATCH 07/17] :boom: allow page objects to be created even if they don't have an associated prediction (#146) --- lib/mindee/parsing/common/inference.rb | 6 +++-- .../barcode_reader/barcode_reader_v1.rb | 4 +-- .../barcode_reader/barcode_reader_v1_page.rb | 12 ++++++--- .../bill_of_lading/bill_of_lading_v1.rb | 4 +-- .../bill_of_lading/bill_of_lading_v1_page.rb | 12 ++++++--- .../product/business_card/business_card_v1.rb | 4 +-- .../business_card/business_card_v1_page.rb | 12 ++++++--- lib/mindee/product/cropper/cropper_v1.rb | 4 +-- lib/mindee/product/cropper/cropper_v1_page.rb | 12 ++++++--- .../product/delivery_note/delivery_note_v1.rb | 4 +-- .../delivery_note/delivery_note_v1_page.rb | 12 ++++++--- .../driver_license/driver_license_v1.rb | 4 +-- .../driver_license/driver_license_v1_page.rb | 12 ++++++--- .../eu/license_plate/license_plate_v1.rb | 4 +-- .../eu/license_plate/license_plate_v1_page.rb | 12 ++++++--- .../financial_document_v1.rb | 4 +-- .../financial_document_v1_page.rb | 12 ++++++--- .../bank_account_details_v1.rb | 4 +-- .../bank_account_details_v1_page.rb | 12 ++++++--- .../bank_account_details_v2.rb | 4 +-- .../bank_account_details_v2_page.rb | 12 ++++++--- .../product/fr/carte_grise/carte_grise_v1.rb | 4 +-- .../fr/carte_grise/carte_grise_v1_page.rb | 12 ++++++--- .../product/fr/energy_bill/energy_bill_v1.rb | 4 +-- .../fr/energy_bill/energy_bill_v1_page.rb | 12 ++++++--- .../product/fr/health_card/health_card_v1.rb | 4 +-- .../fr/health_card/health_card_v1_page.rb | 12 ++++++--- lib/mindee/product/fr/id_card/id_card_v1.rb | 4 +-- .../product/fr/id_card/id_card_v1_page.rb | 12 ++++++--- lib/mindee/product/fr/id_card/id_card_v2.rb | 4 +-- .../product/fr/id_card/id_card_v2_page.rb | 12 ++++++--- lib/mindee/product/fr/payslip/payslip_v2.rb | 4 +-- .../product/fr/payslip/payslip_v2_page.rb | 12 ++++++--- lib/mindee/product/fr/payslip/payslip_v3.rb | 4 +-- .../product/fr/payslip/payslip_v3_page.rb | 12 ++++++--- .../ind/indian_passport/indian_passport_v1.rb | 4 +-- .../indian_passport_v1_page.rb | 12 ++++++--- .../international_id/international_id_v2.rb | 4 +-- .../international_id_v2_page.rb | 12 ++++++--- lib/mindee/product/invoice/invoice_v4.rb | 4 +-- lib/mindee/product/invoice/invoice_v4_page.rb | 12 ++++++--- .../multi_receipts_detector_v1.rb | 4 +-- .../multi_receipts_detector_v1_page.rb | 12 ++++++--- .../nutrition_facts_label_v1.rb | 4 +-- .../nutrition_facts_label_v1_page.rb | 12 ++++++--- lib/mindee/product/passport/passport_v1.rb | 4 +-- .../product/passport/passport_v1_page.rb | 12 ++++++--- lib/mindee/product/receipt/receipt_v5.rb | 4 +-- lib/mindee/product/receipt/receipt_v5_page.rb | 12 ++++++--- lib/mindee/product/resume/resume_v1.rb | 4 +-- lib/mindee/product/resume/resume_v1_page.rb | 12 ++++++--- .../product/us/bank_check/bank_check_v1.rb | 4 +-- .../us/bank_check/bank_check_v1_page.rb | 12 ++++++--- .../us/healthcare_card/healthcare_card_v1.rb | 4 +-- .../healthcare_card_v1_page.rb | 12 ++++++--- lib/mindee/product/us/us_mail/us_mail_v2.rb | 4 +-- .../product/us/us_mail/us_mail_v2_page.rb | 12 ++++++--- lib/mindee/product/us/us_mail/us_mail_v3.rb | 4 +-- .../product/us/us_mail/us_mail_v3_page.rb | 12 ++++++--- lib/mindee/product/us/w9/w9_v1.rb | 4 +-- lib/mindee/product/us/w9/w9_v1_page.rb | 12 ++++++--- spec/extras/full_text_ocr_spec.rb | 27 +++++++++---------- 62 files changed, 287 insertions(+), 226 deletions(-) diff --git a/lib/mindee/parsing/common/inference.rb b/lib/mindee/parsing/common/inference.rb index 443a1fa5..f5469de0 100644 --- a/lib/mindee/parsing/common/inference.rb +++ b/lib/mindee/parsing/common/inference.rb @@ -34,8 +34,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/product/barcode_reader/barcode_reader_v1.rb b/lib/mindee/product/barcode_reader/barcode_reader_v1.rb index 4aed66a3..ed1d5da5 100644 --- a/lib/mindee/product/barcode_reader/barcode_reader_v1.rb +++ b/lib/mindee/product/barcode_reader/barcode_reader_v1.rb @@ -19,9 +19,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 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 508fc2e5..9eec7859 100644 --- a/lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb +++ b/lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb @@ -11,10 +11,14 @@ class BarcodeReaderV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = BarcodeReaderV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..c1902b23 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 @@ -19,9 +19,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 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 2d1479bc..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 @@ -11,10 +11,14 @@ class BillOfLadingV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = BillOfLadingV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + BillOfLadingV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/business_card/business_card_v1.rb b/lib/mindee/product/business_card/business_card_v1.rb index fbd6cffc..c20eb9bd 100644 --- a/lib/mindee/product/business_card/business_card_v1.rb +++ b/lib/mindee/product/business_card/business_card_v1.rb @@ -19,9 +19,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 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 1c75a0f9..48813699 100644 --- a/lib/mindee/product/business_card/business_card_v1_page.rb +++ b/lib/mindee/product/business_card/business_card_v1_page.rb @@ -11,10 +11,14 @@ class BusinessCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = BusinessCardV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..3d79ff48 100644 --- a/lib/mindee/product/cropper/cropper_v1.rb +++ b/lib/mindee/product/cropper/cropper_v1.rb @@ -19,9 +19,7 @@ def initialize(prediction) @prediction = CropperV1Document.new @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 diff --git a/lib/mindee/product/cropper/cropper_v1_page.rb b/lib/mindee/product/cropper/cropper_v1_page.rb index ad5a778b..b401f0c6 100644 --- a/lib/mindee/product/cropper/cropper_v1_page.rb +++ b/lib/mindee/product/cropper/cropper_v1_page.rb @@ -11,10 +11,14 @@ class CropperV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = CropperV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + CropperV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + 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..33d376d9 100644 --- a/lib/mindee/product/delivery_note/delivery_note_v1.rb +++ b/lib/mindee/product/delivery_note/delivery_note_v1.rb @@ -19,9 +19,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 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 4a481e44..b7aaa8e1 100644 --- a/lib/mindee/product/delivery_note/delivery_note_v1_page.rb +++ b/lib/mindee/product/delivery_note/delivery_note_v1_page.rb @@ -11,10 +11,14 @@ class DeliveryNoteV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = DeliveryNoteV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..ec4267bd 100644 --- a/lib/mindee/product/driver_license/driver_license_v1.rb +++ b/lib/mindee/product/driver_license/driver_license_v1.rb @@ -19,9 +19,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 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 5b06fceb..3d1a3641 100644 --- a/lib/mindee/product/driver_license/driver_license_v1_page.rb +++ b/lib/mindee/product/driver_license/driver_license_v1_page.rb @@ -11,10 +11,14 @@ class DriverLicenseV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = DriverLicenseV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + DriverLicenseV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + 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..40b88b44 100644 --- a/lib/mindee/product/eu/license_plate/license_plate_v1.rb +++ b/lib/mindee/product/eu/license_plate/license_plate_v1.rb @@ -20,9 +20,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 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 b9697fff..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 @@ -12,10 +12,14 @@ class LicensePlateV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = LicensePlateV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..6f733d3f 100644 --- a/lib/mindee/product/financial_document/financial_document_v1.rb +++ b/lib/mindee/product/financial_document/financial_document_v1.rb @@ -19,9 +19,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 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 557d451b..5917e3e9 100644 --- a/lib/mindee/product/financial_document/financial_document_v1_page.rb +++ b/lib/mindee/product/financial_document/financial_document_v1_page.rb @@ -11,10 +11,14 @@ class FinancialDocumentV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = FinancialDocumentV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..7d9bd296 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 @@ -20,9 +20,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 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 fe6418a8..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 @@ -12,10 +12,14 @@ class BankAccountDetailsV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = BankAccountDetailsV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..2aa5d075 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 @@ -20,9 +20,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 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 840fc6c2..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 @@ -12,10 +12,14 @@ class BankAccountDetailsV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = BankAccountDetailsV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + BankAccountDetailsV2PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + 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..904f0572 100644 --- a/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb +++ b/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb @@ -20,9 +20,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 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 c67b1b43..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 @@ -12,10 +12,14 @@ class CarteGriseV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = CarteGriseV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..be5a407f 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb @@ -20,9 +20,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 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 2abc8972..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 @@ -12,10 +12,14 @@ class EnergyBillV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = EnergyBillV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + EnergyBillV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + 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..61b98fc3 100644 --- a/lib/mindee/product/fr/health_card/health_card_v1.rb +++ b/lib/mindee/product/fr/health_card/health_card_v1.rb @@ -20,9 +20,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 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 890d2cf7..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 @@ -12,10 +12,14 @@ class HealthCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = HealthCardV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..2bee92fc 100644 --- a/lib/mindee/product/fr/id_card/id_card_v1.rb +++ b/lib/mindee/product/fr/id_card/id_card_v1.rb @@ -20,9 +20,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 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 a47d38b4..caac1a49 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 @@ -12,10 +12,14 @@ class IdCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = IdCardV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + IdCardV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end 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..fa05dea2 100644 --- a/lib/mindee/product/fr/id_card/id_card_v2.rb +++ b/lib/mindee/product/fr/id_card/id_card_v2.rb @@ -20,9 +20,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 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 776e0be1..08a538cf 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 @@ -12,10 +12,14 @@ class IdCardV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = IdCardV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + IdCardV2PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/fr/payslip/payslip_v2.rb b/lib/mindee/product/fr/payslip/payslip_v2.rb index f6d42859..ff690dcc 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2.rb @@ -20,9 +20,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 diff --git a/lib/mindee/product/fr/payslip/payslip_v2_page.rb b/lib/mindee/product/fr/payslip/payslip_v2_page.rb index a526de22..05e8914b 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_page.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_page.rb @@ -12,10 +12,14 @@ class PayslipV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = PayslipV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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_v3.rb b/lib/mindee/product/fr/payslip/payslip_v3.rb index a6f5fc74..57f90e31 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3.rb @@ -20,9 +20,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 diff --git a/lib/mindee/product/fr/payslip/payslip_v3_page.rb b/lib/mindee/product/fr/payslip/payslip_v3_page.rb index a030b9ce..cac295bf 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_page.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_page.rb @@ -12,10 +12,14 @@ class PayslipV3Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = PayslipV3PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + PayslipV3PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + 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..f2f330bb 100644 --- a/lib/mindee/product/ind/indian_passport/indian_passport_v1.rb +++ b/lib/mindee/product/ind/indian_passport/indian_passport_v1.rb @@ -20,9 +20,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 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 fe0261e4..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 @@ -12,10 +12,14 @@ class IndianPassportV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = IndianPassportV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..e7691d66 100644 --- a/lib/mindee/product/international_id/international_id_v2.rb +++ b/lib/mindee/product/international_id/international_id_v2.rb @@ -19,9 +19,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 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 90fe0c58..d958db90 100644 --- a/lib/mindee/product/international_id/international_id_v2_page.rb +++ b/lib/mindee/product/international_id/international_id_v2_page.rb @@ -11,10 +11,14 @@ class InternationalIdV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = InternationalIdV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..93b6a5b9 100644 --- a/lib/mindee/product/invoice/invoice_v4.rb +++ b/lib/mindee/product/invoice/invoice_v4.rb @@ -19,9 +19,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 diff --git a/lib/mindee/product/invoice/invoice_v4_page.rb b/lib/mindee/product/invoice/invoice_v4_page.rb index 5c004298..f8f33616 100644 --- a/lib/mindee/product/invoice/invoice_v4_page.rb +++ b/lib/mindee/product/invoice/invoice_v4_page.rb @@ -11,10 +11,14 @@ class InvoiceV4Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = InvoiceV4PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + InvoiceV4PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end 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..5fa22718 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 @@ -19,9 +19,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 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 077287f5..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 @@ -11,10 +11,14 @@ class MultiReceiptsDetectorV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = MultiReceiptsDetectorV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..05fc63f6 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 @@ -19,9 +19,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 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 a2bf5fd4..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 @@ -11,10 +11,14 @@ class NutritionFactsLabelV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = NutritionFactsLabelV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + NutritionFactsLabelV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/passport/passport_v1.rb b/lib/mindee/product/passport/passport_v1.rb index e3cc942c..ab3e5048 100644 --- a/lib/mindee/product/passport/passport_v1.rb +++ b/lib/mindee/product/passport/passport_v1.rb @@ -19,9 +19,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 diff --git a/lib/mindee/product/passport/passport_v1_page.rb b/lib/mindee/product/passport/passport_v1_page.rb index e68f1429..5816f85b 100644 --- a/lib/mindee/product/passport/passport_v1_page.rb +++ b/lib/mindee/product/passport/passport_v1_page.rb @@ -11,10 +11,14 @@ class PassportV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = PassportV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + PassportV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/receipt/receipt_v5.rb b/lib/mindee/product/receipt/receipt_v5.rb index 8097a1b3..da7cb593 100644 --- a/lib/mindee/product/receipt/receipt_v5.rb +++ b/lib/mindee/product/receipt/receipt_v5.rb @@ -19,9 +19,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 diff --git a/lib/mindee/product/receipt/receipt_v5_page.rb b/lib/mindee/product/receipt/receipt_v5_page.rb index 83ab99a8..5b0aaefc 100644 --- a/lib/mindee/product/receipt/receipt_v5_page.rb +++ b/lib/mindee/product/receipt/receipt_v5_page.rb @@ -11,10 +11,14 @@ class ReceiptV5Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = ReceiptV5PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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..3cfa04a3 100644 --- a/lib/mindee/product/resume/resume_v1.rb +++ b/lib/mindee/product/resume/resume_v1.rb @@ -19,9 +19,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 diff --git a/lib/mindee/product/resume/resume_v1_page.rb b/lib/mindee/product/resume/resume_v1_page.rb index 44aca387..2032a349 100644 --- a/lib/mindee/product/resume/resume_v1_page.rb +++ b/lib/mindee/product/resume/resume_v1_page.rb @@ -11,10 +11,14 @@ class ResumeV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = ResumeV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + ResumeV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end 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..826b5593 100644 --- a/lib/mindee/product/us/bank_check/bank_check_v1.rb +++ b/lib/mindee/product/us/bank_check/bank_check_v1.rb @@ -20,9 +20,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 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 9ad4ccd9..f391a61f 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 @@ -12,10 +12,14 @@ class BankCheckV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = BankCheckV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + BankCheckV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + 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..e5be13ce 100644 --- a/lib/mindee/product/us/healthcare_card/healthcare_card_v1.rb +++ b/lib/mindee/product/us/healthcare_card/healthcare_card_v1.rb @@ -20,9 +20,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 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 41e6e11f..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 @@ -12,10 +12,14 @@ class HealthcareCardV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = HealthcareCardV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @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 index 5b58064a..d508d238 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v2.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v2.rb @@ -20,9 +20,7 @@ def initialize(prediction) @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 + @pages.push(UsMailV2Page.new(page)) 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 index f20c1613..b3d3596e 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v2_page.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v2_page.rb @@ -12,10 +12,14 @@ class UsMailV2Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = UsMailV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + UsMailV2PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + 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..3eed3521 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v3.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v3.rb @@ -20,9 +20,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 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 9fbd0a93..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 @@ -12,10 +12,14 @@ class UsMailV3Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = UsMailV3PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + UsMailV3PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/lib/mindee/product/us/w9/w9_v1.rb b/lib/mindee/product/us/w9/w9_v1.rb index c6aee79d..55822542 100644 --- a/lib/mindee/product/us/w9/w9_v1.rb +++ b/lib/mindee/product/us/w9/w9_v1.rb @@ -20,9 +20,7 @@ def initialize(prediction) @prediction = W9V1Document.new @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 diff --git a/lib/mindee/product/us/w9/w9_v1_page.rb b/lib/mindee/product/us/w9/w9_v1_page.rb index 2024ed7e..3733d19a 100644 --- a/lib/mindee/product/us/w9/w9_v1_page.rb +++ b/lib/mindee/product/us/w9/w9_v1_page.rb @@ -12,10 +12,14 @@ class W9V1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = W9V1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + W9V1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end diff --git a/spec/extras/full_text_ocr_spec.rb b/spec/extras/full_text_ocr_spec.rb index f41a81c3..35140b13 100644 --- a/spec/extras/full_text_ocr_spec.rb +++ b/spec/extras/full_text_ocr_spec.rb @@ -4,17 +4,16 @@ 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 @@ -39,16 +38,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 From 2f41c886f6826c3369c2c0c22322a429c64157e0 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Thu, 30 Jan 2025 09:33:53 +0100 Subject: [PATCH 08/17] :boom: refactor internals to reduce clutter inside of files (#147) --- lib/mindee/client.rb | 2 + lib/mindee/parsing/common.rb | 3 + lib/mindee/parsing/common/api_request.rb | 36 ++++++++ lib/mindee/parsing/common/api_response.rb | 88 ------------------- lib/mindee/parsing/common/job.rb | 46 ++++++++++ .../parsing/common/workflow_response.rb | 28 ++++++ lib/mindee/parsing/standard.rb | 1 + lib/mindee/parsing/standard/abstract_field.rb | 72 +++++++++++++++ lib/mindee/parsing/standard/amount_field.rb | 4 +- lib/mindee/parsing/standard/base_field.rb | 83 +---------------- lib/mindee/parsing/standard/boolean_field.rb | 2 +- .../parsing/standard/classification_field.rb | 2 +- .../standard/company_registration_field.rb | 2 +- lib/mindee/parsing/standard/date_field.rb | 2 +- lib/mindee/parsing/standard/feature_field.rb | 24 +++++ .../parsing/standard/payment_details_field.rb | 2 +- lib/mindee/parsing/standard/string_field.rb | 2 +- lib/mindee/parsing/standard/tax_field.rb | 2 +- lib/mindee/parsing/universal.rb | 4 +- .../universal_list_field.rb | 2 +- .../universal_object_field.rb | 2 +- .../bill_of_lading_v1_carrier_item.rb | 12 +-- .../financial_document_v1_line_item.rb | 20 ++--- .../bank_statement_v1_transaction.rb | 2 +- .../energy_bill_v1_energy_usage.rb | 12 +-- .../energy_bill_v1_subscription.rb | 12 +-- .../energy_bill_v1_taxes_and_contribution.rb | 12 +-- .../fr/payslip/payslip_v2_employment.rb | 2 +- .../fr/payslip/payslip_v2_pay_detail.rb | 20 ++--- .../product/fr/payslip/payslip_v2_pto.rb | 6 +- .../fr/payslip/payslip_v2_salary_detail.rb | 12 +-- .../fr/payslip/payslip_v3_paid_time_off.rb | 12 +-- .../fr/payslip/payslip_v3_pay_detail.rb | 20 ++--- .../fr/payslip/payslip_v3_salary_detail.rb | 16 ++-- .../product/invoice/invoice_v4_line_item.rb | 20 ++--- .../nutrition_facts_label_v1_added_sugar.rb | 6 +- .../nutrition_facts_label_v1_calorie.rb | 6 +- .../nutrition_facts_label_v1_cholesterol.rb | 6 +- .../nutrition_facts_label_v1_dietary_fiber.rb | 6 +- .../nutrition_facts_label_v1_nutrient.rb | 12 +-- .../nutrition_facts_label_v1_protein.rb | 6 +- .../nutrition_facts_label_v1_saturated_fat.rb | 6 +- .../nutrition_facts_label_v1_serving_size.rb | 2 +- .../nutrition_facts_label_v1_sodium.rb | 6 +- ...ition_facts_label_v1_total_carbohydrate.rb | 6 +- .../nutrition_facts_label_v1_total_fat.rb | 6 +- .../nutrition_facts_label_v1_total_sugar.rb | 6 +- .../nutrition_facts_label_v1_trans_fat.rb | 6 +- .../product/receipt/receipt_v5_line_item.rb | 12 +-- .../product/universal/universal_document.rb | 2 +- .../product/universal/universal_page.rb | 2 +- .../product/universal/universal_prediction.rb | 10 +-- .../healthcare_card_v1_copay.rb | 4 +- spec/document/universal_spec.rb | 58 ++++++------ 54 files changed, 400 insertions(+), 355 deletions(-) create mode 100644 lib/mindee/parsing/common/api_request.rb create mode 100644 lib/mindee/parsing/common/job.rb create mode 100644 lib/mindee/parsing/common/workflow_response.rb create mode 100644 lib/mindee/parsing/standard/abstract_field.rb create mode 100644 lib/mindee/parsing/standard/feature_field.rb rename lib/mindee/parsing/{generated => universal}/universal_list_field.rb (96%) rename lib/mindee/parsing/{generated => universal}/universal_object_field.rb (98%) diff --git a/lib/mindee/client.rb b/lib/mindee/client.rb index 35d6c2f6..93d572ac 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -4,6 +4,8 @@ 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' OTS_OWNER = 'mindee' 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 be9f0b8e..d13679db 100644 --- a/lib/mindee/parsing/common/api_response.rb +++ b/lib/mindee/parsing/common/api_response.rb @@ -2,7 +2,6 @@ require_relative 'document' require_relative '../../logging' -require 'time' module Mindee module Parsing @@ -27,72 +26,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] @@ -123,27 +56,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::Universal::Universal - @execution = Mindee::Parsing::Common::Execution.new(product_class, http_response['execution']) - end - end end end end diff --git a/lib/mindee/parsing/common/job.rb b/lib/mindee/parsing/common/job.rb new file mode 100644 index 00000000..31e79bf3 --- /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 [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 + 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..3b51cc82 --- /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 ||= 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/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..f1c58034 100644 --- a/lib/mindee/parsing/standard/base_field.rb +++ b/lib/mindee/parsing/standard/base_field.rb @@ -1,75 +1,13 @@ # 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 + class BaseField < AbstractField # @return [String, Float, Integer, Boolean] attr_reader :value # true if the field was reconstructed or computed using other fields. @@ -85,23 +23,6 @@ def initialize(prediction, page_id, reconstructed: false) @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..c68affb1 100644 --- a/lib/mindee/parsing/standard/boolean_field.rb +++ b/lib/mindee/parsing/standard/boolean_field.rb @@ -6,7 +6,7 @@ module Mindee module Parsing module Standard # Represents basic text information. - class BooleanField < Field + class BooleanField < BaseField # Value as Boolean # @return [Boolean, nil] attr_reader :value 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..21e1fc2d 100644 --- a/lib/mindee/parsing/standard/company_registration_field.rb +++ b/lib/mindee/parsing/standard/company_registration_field.rb @@ -4,7 +4,7 @@ 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 diff --git a/lib/mindee/parsing/standard/date_field.rb b/lib/mindee/parsing/standard/date_field.rb index a0fe738c..9870f111 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 diff --git a/lib/mindee/parsing/standard/feature_field.rb b/lib/mindee/parsing/standard/feature_field.rb new file mode 100644 index 00000000..5ca8bedf --- /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, 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.to_s if max_col_size.nil? + + in_str = in_str.gsub(%r{[\n\r\t]}, "\n" => '\\n', "\r" => '\\r', "\t" => '\\t') + in_str.to_s.length <= max_col_size ? in_str.to_s : "#{in_str[0..max_col_size - 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..774f7011 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] diff --git a/lib/mindee/parsing/standard/string_field.rb b/lib/mindee/parsing/standard/string_field.rb index a7450305..c3cf20c1 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 < 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 index 37f58225..86f0408f 100644 --- a/lib/mindee/parsing/universal.rb +++ b/lib/mindee/parsing/universal.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true -require_relative 'generated/universal_object_field' -require_relative 'generated/universal_list_field' +require_relative 'universal/universal_object_field' +require_relative 'universal/universal_list_field' diff --git a/lib/mindee/parsing/generated/universal_list_field.rb b/lib/mindee/parsing/universal/universal_list_field.rb similarity index 96% rename from lib/mindee/parsing/generated/universal_list_field.rb rename to lib/mindee/parsing/universal/universal_list_field.rb index cd7d45f0..b16f6a52 100644 --- a/lib/mindee/parsing/generated/universal_list_field.rb +++ b/lib/mindee/parsing/universal/universal_list_field.rb @@ -27,7 +27,7 @@ def initialize(raw_prediction, page_id = nil) raw_prediction.each do |value| page_id = value['page_id'] if value.key?('page_id') && !value['page_id'].nil? - if Universal.generated_object?(value) + if Universal.universal_object?(value) @values.push(UniversalObjectField.new(value, page_id)) else value_str = value.dup diff --git a/lib/mindee/parsing/generated/universal_object_field.rb b/lib/mindee/parsing/universal/universal_object_field.rb similarity index 98% rename from lib/mindee/parsing/generated/universal_object_field.rb rename to lib/mindee/parsing/universal/universal_object_field.rb index b8b52ff9..5a1b3b5e 100644 --- a/lib/mindee/parsing/generated/universal_object_field.rb +++ b/lib/mindee/parsing/universal/universal_object_field.rb @@ -90,7 +90,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', 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 82cec8c6..d88c9fe1 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 @@ -44,10 +44,10 @@ 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? ? '' : BaseField.float_to_string(@gross_weight) + printable[:measurement] = @measurement.nil? ? '' : 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? ? '' : BaseField.float_to_string(@quantity) printable[:weight_unit] = format_for_display(@weight_unit) printable end @@ -56,10 +56,10 @@ 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? ? '' : BaseField.float_to_string(@gross_weight) + printable[:measurement] = @measurement.nil? ? '' : 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? ? '' : BaseField.float_to_string(@quantity) printable[:weight_unit] = format_for_display(@weight_unit, nil) printable end 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 5ce22614..6c48d527 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 @@ -53,12 +53,12 @@ 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? ? '' : BaseField.float_to_string(@quantity) + printable[:tax_amount] = @tax_amount.nil? ? '' : BaseField.float_to_string(@tax_amount) + printable[:tax_rate] = @tax_rate.nil? ? '' : BaseField.float_to_string(@tax_rate) + printable[:total_amount] = @total_amount.nil? ? '' : 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? ? '' : BaseField.float_to_string(@unit_price) printable end @@ -67,12 +67,12 @@ 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? ? '' : BaseField.float_to_string(@quantity) + printable[:tax_amount] = @tax_amount.nil? ? '' : BaseField.float_to_string(@tax_amount) + printable[:tax_rate] = @tax_rate.nil? ? '' : BaseField.float_to_string(@tax_rate) + printable[:total_amount] = @total_amount.nil? ? '' : 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? ? '' : BaseField.float_to_string(@unit_price) printable 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 index 5f5628dc..0c85f539 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb @@ -32,7 +32,7 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount) + printable[:amount] = @amount.nil? ? '' : BaseField.float_to_string(@amount) printable[:date] = format_for_display(@date, nil) printable[:description] = format_for_display(@description, 36) printable 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 9a567142..d9be4276 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 @@ -47,9 +47,9 @@ 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? ? '' : BaseField.float_to_string(@tax_rate) + printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) + printable[:unit_price] = @unit_price.nil? ? '' : BaseField.float_to_string(@unit_price) printable end @@ -59,9 +59,9 @@ 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? ? '' : BaseField.float_to_string(@tax_rate) + printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) + printable[:unit_price] = @unit_price.nil? ? '' : BaseField.float_to_string(@unit_price) printable 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 e02fe758..9f686038 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 @@ -47,9 +47,9 @@ 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? ? '' : BaseField.float_to_string(@tax_rate) + printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) + printable[:unit_price] = @unit_price.nil? ? '' : BaseField.float_to_string(@unit_price) printable end @@ -59,9 +59,9 @@ 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? ? '' : BaseField.float_to_string(@tax_rate) + printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) + printable[:unit_price] = @unit_price.nil? ? '' : BaseField.float_to_string(@unit_price) printable 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 11a55404..b14ccaee 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 @@ -47,9 +47,9 @@ 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? ? '' : BaseField.float_to_string(@tax_rate) + printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) + printable[:unit_price] = @unit_price.nil? ? '' : BaseField.float_to_string(@unit_price) printable end @@ -59,9 +59,9 @@ 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? ? '' : BaseField.float_to_string(@tax_rate) + printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) + printable[:unit_price] = @unit_price.nil? ? '' : BaseField.float_to_string(@unit_price) printable end diff --git a/lib/mindee/product/fr/payslip/payslip_v2_employment.rb b/lib/mindee/product/fr/payslip/payslip_v2_employment.rb index 0a8b5335..9dcfa085 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_employment.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_employment.rb @@ -45,7 +45,7 @@ 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? ? '' : 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_pay_detail.rb b/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb index 082ade2b..2f5e85a8 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb @@ -60,20 +60,20 @@ 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? ? '' : BaseField.float_to_string(@gross_salary) + printable[:gross_salary_ytd] = @gross_salary_ytd.nil? ? '' : BaseField.float_to_string(@gross_salary_ytd) + printable[:income_tax_rate] = @income_tax_rate.nil? ? '' : 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) + @income_tax_withheld.nil? ? '' : BaseField.float_to_string(@income_tax_withheld) + printable[:net_paid] = @net_paid.nil? ? '' : 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) + @net_paid_before_tax.nil? ? '' : BaseField.float_to_string(@net_paid_before_tax) + printable[:net_taxable] = @net_taxable.nil? ? '' : BaseField.float_to_string(@net_taxable) + printable[:net_taxable_ytd] = @net_taxable_ytd.nil? ? '' : BaseField.float_to_string(@net_taxable_ytd) printable[:total_cost_employer] = - @total_cost_employer.nil? ? '' : Field.float_to_string(@total_cost_employer) + @total_cost_employer.nil? ? '' : BaseField.float_to_string(@total_cost_employer) printable[:total_taxes_and_deductions] = - @total_taxes_and_deductions.nil? ? '' : Field.float_to_string(@total_taxes_and_deductions) + @total_taxes_and_deductions.nil? ? '' : BaseField.float_to_string(@total_taxes_and_deductions) printable end diff --git a/lib/mindee/product/fr/payslip/payslip_v2_pto.rb b/lib/mindee/product/fr/payslip/payslip_v2_pto.rb index aabad119..4089b230 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_pto.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_pto.rb @@ -33,10 +33,10 @@ def initialize(prediction, page_id) def printable_values printable = {} printable[:accrued_this_period] = - @accrued_this_period.nil? ? '' : Field.float_to_string(@accrued_this_period) + @accrued_this_period.nil? ? '' : BaseField.float_to_string(@accrued_this_period) 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) + @balance_end_of_period.nil? ? '' : BaseField.float_to_string(@balance_end_of_period) + printable[:used_this_period] = @used_this_period.nil? ? '' : 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 b4ba04c5..e4828b55 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb @@ -36,20 +36,20 @@ 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? ? '' : BaseField.float_to_string(@amount) + printable[:base] = @base.nil? ? '' : BaseField.float_to_string(@base) printable[:description] = format_for_display(@description) - printable[:rate] = @rate.nil? ? '' : Field.float_to_string(@rate) + printable[:rate] = @rate.nil? ? '' : 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? ? '' : BaseField.float_to_string(@amount) + printable[:base] = @base.nil? ? '' : 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? ? '' : BaseField.float_to_string(@rate) printable 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 eca6800e..7fa5e0b6 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 @@ -40,22 +40,22 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:accrued] = @accrued.nil? ? '' : Field.float_to_string(@accrued) + printable[:accrued] = @accrued.nil? ? '' : 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? ? '' : BaseField.float_to_string(@remaining) + printable[:used] = @used.nil? ? '' : 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? ? '' : 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? ? '' : BaseField.float_to_string(@remaining) + printable[:used] = @used.nil? ? '' : BaseField.float_to_string(@used) printable 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 83b5fb4b..555f8fde 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb @@ -60,20 +60,20 @@ 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? ? '' : BaseField.float_to_string(@gross_salary) + printable[:gross_salary_ytd] = @gross_salary_ytd.nil? ? '' : BaseField.float_to_string(@gross_salary_ytd) + printable[:income_tax_rate] = @income_tax_rate.nil? ? '' : 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) + @income_tax_withheld.nil? ? '' : BaseField.float_to_string(@income_tax_withheld) + printable[:net_paid] = @net_paid.nil? ? '' : 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) + @net_paid_before_tax.nil? ? '' : BaseField.float_to_string(@net_paid_before_tax) + printable[:net_taxable] = @net_taxable.nil? ? '' : BaseField.float_to_string(@net_taxable) + printable[:net_taxable_ytd] = @net_taxable_ytd.nil? ? '' : BaseField.float_to_string(@net_taxable_ytd) printable[:total_cost_employer] = - @total_cost_employer.nil? ? '' : Field.float_to_string(@total_cost_employer) + @total_cost_employer.nil? ? '' : BaseField.float_to_string(@total_cost_employer) printable[:total_taxes_and_deductions] = - @total_taxes_and_deductions.nil? ? '' : Field.float_to_string(@total_taxes_and_deductions) + @total_taxes_and_deductions.nil? ? '' : BaseField.float_to_string(@total_taxes_and_deductions) printable end 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 799b3bf9..86a78aa4 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb @@ -40,22 +40,22 @@ 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? ? '' : BaseField.float_to_string(@amount) + printable[:base] = @base.nil? ? '' : 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? ? '' : BaseField.float_to_string(@number) + printable[:rate] = @rate.nil? ? '' : 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? ? '' : BaseField.float_to_string(@amount) + printable[:base] = @base.nil? ? '' : 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? ? '' : BaseField.float_to_string(@number) + printable[:rate] = @rate.nil? ? '' : BaseField.float_to_string(@rate) printable end diff --git a/lib/mindee/product/invoice/invoice_v4_line_item.rb b/lib/mindee/product/invoice/invoice_v4_line_item.rb index ff8b4a61..a36aa237 100644 --- a/lib/mindee/product/invoice/invoice_v4_line_item.rb +++ b/lib/mindee/product/invoice/invoice_v4_line_item.rb @@ -53,12 +53,12 @@ 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? ? '' : BaseField.float_to_string(@quantity) + printable[:tax_amount] = @tax_amount.nil? ? '' : BaseField.float_to_string(@tax_amount) + printable[:tax_rate] = @tax_rate.nil? ? '' : BaseField.float_to_string(@tax_rate) + printable[:total_amount] = @total_amount.nil? ? '' : 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? ? '' : BaseField.float_to_string(@unit_price) printable end @@ -67,12 +67,12 @@ 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? ? '' : BaseField.float_to_string(@quantity) + printable[:tax_amount] = @tax_amount.nil? ? '' : BaseField.float_to_string(@tax_amount) + printable[:tax_rate] = @tax_rate.nil? ? '' : BaseField.float_to_string(@tax_rate) + printable[:total_amount] = @total_amount.nil? ? '' : 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? ? '' : BaseField.float_to_string(@unit_price) printable 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 4b7ac1e8..a090cab0 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 @@ -31,9 +31,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : 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 7cc8546d..6aafe190 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 @@ -31,9 +31,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : 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 d80729b2..edae3c87 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 @@ -31,9 +31,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : 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 7032464b..1d3359b4 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 @@ -31,9 +31,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : BaseField.float_to_string(@per_serving) printable end 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 9dcee678..0bf5ad64 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 @@ -39,10 +39,10 @@ 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? ? '' : 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? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : BaseField.float_to_string(@per_serving) printable[:unit] = format_for_display(@unit) printable end @@ -50,10 +50,10 @@ 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? ? '' : 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? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : 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_protein.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rb index 548dd260..547c3dcd 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 @@ -31,9 +31,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : 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 2a2cd06d..a56e57a7 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 @@ -31,9 +31,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : 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 2615ce6a..a4120bcc 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 @@ -27,7 +27,7 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : Field.float_to_string(@amount) + printable[:amount] = @amount.nil? ? '' : 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 0b521eeb..9084994b 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 @@ -35,9 +35,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : 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 3a34bb3d..61ec6e57 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 @@ -31,9 +31,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : 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 c5632119..0e92cedf 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 @@ -31,9 +31,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : 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 2e7a323c..e9b464ee 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 @@ -31,9 +31,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : 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 9a1cc35c..b48dd9d0 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 @@ -31,9 +31,9 @@ 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? ? '' : BaseField.float_to_string(@daily_value) + printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) + printable[:per_serving] = @per_serving.nil? ? '' : BaseField.float_to_string(@per_serving) printable end diff --git a/lib/mindee/product/receipt/receipt_v5_line_item.rb b/lib/mindee/product/receipt/receipt_v5_line_item.rb index 4fc8fcf7..66e1c65d 100644 --- a/lib/mindee/product/receipt/receipt_v5_line_item.rb +++ b/lib/mindee/product/receipt/receipt_v5_line_item.rb @@ -36,9 +36,9 @@ 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? ? '' : BaseField.float_to_string(@quantity) + printable[:total_amount] = @total_amount.nil? ? '' : BaseField.float_to_string(@total_amount) + printable[:unit_price] = @unit_price.nil? ? '' : BaseField.float_to_string(@unit_price) printable end @@ -46,9 +46,9 @@ 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? ? '' : BaseField.float_to_string(@quantity) + printable[:total_amount] = @total_amount.nil? ? '' : BaseField.float_to_string(@total_amount) + printable[:unit_price] = @unit_price.nil? ? '' : BaseField.float_to_string(@unit_price) printable end diff --git a/lib/mindee/product/universal/universal_document.rb b/lib/mindee/product/universal/universal_document.rb index 37cbf4e6..879290c2 100644 --- a/lib/mindee/product/universal/universal_document.rb +++ b/lib/mindee/product/universal/universal_document.rb @@ -18,7 +18,7 @@ def initialize(raw_prediction) 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.generated_object?(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 diff --git a/lib/mindee/product/universal/universal_page.rb b/lib/mindee/product/universal/universal_page.rb index 1c368533..2137834c 100644 --- a/lib/mindee/product/universal/universal_page.rb +++ b/lib/mindee/product/universal/universal_page.rb @@ -27,7 +27,7 @@ def initialize(raw_prediction, page_id = nil) raw_prediction.each do |field_name, field_contents| if field_contents.is_a?(Array) @fields[field_name] = UniversalListField.new(field_contents, page_id) - elsif field_contents.is_a?(Hash) && Parsing::Universal.generated_object?(field_contents) + elsif field_contents.is_a?(Hash) && Parsing::Universal.universal_object?(field_contents) @fields[field_name] = UniversalObjectField.new(field_contents, page_id) else field_contents_str = field_contents.dup diff --git a/lib/mindee/product/universal/universal_prediction.rb b/lib/mindee/product/universal/universal_prediction.rb index 73f2c7b5..82c1c6bd 100644 --- a/lib/mindee/product/universal/universal_prediction.rb +++ b/lib/mindee/product/universal/universal_prediction.rb @@ -66,7 +66,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?(UniversalObjectField) sub_value.str_level(1).gsub(pattern, '\1* :') else (' ' * (field_name.length + 2)) + "#{sub_value}\n" @@ -84,21 +84,21 @@ def single_fields end # Returns a hash of all list-like fields - # @return [Hash] + # @return [Hash] def list_fields list_fields = {} @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?(UniversalListField) end list_fields end # Returns a hash of all object-like fields - # @return [Hash] + # @return [Hash] def object_fields object_fields = {} @fields.each do |field_name, field_value| - object_fields[field_name] = field_value if field_value.is_a?(GeneratedObjectField) + object_fields[field_name] = field_value if field_value.is_a?(UniversalObjectField) end object_fields 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 44c51ae0..3606355d 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 @@ -28,7 +28,7 @@ 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? ? '' : BaseField.float_to_string(@service_fees) printable[:service_name] = format_for_display(@service_name) printable end @@ -36,7 +36,7 @@ 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? ? '' : BaseField.float_to_string(@service_fees) printable[:service_name] = format_for_display(@service_name, nil) printable end diff --git a/spec/document/universal_spec.rb b/spec/document/universal_spec.rb index 4f0b7017..8b4532d9 100644 --- a/spec/document/universal_spec.rb +++ b/spec/document/universal_spec.rb @@ -8,8 +8,8 @@ StringField = Mindee::Parsing::Standard.const_get(:StringField) PositionField = Mindee::Parsing::Standard.const_get(:PositionField) -GeneratedListField = Mindee::Parsing::Universal.const_get(:UniversalListField) -GeneratedObjectField = Mindee::Parsing::Universal.const_get(:UniversalObjectField) +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) @@ -54,10 +54,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 +131,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 +145,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] @@ -283,7 +283,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 +323,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 +349,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 +364,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 +373,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( @@ -397,7 +397,7 @@ 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 +415,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 +427,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 +466,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 +484,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 +494,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] From e1462afebf698836cb70a4b1b5c6bc8fed3f9028 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Thu, 30 Jan 2025 14:01:01 +0100 Subject: [PATCH 09/17] :coffin: remove support for US Driver License, EU Driver License & Proof of Address (#148) --- README.md | 3 - bin/mindee.rb | 18 --- docs/code_samples/eu_driver_license_v1.txt | 19 --- docs/code_samples/proof_of_address_v1.txt | 19 --- docs/code_samples/us_driver_license_v1.txt | 19 --- lib/mindee/product.rb | 3 - .../eu/driver_license/driver_license_v1.rb | 41 ------- .../driver_license_v1_document.rb | 88 -------------- .../driver_license/driver_license_v1_page.rb | 53 -------- .../proof_of_address/proof_of_address_v1.rb | 39 ------ .../proof_of_address_v1_document.rb | 83 ------------- .../proof_of_address_v1_page.rb | 32 ----- .../us/driver_license/driver_license_v1.rb | 41 ------- .../driver_license_v1_document.rb | 113 ------------------ .../driver_license/driver_license_v1_page.rb | 53 -------- spec/document/eu/driver_license_v1_spec.rb | 42 ------- spec/document/proof_of_address_v1_spec.rb | 32 ----- spec/document/us/driver_license_v1_spec.rb | 42 ------- 18 files changed, 740 deletions(-) delete mode 100644 docs/code_samples/eu_driver_license_v1.txt delete mode 100644 docs/code_samples/proof_of_address_v1.txt delete mode 100644 docs/code_samples/us_driver_license_v1.txt delete mode 100644 lib/mindee/product/eu/driver_license/driver_license_v1.rb delete mode 100644 lib/mindee/product/eu/driver_license/driver_license_v1_document.rb delete mode 100644 lib/mindee/product/eu/driver_license/driver_license_v1_page.rb delete mode 100644 lib/mindee/product/proof_of_address/proof_of_address_v1.rb delete mode 100644 lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb delete mode 100644 lib/mindee/product/proof_of_address/proof_of_address_v1_page.rb delete mode 100644 lib/mindee/product/us/driver_license/driver_license_v1.rb delete mode 100644 lib/mindee/product/us/driver_license/driver_license_v1_document.rb delete mode 100644 lib/mindee/product/us/driver_license/driver_license_v1_page.rb delete mode 100644 spec/document/eu/driver_license_v1_spec.rb delete mode 100644 spec/document/proof_of_address_v1_spec.rb delete mode 100644 spec/document/us/driver_license_v1_spec.rb diff --git a/README.md b/README.md index 6a9a2718..40c9ab4d 100644 --- a/README.md +++ b/README.md @@ -232,17 +232,14 @@ customize the experience. * [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) diff --git a/bin/mindee.rb b/bin/mindee.rb index 6752fb01..c2dd52d7 100755 --- a/bin/mindee.rb +++ b/bin/mindee.rb @@ -13,12 +13,6 @@ 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, @@ -73,12 +67,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, @@ -115,12 +103,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, diff --git a/docs/code_samples/eu_driver_license_v1.txt b/docs/code_samples/eu_driver_license_v1.txt deleted file mode 100644 index 0065552f..00000000 --- a/docs/code_samples/eu_driver_license_v1.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.parse( - input_source, - Mindee::Product::EU::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/proof_of_address_v1.txt b/docs/code_samples/proof_of_address_v1.txt deleted file mode 100644 index 940291ed..00000000 --- a/docs/code_samples/proof_of_address_v1.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.parse( - input_source, - Mindee::Product::ProofOfAddress::ProofOfAddressV1 -) - -# 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_driver_license_v1.txt b/docs/code_samples/us_driver_license_v1.txt deleted file mode 100644 index f5128301..00000000 --- a/docs/code_samples/us_driver_license_v1.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.parse( - input_source, - Mindee::Product::US::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/lib/mindee/product.rb b/lib/mindee/product.rb index eccad62b..d8f1188a 100644 --- a/lib/mindee/product.rb +++ b/lib/mindee/product.rb @@ -7,7 +7,6 @@ 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' @@ -28,12 +27,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/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' 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 0a5c0a6c..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 = 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 - 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/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 93ff6aa1..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 = 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/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 85ae0944..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 = 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 - 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/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/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/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 From 37268fe39bfddbcecd689da709a5282049dd92f5 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 4 Feb 2025 15:24:36 +0100 Subject: [PATCH 10/17] :boom: mutualise parse enqueue_and_parse calls (#150) --- README.md | 10 +- bin/mindee.rb | 24 +- docs/bank_account_details_v2.md | 1 - docs/bank_check_v1.md | 1 - docs/bank_statement_fr_v1.md | 2 +- docs/barcode_reader_v1.md | 1 - docs/bill_of_lading_v1.md | 3 +- docs/business_card_v1.md | 3 +- docs/carte_grise_v1.md | 1 - ..._fr_v1_async.txt => bill_of_lading_v1.txt} | 4 +- docs/code_samples/bill_of_lading_v1_async.txt | 2 +- docs/code_samples/business_card_v1.txt | 19 + docs/code_samples/business_card_v1_async.txt | 2 +- docs/code_samples/default.txt | 3 +- docs/code_samples/default_async.txt | 2 +- docs/code_samples/delivery_notes_v1.txt | 19 + docs/code_samples/delivery_notes_v1_async.txt | 2 +- docs/code_samples/driver_license_v1.txt | 19 + docs/code_samples/driver_license_v1_async.txt | 2 +- docs/code_samples/energy_bill_fra_v1.txt | 19 + .../code_samples/energy_bill_fra_v1_async.txt | 2 +- .../expense_receipts_v5_async.txt | 2 +- .../financial_document_v1_async.txt | 2 +- docs/code_samples/french_healthcard_v1.txt | 19 + .../french_healthcard_v1_async.txt | 2 +- docs/code_samples/ind_passport_v1.txt | 19 + docs/code_samples/ind_passport_v1_async.txt | 2 +- docs/code_samples/international_id_v2.txt | 19 + .../international_id_v2_async.txt | 2 +- .../invoice_splitter_v1_async.txt | 2 +- docs/code_samples/invoices_v4_async.txt | 2 +- docs/code_samples/nutrition_facts_v1.txt | 19 + .../code_samples/nutrition_facts_v1_async.txt | 2 +- docs/code_samples/payslip_fra_v2.txt | 19 + docs/code_samples/payslip_fra_v2_async.txt | 2 +- docs/code_samples/payslip_fra_v3.txt | 19 + docs/code_samples/payslip_fra_v3_async.txt | 2 +- ...{expense_receipts_v4.txt => resume_v1.txt} | 2 +- docs/code_samples/resume_v1_async.txt | 2 +- docs/code_samples/us_healthcare_cards_v1.txt | 19 + .../us_healthcare_cards_v1_async.txt | 2 +- docs/code_samples/us_mail_v2.txt | 19 + docs/code_samples/us_mail_v2_async.txt | 2 +- docs/code_samples/us_mail_v3.txt | 19 + docs/code_samples/us_mail_v3_async.txt | 2 +- docs/code_samples/workflow_execution.txt | 29 -- docs/cropper_v1.md | 1 - docs/delivery_notes_v1.md | 3 +- docs/driver_license_v1.md | 3 +- docs/energy_bill_fra_v1.md | 3 +- docs/expense_receipts_v5.md | 26 - docs/financial_document_v1.md | 26 - docs/french_healthcard_v1.md | 3 +- docs/getting_started.md | 6 +- docs/idcard_fr_v2.md | 1 - docs/ind_passport_v1.md | 3 +- docs/international_id_v2.md | 3 +- docs/invoice_splitter_v1.md | 2 +- docs/invoices_v4.md | 26 - docs/license_plates_v1.md | 1 - docs/multi_receipts_detector_v1.md | 1 - docs/nutrition_facts_v1.md | 3 +- docs/passport_v1.md | 1 - docs/payslip_fra_v2.md | 2 +- docs/payslip_fra_v3.md | 3 +- docs/resume_v1.md | 3 +- docs/universal.md | 2 +- docs/us_healthcare_cards_v1.md | 3 +- docs/us_mail_v3.md | 3 +- docs/us_w9_v1.md | 1 - examples/auto_invoice_splitter_extraction.rb | 6 +- ...auto_multi_receipts_detector_extraction.rb | 4 +- lib/mindee/client.rb | 453 ++++++++++-------- lib/mindee/product.rb | 1 - .../barcode_reader/barcode_reader_v1.rb | 8 + .../bill_of_lading/bill_of_lading_v1.rb | 8 + .../product/business_card/business_card_v1.rb | 8 + lib/mindee/product/cropper/cropper_v1.rb | 8 + .../product/delivery_note/delivery_note_v1.rb | 8 + .../driver_license/driver_license_v1.rb | 8 + .../eu/license_plate/license_plate_v1.rb | 8 + .../financial_document_v1.rb | 8 + .../bank_account_details_v1.rb | 8 + .../bank_account_details_v2.rb | 8 + .../product/fr/carte_grise/carte_grise_v1.rb | 8 + .../product/fr/energy_bill/energy_bill_v1.rb | 8 + .../product/fr/health_card/health_card_v1.rb | 8 + lib/mindee/product/fr/id_card/id_card_v1.rb | 8 + lib/mindee/product/fr/id_card/id_card_v2.rb | 8 + lib/mindee/product/fr/payslip/payslip_v2.rb | 8 + lib/mindee/product/fr/payslip/payslip_v3.rb | 8 + .../ind/indian_passport/indian_passport_v1.rb | 8 + .../international_id/international_id_v2.rb | 8 + lib/mindee/product/invoice/invoice_v4.rb | 8 + .../invoice_splitter/invoice_splitter_v1.rb | 8 + .../multi_receipts_detector_v1.rb | 8 + .../nutrition_facts_label_v1.rb | 8 + lib/mindee/product/passport/passport_v1.rb | 8 + lib/mindee/product/receipt/receipt_v4.rb | 36 -- .../product/receipt/receipt_v4_document.rb | 86 ---- lib/mindee/product/receipt/receipt_v4_page.rb | 32 -- lib/mindee/product/receipt/receipt_v5.rb | 8 + lib/mindee/product/resume/resume_v1.rb | 8 + lib/mindee/product/universal/universal.rb | 8 + .../product/us/bank_check/bank_check_v1.rb | 8 + .../us/healthcare_card/healthcare_card_v1.rb | 8 + lib/mindee/product/us/us_mail/us_mail_v2.rb | 8 + lib/mindee/product/us/us_mail/us_mail_v3.rb | 8 + lib/mindee/product/us/w9/w9_v1.rb | 8 + spec/client_spec.rb | 12 +- spec/document/receipt_v4_spec.rb | 41 -- ...invoice_splitter_extraction_integration.rb | 4 +- spec/extras/extras_integration.rb | 7 +- spec/http/error_handler_spec.rb | 2 +- spec/workflow/workflow_integration.rb | 4 +- 115 files changed, 844 insertions(+), 600 deletions(-) rename docs/code_samples/{bank_statement_fr_v1_async.txt => bill_of_lading_v1.txt} (80%) create mode 100644 docs/code_samples/business_card_v1.txt create mode 100644 docs/code_samples/delivery_notes_v1.txt create mode 100644 docs/code_samples/driver_license_v1.txt create mode 100644 docs/code_samples/energy_bill_fra_v1.txt create mode 100644 docs/code_samples/french_healthcard_v1.txt create mode 100644 docs/code_samples/ind_passport_v1.txt create mode 100644 docs/code_samples/international_id_v2.txt create mode 100644 docs/code_samples/nutrition_facts_v1.txt create mode 100644 docs/code_samples/payslip_fra_v2.txt create mode 100644 docs/code_samples/payslip_fra_v3.txt rename docs/code_samples/{expense_receipts_v4.txt => resume_v1.txt} (91%) create mode 100644 docs/code_samples/us_healthcare_cards_v1.txt create mode 100644 docs/code_samples/us_mail_v2.txt create mode 100644 docs/code_samples/us_mail_v3.txt delete mode 100644 docs/code_samples/workflow_execution.txt delete mode 100644 lib/mindee/product/receipt/receipt_v4.rb delete mode 100644 lib/mindee/product/receipt/receipt_v4_document.rb delete mode 100644 lib/mindee/product/receipt/receipt_v4_page.rb delete mode 100644 spec/document/receipt_v4_spec.rb diff --git a/README.md b/README.md index 40c9ab4d..a0295c7e 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,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,8 +108,8 @@ 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 @@ -133,7 +133,7 @@ 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::Universal::Universal, endpoint: endpoint diff --git a/bin/mindee.rb b/bin/mindee.rb index c2dd52d7..2240b5c2 100755 --- a/bin/mindee.rb +++ b/bin/mindee.rb @@ -5,7 +5,6 @@ require 'optparse' require 'mindee' -options = {} DOCUMENTS = { "universal" => { description: "Universal document type from API builder", @@ -219,7 +218,7 @@ def custom_subcommand(cli_parser, options) custom_endpoint = nil end -page_options = options[:cut_pages].nil? ? nil : default_cutting +page_options = options[:cut_pages].nil? ? nil : :default_cutting if options[:parse_async].nil? if !DOCUMENTS[command][:sync] options[:parse_async] = true @@ -227,21 +226,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, + page_options: page_options, enqueue: options[:parse_async] } +) if options[:print_full] puts result.document diff --git a/docs/bank_account_details_v2.md b/docs/bank_account_details_v2.md index 69540f72..7497034b 100644 --- a/docs/bank_account_details_v2.md +++ b/docs/bank_account_details_v2.md @@ -30,7 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/bank_check_v1.md b/docs/bank_check_v1.md index e8cb950c..4c3854c1 100644 --- a/docs/bank_check_v1.md +++ b/docs/bank_check_v1.md @@ -30,7 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/bank_statement_fr_v1.md b/docs/bank_statement_fr_v1.md index 7046e8fb..0344d488 100644 --- a/docs/bank_statement_fr_v1.md +++ b/docs/bank_statement_fr_v1.md @@ -20,7 +20,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::BankStatementV1 ) diff --git a/docs/barcode_reader_v1.md b/docs/barcode_reader_v1.md index 94777528..98ff5de7 100644 --- a/docs/barcode_reader_v1.md +++ b/docs/barcode_reader_v1.md @@ -30,7 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/bill_of_lading_v1.md b/docs/bill_of_lading_v1.md index 658434f6..ae2b02dd 100644 --- a/docs/bill_of_lading_v1.md +++ b/docs/bill_of_lading_v1.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/business_card_v1.md b/docs/business_card_v1.md index bb770835..ac5ec510 100644 --- a/docs/business_card_v1.md +++ b/docs/business_card_v1.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/carte_grise_v1.md b/docs/carte_grise_v1.md index eb4c6345..ac31ce66 100644 --- a/docs/carte_grise_v1.md +++ b/docs/carte_grise_v1.md @@ -30,7 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/code_samples/bank_statement_fr_v1_async.txt b/docs/code_samples/bill_of_lading_v1.txt similarity index 80% rename from docs/code_samples/bank_statement_fr_v1_async.txt rename to docs/code_samples/bill_of_lading_v1.txt index 58f4026d..e626c77c 100644 --- a/docs/code_samples/bank_statement_fr_v1_async.txt +++ b/docs/code_samples/bill_of_lading_v1.txt @@ -7,9 +7,9 @@ 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::BankStatementV1 + Mindee::Product::BillOfLading::BillOfLadingV1 ) # Print a full summary of the parsed data in RST format diff --git a/docs/code_samples/bill_of_lading_v1_async.txt b/docs/code_samples/bill_of_lading_v1_async.txt index 1bfba1a8..e626c77c 100644 --- a/docs/code_samples/bill_of_lading_v1_async.txt +++ b/docs/code_samples/bill_of_lading_v1_async.txt @@ -7,7 +7,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..ae200eac --- /dev/null +++ b/docs/code_samples/business_card_v1.txt @@ -0,0 +1,19 @@ +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..ae200eac 100644 --- a/docs/code_samples/business_card_v1_async.txt +++ b/docs/code_samples/business_card_v1_async.txt @@ -7,7 +7,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/default.txt b/docs/code_samples/default.txt index 18231fbd..5ddcf176 100644 --- a/docs/code_samples/default.txt +++ b/docs/code_samples/default.txt @@ -17,7 +17,8 @@ custom_endpoint = mindee_client.create_endpoint( result = mindee_client.parse( input_source, Mindee::Product::Universal::Universal, - endpoint: custom_endpoint + 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 a9dc6132..230cfc95 100644 --- a/docs/code_samples/default_async.txt +++ b/docs/code_samples/default_async.txt @@ -14,7 +14,7 @@ custom_endpoint = mindee_client.create_endpoint( ) # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, 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..8ba9cf72 --- /dev/null +++ b/docs/code_samples/delivery_notes_v1.txt @@ -0,0 +1,19 @@ +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..8ba9cf72 100644 --- a/docs/code_samples/delivery_notes_v1_async.txt +++ b/docs/code_samples/delivery_notes_v1_async.txt @@ -7,7 +7,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..feafd685 --- /dev/null +++ b/docs/code_samples/driver_license_v1.txt @@ -0,0 +1,19 @@ +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..feafd685 100644 --- a/docs/code_samples/driver_license_v1_async.txt +++ b/docs/code_samples/driver_license_v1_async.txt @@ -7,7 +7,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..01cda8d4 --- /dev/null +++ b/docs/code_samples/energy_bill_fra_v1.txt @@ -0,0 +1,19 @@ +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..01cda8d4 100644 --- a/docs/code_samples/energy_bill_fra_v1_async.txt +++ b/docs/code_samples/energy_bill_fra_v1_async.txt @@ -7,7 +7,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_async.txt b/docs/code_samples/expense_receipts_v5_async.txt index 8cfabd14..cc3d8bac 100644 --- a/docs/code_samples/expense_receipts_v5_async.txt +++ b/docs/code_samples/expense_receipts_v5_async.txt @@ -7,7 +7,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_async.txt b/docs/code_samples/financial_document_v1_async.txt index ee4cbb42..bca415af 100644 --- a/docs/code_samples/financial_document_v1_async.txt +++ b/docs/code_samples/financial_document_v1_async.txt @@ -7,7 +7,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..1d557b08 --- /dev/null +++ b/docs/code_samples/french_healthcard_v1.txt @@ -0,0 +1,19 @@ +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..1d557b08 100644 --- a/docs/code_samples/french_healthcard_v1_async.txt +++ b/docs/code_samples/french_healthcard_v1_async.txt @@ -7,7 +7,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/ind_passport_v1.txt b/docs/code_samples/ind_passport_v1.txt new file mode 100644 index 00000000..9ee52bfb --- /dev/null +++ b/docs/code_samples/ind_passport_v1.txt @@ -0,0 +1,19 @@ +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..9ee52bfb 100644 --- a/docs/code_samples/ind_passport_v1_async.txt +++ b/docs/code_samples/ind_passport_v1_async.txt @@ -7,7 +7,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..05bdbc87 --- /dev/null +++ b/docs/code_samples/international_id_v2.txt @@ -0,0 +1,19 @@ +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..05bdbc87 100644 --- a/docs/code_samples/international_id_v2_async.txt +++ b/docs/code_samples/international_id_v2_async.txt @@ -7,7 +7,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..24f697ec 100644 --- a/docs/code_samples/invoice_splitter_v1_async.txt +++ b/docs/code_samples/invoice_splitter_v1_async.txt @@ -6,7 +6,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_async.txt b/docs/code_samples/invoices_v4_async.txt index 2c681b86..1312a7c9 100644 --- a/docs/code_samples/invoices_v4_async.txt +++ b/docs/code_samples/invoices_v4_async.txt @@ -7,7 +7,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/nutrition_facts_v1.txt b/docs/code_samples/nutrition_facts_v1.txt new file mode 100644 index 00000000..d497e1b3 --- /dev/null +++ b/docs/code_samples/nutrition_facts_v1.txt @@ -0,0 +1,19 @@ +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..d497e1b3 100644 --- a/docs/code_samples/nutrition_facts_v1_async.txt +++ b/docs/code_samples/nutrition_facts_v1_async.txt @@ -7,7 +7,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/payslip_fra_v2.txt b/docs/code_samples/payslip_fra_v2.txt new file mode 100644 index 00000000..61444771 --- /dev/null +++ b/docs/code_samples/payslip_fra_v2.txt @@ -0,0 +1,19 @@ +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::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 diff --git a/docs/code_samples/payslip_fra_v2_async.txt b/docs/code_samples/payslip_fra_v2_async.txt index c82bfd63..61444771 100644 --- a/docs/code_samples/payslip_fra_v2_async.txt +++ b/docs/code_samples/payslip_fra_v2_async.txt @@ -7,7 +7,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/payslip_fra_v3.txt b/docs/code_samples/payslip_fra_v3.txt new file mode 100644 index 00000000..2c2317aa --- /dev/null +++ b/docs/code_samples/payslip_fra_v3.txt @@ -0,0 +1,19 @@ +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::Payslip::PayslipV3 +) + +# 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/payslip_fra_v3_async.txt b/docs/code_samples/payslip_fra_v3_async.txt index ab012ee1..2c2317aa 100644 --- a/docs/code_samples/payslip_fra_v3_async.txt +++ b/docs/code_samples/payslip_fra_v3_async.txt @@ -7,7 +7,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/expense_receipts_v4.txt b/docs/code_samples/resume_v1.txt similarity index 91% rename from docs/code_samples/expense_receipts_v4.txt rename to docs/code_samples/resume_v1.txt index b65a8c84..7ff22b55 100644 --- a/docs/code_samples/expense_receipts_v4.txt +++ b/docs/code_samples/resume_v1.txt @@ -9,7 +9,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::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..7ff22b55 100644 --- a/docs/code_samples/resume_v1_async.txt +++ b/docs/code_samples/resume_v1_async.txt @@ -7,7 +7,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..e5b64179 --- /dev/null +++ b/docs/code_samples/us_healthcare_cards_v1.txt @@ -0,0 +1,19 @@ +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..e5b64179 100644 --- a/docs/code_samples/us_healthcare_cards_v1_async.txt +++ b/docs/code_samples/us_healthcare_cards_v1_async.txt @@ -7,7 +7,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.txt b/docs/code_samples/us_mail_v2.txt new file mode 100644 index 00000000..908eed55 --- /dev/null +++ b/docs/code_samples/us_mail_v2.txt @@ -0,0 +1,19 @@ +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::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/us_mail_v2_async.txt b/docs/code_samples/us_mail_v2_async.txt index 94459557..908eed55 100644 --- a/docs/code_samples/us_mail_v2_async.txt +++ b/docs/code_samples/us_mail_v2_async.txt @@ -7,7 +7,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::UsMailV2 ) diff --git a/docs/code_samples/us_mail_v3.txt b/docs/code_samples/us_mail_v3.txt new file mode 100644 index 00000000..0c2a6e45 --- /dev/null +++ b/docs/code_samples/us_mail_v3.txt @@ -0,0 +1,19 @@ +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::UsMail::UsMailV3 +) + +# 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_mail_v3_async.txt b/docs/code_samples/us_mail_v3_async.txt index c6949216..0c2a6e45 100644 --- a/docs/code_samples/us_mail_v3_async.txt +++ b/docs/code_samples/us_mail_v3_async.txt @@ -7,7 +7,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/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/cropper_v1.md b/docs/cropper_v1.md index 754555a4..d8591056 100644 --- a/docs/cropper_v1.md +++ b/docs/cropper_v1.md @@ -27,7 +27,6 @@ result = mindee_client.parse( # Print a full summary of the parsed data in RST format puts result.document - ``` **Output (RST):** diff --git a/docs/delivery_notes_v1.md b/docs/delivery_notes_v1.md index 88543d25..4336a929 100644 --- a/docs/delivery_notes_v1.md +++ b/docs/delivery_notes_v1.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/driver_license_v1.md b/docs/driver_license_v1.md index 8c31e285..eeb57d20 100644 --- a/docs/driver_license_v1.md +++ b/docs/driver_license_v1.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/energy_bill_fra_v1.md b/docs/energy_bill_fra_v1.md index 71f80405..4af3c00b 100644 --- a/docs/energy_bill_fra_v1.md +++ b/docs/energy_bill_fra_v1.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/expense_receipts_v5.md b/docs/expense_receipts_v5.md index 3dc12e4d..09dc85c5 100644 --- a/docs/expense_receipts_v5.md +++ b/docs/expense_receipts_v5.md @@ -30,32 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - -``` - -You can also call this product asynchronously: - -```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::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 - ``` **Output (RST):** diff --git a/docs/financial_document_v1.md b/docs/financial_document_v1.md index 53786c2e..f7db6832 100644 --- a/docs/financial_document_v1.md +++ b/docs/financial_document_v1.md @@ -30,32 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - -``` - -You can also call this product asynchronously: - -```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::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 - ``` **Output (RST):** diff --git a/docs/french_healthcard_v1.md b/docs/french_healthcard_v1.md index a64c3e92..21a19bbd 100644 --- a/docs/french_healthcard_v1.md +++ b/docs/french_healthcard_v1.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/getting_started.md b/docs/getting_started.md index cc90f734..c5dd5603 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -183,7 +183,7 @@ Requires raw bytes. **Note**: The original filename is required when calling the method. ```ruby -raw_bytes = b"%PDF-1.3\n%\xbf\xf7\xa2\xfe\n1 0 ob..." +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") result = mindee_client.parse( @@ -196,6 +196,7 @@ result = mindee_client.parse( Requires an url as a String. **Note**: the url must start with `https://`. + ```ruby input_source = mindee_client.source_from_url("https://www.example.com/invoice.pdf") @@ -218,6 +219,7 @@ This is detailed in each document-specific guide. ### Off-the-Shelf Documents Simply setting the correct class is enough: + ```ruby result = mindee_client.parse( @@ -232,7 +234,7 @@ For custom documents, the endpoint to use must also be set, and it must take in ```ruby 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::Universal::Universal, endpoint: endpoint diff --git a/docs/idcard_fr_v2.md b/docs/idcard_fr_v2.md index b18893f7..c63f310c 100644 --- a/docs/idcard_fr_v2.md +++ b/docs/idcard_fr_v2.md @@ -30,7 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/ind_passport_v1.md b/docs/ind_passport_v1.md index 401f72d6..b505185c 100644 --- a/docs/ind_passport_v1.md +++ b/docs/ind_passport_v1.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/international_id_v2.md b/docs/international_id_v2.md index 03edbf42..b8298ddd 100644 --- a/docs/international_id_v2.md +++ b/docs/international_id_v2.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/invoice_splitter_v1.md b/docs/invoice_splitter_v1.md index e890db8f..ec0fdeb9 100644 --- a/docs/invoice_splitter_v1.md +++ b/docs/invoice_splitter_v1.md @@ -19,7 +19,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/invoices_v4.md b/docs/invoices_v4.md index c624a202..36f77a20 100644 --- a/docs/invoices_v4.md +++ b/docs/invoices_v4.md @@ -30,32 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - -``` - -You can also call this product asynchronously: - -```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::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 - ``` **Output (RST):** diff --git a/docs/license_plates_v1.md b/docs/license_plates_v1.md index eb9baf0d..7dc3c0b2 100644 --- a/docs/license_plates_v1.md +++ b/docs/license_plates_v1.md @@ -30,7 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/multi_receipts_detector_v1.md b/docs/multi_receipts_detector_v1.md index adb57c8c..7e766e35 100644 --- a/docs/multi_receipts_detector_v1.md +++ b/docs/multi_receipts_detector_v1.md @@ -30,7 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/nutrition_facts_v1.md b/docs/nutrition_facts_v1.md index 59c5a88f..9890c0a0 100644 --- a/docs/nutrition_facts_v1.md +++ b/docs/nutrition_facts_v1.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/passport_v1.md b/docs/passport_v1.md index ccee5739..795d18b7 100644 --- a/docs/passport_v1.md +++ b/docs/passport_v1.md @@ -30,7 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/payslip_fra_v2.md b/docs/payslip_fra_v2.md index a9095386..9b64c6a0 100644 --- a/docs/payslip_fra_v2.md +++ b/docs/payslip_fra_v2.md @@ -20,7 +20,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/payslip_fra_v3.md b/docs/payslip_fra_v3.md index 76827ce5..1796bab4 100644 --- a/docs/payslip_fra_v3.md +++ b/docs/payslip_fra_v3.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/resume_v1.md b/docs/resume_v1.md index 84eddf98..6ed2eebe 100644 --- a/docs/resume_v1.md +++ b/docs/resume_v1.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/universal.md b/docs/universal.md index f0211e52..adde21a3 100644 --- a/docs/universal.md +++ b/docs/universal.md @@ -26,7 +26,7 @@ custom_endpoint = mindee_client.create_endpoint( ) # Parse the file -result = mindee_client.enqueue_and_parse( +result = mindee_client.parse( input_source, Mindee::Product::Universal::Universal, endpoint: custom_endpoint diff --git a/docs/us_healthcare_cards_v1.md b/docs/us_healthcare_cards_v1.md index bde75916..770888d7 100644 --- a/docs/us_healthcare_cards_v1.md +++ b/docs/us_healthcare_cards_v1.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/us_mail_v3.md b/docs/us_mail_v3.md index 49602d9d..004ac614 100644 --- a/docs/us_mail_v3.md +++ b/docs/us_mail_v3.md @@ -20,7 +20,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 +30,6 @@ puts result.document # Print the document-level parsed data # puts result.document.inference.prediction - ``` **Output (RST):** diff --git a/docs/us_w9_v1.md b/docs/us_w9_v1.md index e2c21a74..18f060eb 100644 --- a/docs/us_w9_v1.md +++ b/docs/us_w9_v1.md @@ -27,7 +27,6 @@ result = mindee_client.parse( # Print a full summary of the parsed data in RST format puts result.document - ``` **Output (RST):** diff --git a/examples/auto_invoice_splitter_extraction.rb b/examples/auto_invoice_splitter_extraction.rb index 8955a3ff..9d5f8aa7 100644 --- a/examples/auto_invoice_splitter_extraction.rb +++ b/examples/auto_invoice_splitter_extraction.rb @@ -23,10 +23,10 @@ def parse_single_page(mindee_client, input_source) def parse_multi_page(mindee_client, input_source) pdf_extractor = Mindee::PDF::PDFExtractor::PDFExtractor.new(input_source) - invoice_splitter_response = mindee_client.enqueue_and_parse( + 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 63a5410b..6280ecde 100644 --- a/examples/auto_multi_receipts_detector_extraction.rb +++ b/examples/auto_multi_receipts_detector_extraction.rb @@ -9,7 +9,7 @@ def multi_receipts_detection(file_path, mindee_client) result_multi_receipts = mindee_client.parse( input_source, Mindee::Product::MultiReceiptsDetector::MultiReceiptsDetectorV1, - close_file: false + options: { close_file: false } ) images = Mindee::Extraction.extract_receipts(input_source, result_multi_receipts.document.inference) @@ -20,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/client.rb b/lib/mindee/client.rb index 93d572ac..3e2f5d23 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -11,6 +11,87 @@ OTS_OWNER = 'mindee' module Mindee + # Struct for configuration options in parse calls + # + # @!attribute 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. + # + # @!attribute 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. + # + # @!attribute close_file [Boolean] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # + # @!attribute 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. + # + # @!attribute cropper [Boolean] 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 [Integer, Float] initial delay before polling. Defaults to 2. + # @!attribute delay_sec [Integer, Float] delay between polling attempts. Defaults to 1.5. + # @!attribute max_retries [Integer] maximum amount of retries. Defaults to 80. + ParseOptions = Struct.new( + :all_words, + :full_text, + :close_file, + :page_options, + :cropper, + :initial_delay_sec, + :delay_sec, + :max_retries + ) do + def initialize(params = {}) + super( + params.fetch(:all_words, false), + params.fetch(:full_text, false), + params.fetch(:close_file, true), + params.fetch(:page_options, nil), + params.fetch(:cropper, false), + params.fetch(:initial_delay_sec, 2), + params.fetch(:delay_sec, 1.5), + params.fetch(:max_retries, 80) + ) + end + end + + # Struct 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 [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. + # + # @!attribute public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without + # requiring authentication. + # @!attribute 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 + WorkflowOptions = Struct.new( + :document_alias, + :priority, + :full_text, + :public_url, + :page_options + ) do + def initialize(params = {}) + super( + params.fetch(:document_alias, nil), + params.fetch(:priority, nil), + params.fetch(:full_text, false), + params.fetch(:public_url, nil), + params.fetch(:page_options, nil) + ) + end + end + # Mindee API Client. # See: https://developers.mindee.com/docs class Client @@ -19,105 +100,117 @@ 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` [Boolean] 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` [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. + # * `:close_file` [Boolean] 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` [Boolean, 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` [Integer, Float] Initial delay before polling. Defaults to 2. + # * `:delay_sec` [Integer, Float] Delay between polling attempts. Defaults to 1.5. + # * `:max_retries` [Integer] Maximum number of retries. Defaults to 80. + # @param enqueue [Boolean] 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) + 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? + 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 [Mindee::HTTP::Endpoint, nil] Endpoint of the API. + # @param options [Hash] A hash of options to configure the parsing behavior. Possible keys: + # * `: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. + # * `: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. + # * `:close_file` [Boolean] 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` [Boolean, 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, all_words, full_text, close_file, cropper) + 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 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. - # - # + # 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` [Boolean] 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` [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. + # * `:close_file` [Boolean] 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` [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] 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? - + 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, all_words, full_text, close_file, cropper) - Mindee::Parsing::Common::ApiResponse.new(product_class, - prediction, raw_http) + 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 @@ -128,85 +221,59 @@ def enqueue( # 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}") - + 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. + # 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` [Boolean] 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` [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. + # * `:close_file` [Boolean] 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` [Boolean, 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` [Integer, Float] Initial delay before polling. Defaults to 2. + # * `:delay_sec` [Integer, Float] 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 - ) - validate_async_params(initial_delay_sec, delay_sec, max_retries) - 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 - ) + 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_id = enqueue_res.job.id - sleep(initial_delay_sec) - polling_attempts = 1 + sleep(options.initial_delay_sec) + polling_attempts = 1 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 - logger.debug("Polling server for parsing result with job id: '#{job_id}. Attempt #{polling_attempts}'") - sleep(delay_sec) + while queue_res.job.status != Mindee::Parsing::Common::JobStatus::COMPLETED && + 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) polling_attempts += 1 end + if queue_res.job.status != Mindee::Parsing::Common::JobStatus::COMPLETED - elapsed = initial_delay_sec + (polling_attempts * delay_sec) + elapsed = options.initial_delay_sec + (polling_attempts * options.delay_sec) raise Errors::MindeeAPIError, "Asynchronous parsing request timed out after #{elapsed} seconds (#{polling_attempts} tries)" end @@ -214,49 +281,44 @@ def enqueue_and_parse( queue_res end - # rubocop:enable Metrics/ParameterLists - + # Same idea applies to execute_workflow: + # # Sends a document to a workflow. # + # Accepts options either as a Hash or as a WorkflowOptions struct. + # # @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 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` [Boolean] 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 + # * `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: - # - # * `: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. - # - # + # * `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) - end + def execute_workflow(input_source, workflow_id, options: {}) + opts = options.is_a?(WorkflowOptions) ? options : WorkflowOptions.new(options) + process_pdf_if_required(input_source, opts) if opts.respond_to?(:page_options) workflow_endpoint = Mindee::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key) - logger.debug("Sending document to workflow '#{workflow_id}'") - prediction, raw_http = workflow_endpoint.execute_workflow(input_source, full_text, document_alias, priority, - public_url) - Mindee::Parsing::Common::WorkflowResponse.new(Product::Universal::Universal, - prediction, raw_http) + 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. @@ -332,8 +394,6 @@ def create_endpoint(endpoint_name: '', account_name: '', 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 @@ -342,6 +402,7 @@ def validate_async_params(initial_delay_sec, delay_sec, max_retries) min_delay_sec = 1 min_initial_delay_sec = 1 min_retries = 2 + if delay_sec < min_delay_sec raise ArgumentError, "Cannot set auto-poll delay to less than #{min_delay_sec} second(s)" @@ -350,10 +411,7 @@ def validate_async_params(initial_delay_sec, delay_sec, max_retries) raise ArgumentError, "Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)" end - return unless max_retries < min_retries - - raise ArgumentError, - "Cannot set auto-poll retries to less than #{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. @@ -375,18 +433,19 @@ def initialize_endpoint(product_class, endpoint_name: '', account_name: '', vers 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) - logger.info("No account name provided, #{OTS_OWNER} will be used by default.") - 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 @@ -398,8 +457,22 @@ def fix_version(product_class, version) 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 + + def normalize_parse_options(options) + options.is_a?(ParseOptions) ? options : ParseOptions.new(options) + end + + 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/product.rb b/lib/mindee/product.rb index d8f1188a..c4a285bd 100644 --- a/lib/mindee/product.rb +++ b/lib/mindee/product.rb @@ -27,7 +27,6 @@ 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/receipt/receipt_v4' require_relative 'product/receipt/receipt_v5' require_relative 'product/resume/resume_v1' require_relative 'product/us/bank_check/bank_check_v1' diff --git a/lib/mindee/product/barcode_reader/barcode_reader_v1.rb b/lib/mindee/product/barcode_reader/barcode_reader_v1.rb index ed1d5da5..2a69c95c 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 c1902b23..25961a6d 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/business_card/business_card_v1.rb b/lib/mindee/product/business_card/business_card_v1.rb index c20eb9bd..d00b2963 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/cropper/cropper_v1.rb b/lib/mindee/product/cropper/cropper_v1.rb index 3d79ff48..73e30622 100644 --- a/lib/mindee/product/cropper/cropper_v1.rb +++ b/lib/mindee/product/cropper/cropper_v1.rb @@ -12,6 +12,8 @@ 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 33d376d9..3e1606e1 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 ec4267bd..f099e190 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 40b88b44..17b976aa 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 6f733d3f..79080fc9 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 7d9bd296..ade9cd84 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 2aa5d075..2703f4e8 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 904f0572..58ef3f67 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 be5a407f..97c33480 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 61b98fc3..ed9971e8 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 2bee92fc..1dec2c79 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end 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 fa05dea2..e3a9c1b8 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/payslip/payslip_v2.rb b/lib/mindee/product/fr/payslip/payslip_v2.rb index ff690dcc..33c3e465 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/fr/payslip/payslip_v3.rb b/lib/mindee/product/fr/payslip/payslip_v3.rb index 57f90e31..beb23f14 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 f2f330bb..762c69aa 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 e7691d66..c1afecd9 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/invoice/invoice_v4.rb b/lib/mindee/product/invoice/invoice_v4.rb index 93b6a5b9..47734e4a 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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..dd7dd79a 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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end 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 5fa22718..0de4c71c 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 05fc63f6..ae48b10c 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/passport/passport_v1.rb b/lib/mindee/product/passport/passport_v1.rb index ab3e5048..7d261844 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 9e87c8f3..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 = 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 da7cb593..554b37af 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/resume/resume_v1.rb b/lib/mindee/product/resume/resume_v1.rb index 3cfa04a3..76e58d11 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) @@ -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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/universal/universal.rb b/lib/mindee/product/universal/universal.rb index 74f51838..99d9f413 100644 --- a/lib/mindee/product/universal/universal.rb +++ b/lib/mindee/product/universal/universal.rb @@ -11,6 +11,8 @@ module Universal class Universal < Mindee::Parsing::Common::Inference @endpoint_name = '' @endpoint_version = '' + @has_sync = true + @has_async = true # @param prediction [Hash] def initialize(prediction) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end 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 826b5593..f6e1a05d 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 e5be13ce..1f899538 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 index d508d238..0fad49b0 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v2.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v2.rb @@ -13,6 +13,8 @@ module UsMail class UsMailV2 < Mindee::Parsing::Common::Inference @endpoint_name = 'us_mail' @endpoint_version = '2' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync 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 3eed3521..9d9b10da 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end diff --git a/lib/mindee/product/us/w9/w9_v1.rb b/lib/mindee/product/us/w9/w9_v1.rb index 55822542..d479cd18 100644 --- a/lib/mindee/product/us/w9/w9_v1.rb +++ b/lib/mindee/product/us/w9/w9_v1.rb @@ -13,6 +13,8 @@ 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) @@ -31,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 [Boolean] + attr_reader :has_async + # Whether this product has access to synchronous endpoint. + # @return [Boolean] + attr_reader :has_sync end end end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 4c888520..1de4573c 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -75,24 +75,24 @@ 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.enqueue_and_parse( + mindee_client.parse( input_source, Mindee::Product::Invoice::InvoiceV4, - max_retries: 0 + options: { max_retries: 0 } ) end.to raise_error ArgumentError expect do - mindee_client.enqueue_and_parse( + mindee_client.parse( input_source, Mindee::Product::Invoice::InvoiceV4, - initial_delay_sec: 0.5 + options: { initial_delay_sec: 0.5 } ) end.to raise_error ArgumentError expect do - mindee_client.enqueue_and_parse( + mindee_client.parse( input_source, Mindee::Product::Invoice::InvoiceV4, - delay_sec: 0.5 + options: { delay_sec: 0.5 } ) end.to raise_error ArgumentError 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/extraction/invoice_splitter_extraction_integration.rb b/spec/extraction/invoice_splitter_extraction_integration.rb index e32b8ad0..9ad0df3d 100644 --- a/spec/extraction/invoice_splitter_extraction_integration.rb +++ b/spec/extraction/invoice_splitter_extraction_integration.rb @@ -25,8 +25,8 @@ 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 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/http/error_handler_spec.rb b/spec/http/error_handler_spec.rb index 2b2c0a3b..34a7462f 100644 --- a/spec/http/error_handler_spec.rb +++ b/spec/http/error_handler_spec.rb @@ -12,7 +12,7 @@ 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) + mindee_client1.parse(input_source, doc_class, options: { all_words: false, close_file: true }) end.to raise_error Mindee::Errors::MindeeHTTPClientError end 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) From ed8e730027eea86c543b3f5580a15a18e7e1d7b4 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:28:33 +0100 Subject: [PATCH 11/17] :memo: fix missing yard documentation + micro-refacto (#151) --- examples/auto_invoice_splitter_extraction.rb | 2 +- lib/mindee.rb | 5 ++ lib/mindee/client.rb | 17 ++++--- .../extraction/multi_receipts_extractor.rb | 2 +- lib/mindee/image/image_extractor.rb | 9 ++-- .../input/sources/local_input_source.rb | 5 +- lib/mindee/parsing/common/document.rb | 10 ++-- .../parsing/common/execution_priority.rb | 6 +++ .../parsing/common/extras/cropper_extra.rb | 1 + lib/mindee/parsing/common/extras/extras.rb | 1 + .../common/extras/full_text_ocr_extra.rb | 1 + lib/mindee/parsing/standard/base_field.rb | 2 +- lib/mindee/parsing/standard/boolean_field.rb | 1 + .../standard/company_registration_field.rb | 5 ++ lib/mindee/pdf/pdf_compressor.rb | 1 + lib/mindee/pdf/pdf_tools.rb | 51 +++++++++++++++++-- .../multi_receipts_extractor_spec.rb | 2 +- 17 files changed, 97 insertions(+), 24 deletions(-) diff --git a/examples/auto_invoice_splitter_extraction.rb b/examples/auto_invoice_splitter_extraction.rb index 9d5f8aa7..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) diff --git a/lib/mindee.rb b/lib/mindee.rb index f44c9eaa..26f2be43 100644 --- a/lib/mindee.rb +++ b/lib/mindee.rb @@ -70,12 +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 3e2f5d23..a9bc6222 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -8,6 +8,7 @@ require_relative 'parsing/common/workflow_response' require_relative 'logging' +# Default owner for products. OTS_OWNER = 'mindee' module Mindee @@ -32,8 +33,8 @@ module Mindee # # @!attribute cropper [Boolean] 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 [Integer, Float] initial delay before polling. Defaults to 2. - # @!attribute delay_sec [Integer, Float] delay between polling attempts. Defaults to 1.5. + # @!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 amount of retries. Defaults to 80. ParseOptions = Struct.new( :all_words, @@ -122,8 +123,8 @@ def initialize(api_key: '') # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. # * `:cropper` [Boolean, 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` [Integer, Float] Initial delay before polling. Defaults to 2. - # * `:delay_sec` [Integer, Float] Delay between polling attempts. Defaults to 1.5. + # * `: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 [Boolean] Whether to enqueue the file. # @return [Mindee::Parsing::Common::ApiResponse] @@ -250,8 +251,8 @@ def parse_queued(job_id, product_class, endpoint: nil) # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. # * `:cropper` [Boolean, 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` [Integer, Float] Initial delay before polling. Defaults to 2. - # * `:delay_sec` [Integer, Float] Delay between polling attempts. Defaults to 1.5. + # * `: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] @@ -395,8 +396,8 @@ def create_endpoint(endpoint_name: '', account_name: '', version: '') end # 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 diff --git a/lib/mindee/extraction/multi_receipts_extractor.rb b/lib/mindee/extraction/multi_receipts_extractor.rb index 7a4339c2..188a0fd0 100644 --- a/lib/mindee/extraction/multi_receipts_extractor.rb +++ b/lib/mindee/extraction/multi_receipts_extractor.rb @@ -16,7 +16,7 @@ def self.extract_receipts(input_source, inference) 'No possible receipts candidates found for Multi-Receipts extraction.' end - (0...input_source.count_pdf_pages).each do |page_id| + (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, diff --git a/lib/mindee/image/image_extractor.rb b/lib/mindee/image/image_extractor.rb index c7420d3f..2da07bb9 100644 --- a/lib/mindee/image/image_extractor.rb +++ b/lib/mindee/image/image_extractor.rb @@ -12,12 +12,11 @@ module Mindee 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. diff --git a/lib/mindee/input/sources/local_input_source.rb b/lib/mindee/input/sources/local_input_source.rb index 77dab457..532f3cdf 100644 --- a/lib/mindee/input/sources/local_input_source.rb +++ b/lib/mindee/input/sources/local_input_source.rb @@ -102,7 +102,10 @@ def read_contents(close: true) ['document', data, { filename: Mindee::Input::Source.convert_to_unicode_escape(@filename) }] end - def count_pdf_pages + # 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) diff --git a/lib/mindee/parsing/common/document.rb b/lib/mindee/parsing/common/document.rb index a5d09fad..fd4a6714 100644 --- a/lib/mindee/parsing/common/document.rb +++ b/lib/mindee/parsing/common/document.rb @@ -21,7 +21,8 @@ class Document # @return [Integer] Amount of pages of the document attr_reader :n_pages - # @param http_response [Hash] + # 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) @@ -30,7 +31,10 @@ def self.load_ocr(http_response) 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? @@ -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 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..3183858c 100644 --- a/lib/mindee/parsing/common/extras/cropper_extra.rb +++ b/lib/mindee/parsing/common/extras/cropper_extra.rb @@ -19,6 +19,7 @@ def initialize(raw_prediction, page_id = nil) 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..3d9c5791 100644 --- a/lib/mindee/parsing/common/extras/extras.rb +++ b/lib/mindee/parsing/common/extras/extras.rb @@ -23,6 +23,7 @@ def initialize(raw_prediction) end end + # @return [String] def to_s out_str = String.new instance_variables.each do |var| 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/standard/base_field.rb b/lib/mindee/parsing/standard/base_field.rb index f1c58034..20d6ddb4 100644 --- a/lib/mindee/parsing/standard/base_field.rb +++ b/lib/mindee/parsing/standard/base_field.rb @@ -8,7 +8,7 @@ module Parsing module Standard # Base field object. class BaseField < AbstractField - # @return [String, Float, Integer, Boolean] + # @return [String, Numeric, Boolean] attr_reader :value # true if the field was reconstructed or computed using other fields. # @return [Boolean] diff --git a/lib/mindee/parsing/standard/boolean_field.rb b/lib/mindee/parsing/standard/boolean_field.rb index c68affb1..1036515c 100644 --- a/lib/mindee/parsing/standard/boolean_field.rb +++ b/lib/mindee/parsing/standard/boolean_field.rb @@ -15,6 +15,7 @@ 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/company_registration_field.rb b/lib/mindee/parsing/standard/company_registration_field.rb index 21e1fc2d..3a7f058d 100644 --- a/lib/mindee/parsing/standard/company_registration_field.rb +++ b/lib/mindee/parsing/standard/company_registration_field.rb @@ -16,16 +16,21 @@ def initialize(prediction, page_id, reconstructed: false) @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/pdf/pdf_compressor.rb b/lib/mindee/pdf/pdf_compressor.rb index dada7d61..7ab9c3d8 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 diff --git a/lib/mindee/pdf/pdf_tools.rb b/lib/mindee/pdf/pdf_tools.rb index 8aac547d..fab967f1 100644 --- a/lib/mindee/pdf/pdf_tools.rb +++ b/lib/mindee/pdf/pdf_tools.rb @@ -2,9 +2,17 @@ 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 [Boolean] (default: true) Whether to convert a linearized PDF to its full form. + # - :recompile [Boolean] (default: true) Whether to recompile the PDF after processing. + # - :decrypt [Boolean] (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, @@ -43,7 +51,7 @@ 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 + # @param [StringIO] pdf_data Abinary-encoded stream representing the PDF file. # @return [Boolean] True if the pdf has source text, false otherwise. def self.source_text?(pdf_data) begin @@ -70,11 +78,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 +102,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 +115,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 +128,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/spec/extraction/multi_receipts_extractor_spec.rb b/spec/extraction/multi_receipts_extractor_spec.rb index abffe667..b2da5094 100644 --- a/spec/extraction/multi_receipts_extractor_spec.rb +++ b/spec/extraction/multi_receipts_extractor_spec.rb @@ -15,7 +15,7 @@ end let(:empty_input_source) do - double('InputSource', count_pdf_pages: 0) + double('InputSource', count_pages: 0) end let(:multi_receipts_single_page_path) do File.join(DATA_DIR, 'products', 'multi_receipts_detector', 'default_sample.jpg') From 979e079a15a24dd48efe33656e25993733949096 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 12 Feb 2025 18:08:34 +0100 Subject: [PATCH 12/17] :sparkles: add support for typing through RBS (#152) --- .github/workflows/_test-code-samples.yml | 1 + .rubocop.yml | 1 + Steepfile | 46 ++++ docs/code_samples/us_mail_v2.txt | 19 -- docs/code_samples/us_mail_v2_async.txt | 19 -- lib/mindee/client.rb | 210 ++++++++++-------- lib/mindee/geometry/polygon.rb | 2 +- lib/mindee/http.rb | 2 +- lib/mindee/http/endpoint.rb | 57 ++--- ...error_handler.rb => http_error_handler.rb} | 0 lib/mindee/http/response_validation.rb | 4 +- lib/mindee/http/workflow_endpoint.rb | 10 +- lib/mindee/image/extracted_image.rb | 2 +- lib/mindee/image/image_extractor.rb | 2 +- lib/mindee/input/local_response.rb | 2 +- .../input/sources/base64_input_source.rb | 4 +- .../input/sources/bytes_input_source.rb | 2 +- lib/mindee/input/sources/file_input_source.rb | 2 +- .../input/sources/local_input_source.rb | 14 +- lib/mindee/input/sources/path_input_source.rb | 2 +- lib/mindee/parsing/common/document.rb | 4 +- lib/mindee/parsing/common/execution.rb | 4 +- .../parsing/common/extras/cropper_extra.rb | 2 +- lib/mindee/parsing/common/extras/extras.rb | 12 +- lib/mindee/parsing/common/inference.rb | 21 +- lib/mindee/parsing/common/ocr/mvision_v1.rb | 2 +- lib/mindee/parsing/common/ocr/ocr.rb | 14 +- lib/mindee/parsing/common/page.rb | 6 +- lib/mindee/parsing/common/prediction.rb | 2 + .../parsing/common/workflow_response.rb | 2 +- lib/mindee/parsing/standard/base_field.rb | 8 +- lib/mindee/parsing/standard/boolean_field.rb | 4 +- .../standard/company_registration_field.rb | 2 +- lib/mindee/parsing/standard/date_field.rb | 2 +- lib/mindee/parsing/standard/feature_field.rb | 4 +- .../parsing/standard/payment_details_field.rb | 2 +- lib/mindee/parsing/standard/position_field.rb | 4 +- lib/mindee/parsing/standard/string_field.rb | 2 +- .../parsing/universal/universal_list_field.rb | 6 +- .../universal/universal_object_field.rb | 11 +- lib/mindee/pdf/extracted_pdf.rb | 4 +- lib/mindee/pdf/pdf_compressor.rb | 8 +- lib/mindee/pdf/pdf_extractor.rb | 6 +- lib/mindee/pdf/pdf_processor.rb | 4 +- lib/mindee/pdf/pdf_tools.rb | 13 +- lib/mindee/product.rb | 3 +- .../barcode_reader/barcode_reader_v1.rb | 4 +- .../barcode_reader_v1_document.rb | 6 +- .../bill_of_lading/bill_of_lading_v1.rb | 4 +- .../bill_of_lading_v1_document.rb | 4 +- .../product/business_card/business_card_v1.rb | 4 +- .../business_card_v1_document.rb | 4 +- lib/mindee/product/cropper/cropper_v1.rb | 4 +- .../product/delivery_note/delivery_note_v1.rb | 4 +- .../delivery_note_v1_document.rb | 2 +- .../driver_license/driver_license_v1.rb | 4 +- .../driver_license_v1_document.rb | 2 +- .../eu/license_plate/license_plate_v1.rb | 4 +- .../license_plate_v1_document.rb | 4 +- .../financial_document_v1.rb | 4 +- .../financial_document_v1_document.rb | 12 +- .../bank_account_details_v1.rb | 4 +- .../bank_account_details_v1_document.rb | 2 +- .../bank_account_details_v2.rb | 4 +- .../bank_account_details_v2_document.rb | 2 +- .../product/fr/carte_grise/carte_grise_v1.rb | 4 +- .../fr/carte_grise/carte_grise_v1_document.rb | 2 +- .../product/fr/energy_bill/energy_bill_v1.rb | 4 +- .../fr/energy_bill/energy_bill_v1_document.rb | 8 +- .../product/fr/health_card/health_card_v1.rb | 4 +- .../fr/health_card/health_card_v1_document.rb | 4 +- lib/mindee/product/fr/id_card/id_card_v1.rb | 4 +- .../product/fr/id_card/id_card_v1_document.rb | 4 +- lib/mindee/product/fr/id_card/id_card_v2.rb | 4 +- .../product/fr/id_card/id_card_v2_document.rb | 4 +- lib/mindee/product/fr/payslip/payslip_v2.rb | 4 +- .../product/fr/payslip/payslip_v2_document.rb | 4 +- lib/mindee/product/fr/payslip/payslip_v3.rb | 4 +- .../product/fr/payslip/payslip_v3_document.rb | 6 +- .../ind/indian_passport/indian_passport_v1.rb | 4 +- .../indian_passport_v1_document.rb | 2 +- .../international_id/international_id_v2.rb | 4 +- .../international_id_v2_document.rb | 6 +- lib/mindee/product/invoice/invoice_v4.rb | 4 +- .../product/invoice/invoice_v4_document.rb | 12 +- .../invoice_splitter/invoice_splitter_v1.rb | 4 +- .../invoice_splitter_v1_document.rb | 4 +- .../multi_receipts_detector_v1.rb | 4 +- .../multi_receipts_detector_v1_document.rb | 8 +- .../nutrition_facts_label_v1.rb | 4 +- .../nutrition_facts_label_v1_document.rb | 4 +- lib/mindee/product/passport/passport_v1.rb | 4 +- .../product/passport/passport_v1_document.rb | 4 +- lib/mindee/product/receipt/receipt_v5.rb | 4 +- .../product/receipt/receipt_v5_document.rb | 6 +- lib/mindee/product/resume/resume_v1.rb | 4 +- .../product/resume/resume_v1_document.rb | 20 +- lib/mindee/product/universal/universal.rb | 6 +- .../product/universal/universal_document.rb | 7 +- .../product/universal/universal_page.rb | 8 +- .../product/universal/universal_prediction.rb | 25 ++- .../product/us/bank_check/bank_check_v1.rb | 4 +- .../us/bank_check/bank_check_v1_document.rb | 4 +- .../us/healthcare_card/healthcare_card_v1.rb | 4 +- .../healthcare_card_v1_document.rb | 6 +- lib/mindee/product/us/us_mail/us_mail_v2.rb | 47 ---- .../product/us/us_mail/us_mail_v2_document.rb | 100 --------- .../product/us/us_mail/us_mail_v2_page.rb | 38 ---- .../us_mail/us_mail_v2_recipient_address.rb | 105 --------- .../us/us_mail/us_mail_v2_sender_address.rb | 66 ------ lib/mindee/product/us/us_mail/us_mail_v3.rb | 4 +- .../product/us/us_mail/us_mail_v3_document.rb | 6 +- .../us_mail/us_mail_v3_recipient_address.rb | 2 +- lib/mindee/product/us/w9/w9_v1.rb | 4 +- lib/mindee/version.rb | 2 +- mindee.gemspec | 15 +- sig/custom/mini_magick.rbs | 12 + sig/custom/net_http.rbs | 26 +++ sig/custom/origami.rbs | 49 ++++ sig/mindee.rbs | 59 +++++ sig/mindee/client.rbs | 112 ++++++++++ sig/mindee/errors/mindee_error.rbs | 13 ++ sig/mindee/errors/mindee_http_error.rbs | 16 ++ sig/mindee/errors/mindee_input_error.rbs | 17 ++ .../extraction/multi_receipts_extractor.rbs | 6 + sig/mindee/geometry/min_max.rbs | 10 + sig/mindee/geometry/point.rbs | 13 ++ sig/mindee/geometry/polygon.rbs | 9 + sig/mindee/geometry/quadrilateral.rbs | 18 ++ sig/mindee/geometry/utils.rbs | 13 ++ sig/mindee/http/endpoint.rbs | 26 +++ sig/mindee/http/http_error_handler.rbs | 10 + sig/mindee/http/response_validation.rbs | 10 + sig/mindee/http/workflow_endpoint.rbs | 14 ++ sig/mindee/image/extracted_image.rbs | 15 ++ sig/mindee/image/image_compressor.rbs | 8 + sig/mindee/image/image_extractor.rbs | 13 ++ sig/mindee/image/image_utils.rbs | 19 ++ sig/mindee/input/local_response.rbs | 13 ++ .../input/sources/base64_input_source.rbs | 11 + .../input/sources/bytes_input_source.rbs | 10 + .../input/sources/file_input_source.rbs | 10 + .../input/sources/local_input_source.rbs | 22 ++ .../input/sources/path_input_source.rbs | 10 + sig/mindee/input/sources/url_input_source.rbs | 19 ++ sig/mindee/logging/logger.rbs | 9 + sig/mindee/parsing/common/api_request.rbs | 15 ++ sig/mindee/parsing/common/api_response.rbs | 27 +++ sig/mindee/parsing/common/document.rbs | 20 ++ sig/mindee/parsing/common/execution.rbs | 23 ++ sig/mindee/parsing/common/execution_file.rbs | 12 + .../parsing/common/execution_priority.rbs | 13 ++ .../parsing/common/extras/cropper_extra.rbs | 14 ++ sig/mindee/parsing/common/extras/extras.rbs | 18 ++ .../common/extras/full_text_ocr_extra.rbs | 15 ++ sig/mindee/parsing/common/inference.rbs | 19 ++ sig/mindee/parsing/common/job.rbs | 16 ++ sig/mindee/parsing/common/ocr/mvision_v1.rbs | 15 ++ sig/mindee/parsing/common/ocr/ocr.rbs | 39 ++++ sig/mindee/parsing/common/orientation.rbs | 12 + sig/mindee/parsing/common/page.rbs | 15 ++ sig/mindee/parsing/common/prediction.rbs | 11 + sig/mindee/parsing/common/product.rbs | 13 ++ .../parsing/common/workflow_response.rbs | 13 ++ .../parsing/standard/abstract_field.rbs | 19 ++ sig/mindee/parsing/standard/amount_field.rbs | 12 + sig/mindee/parsing/standard/base_field.rbs | 12 + sig/mindee/parsing/standard/boolean_field.rbs | 12 + .../parsing/standard/classification_field.rbs | 10 + .../standard/company_registration_field.rbs | 14 ++ sig/mindee/parsing/standard/date_field.rbs | 14 ++ sig/mindee/parsing/standard/feature_field.rbs | 10 + sig/mindee/parsing/standard/locale_field.rbs | 16 ++ .../standard/payment_details_field.rbs | 15 ++ .../parsing/standard/position_field.rbs | 17 ++ sig/mindee/parsing/standard/string_field.rbs | 12 + sig/mindee/parsing/standard/tax_field.rbs | 23 ++ .../universal/universal_list_field.rbs | 18 ++ .../universal/universal_object_field.rbs | 23 ++ sig/mindee/pdf/extracted_pdf.rbs | 15 ++ sig/mindee/pdf/pdf_compressor.rbs | 15 ++ sig/mindee/pdf/pdf_extractor.rbs | 16 ++ sig/mindee/pdf/pdf_processor.rbs | 13 ++ sig/mindee/pdf/pdf_tools.rbs | 23 ++ .../invoice_splitter/invoice_splitter_v1.rbs | 14 ++ .../invoice_splitter_v1_document.rbs | 19 ++ .../invoice_splitter_v1_page.rbs | 13 ++ .../multi_receipts_detector_v1.rbs | 14 ++ .../multi_receipts_detector_v1_document.rbs | 12 + .../multi_receipts_detector_v1_page.rbs | 13 ++ sig/mindee/product/universal/universal.rbs | 14 ++ .../product/universal/universal_document.rbs | 10 + .../product/universal/universal_page.rbs | 14 ++ .../universal/universal_prediction.rbs | 19 ++ sig/mindee/version.rbs | 6 + spec/document/us/us_mail_v2_spec.rb | 32 --- spec/pdf/extracted_pdf_spec.rb | 2 +- spec/pdf/pdf_processor_spec.rb | 16 +- 198 files changed, 1846 insertions(+), 809 deletions(-) create mode 100644 Steepfile delete mode 100644 docs/code_samples/us_mail_v2.txt delete mode 100644 docs/code_samples/us_mail_v2_async.txt rename lib/mindee/http/{error_handler.rb => http_error_handler.rb} (100%) delete mode 100644 lib/mindee/product/us/us_mail/us_mail_v2.rb delete mode 100644 lib/mindee/product/us/us_mail/us_mail_v2_document.rb delete mode 100644 lib/mindee/product/us/us_mail/us_mail_v2_page.rb delete mode 100644 lib/mindee/product/us/us_mail/us_mail_v2_recipient_address.rb delete mode 100644 lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb create mode 100644 sig/custom/mini_magick.rbs create mode 100644 sig/custom/net_http.rbs create mode 100644 sig/custom/origami.rbs create mode 100644 sig/mindee.rbs create mode 100644 sig/mindee/client.rbs create mode 100644 sig/mindee/errors/mindee_error.rbs create mode 100644 sig/mindee/errors/mindee_http_error.rbs create mode 100644 sig/mindee/errors/mindee_input_error.rbs create mode 100644 sig/mindee/extraction/multi_receipts_extractor.rbs create mode 100644 sig/mindee/geometry/min_max.rbs create mode 100644 sig/mindee/geometry/point.rbs create mode 100644 sig/mindee/geometry/polygon.rbs create mode 100644 sig/mindee/geometry/quadrilateral.rbs create mode 100644 sig/mindee/geometry/utils.rbs create mode 100644 sig/mindee/http/endpoint.rbs create mode 100644 sig/mindee/http/http_error_handler.rbs create mode 100644 sig/mindee/http/response_validation.rbs create mode 100644 sig/mindee/http/workflow_endpoint.rbs create mode 100644 sig/mindee/image/extracted_image.rbs create mode 100644 sig/mindee/image/image_compressor.rbs create mode 100644 sig/mindee/image/image_extractor.rbs create mode 100644 sig/mindee/image/image_utils.rbs create mode 100644 sig/mindee/input/local_response.rbs create mode 100644 sig/mindee/input/sources/base64_input_source.rbs create mode 100644 sig/mindee/input/sources/bytes_input_source.rbs create mode 100644 sig/mindee/input/sources/file_input_source.rbs create mode 100644 sig/mindee/input/sources/local_input_source.rbs create mode 100644 sig/mindee/input/sources/path_input_source.rbs create mode 100644 sig/mindee/input/sources/url_input_source.rbs create mode 100644 sig/mindee/logging/logger.rbs create mode 100644 sig/mindee/parsing/common/api_request.rbs create mode 100644 sig/mindee/parsing/common/api_response.rbs create mode 100644 sig/mindee/parsing/common/document.rbs create mode 100644 sig/mindee/parsing/common/execution.rbs create mode 100644 sig/mindee/parsing/common/execution_file.rbs create mode 100644 sig/mindee/parsing/common/execution_priority.rbs create mode 100644 sig/mindee/parsing/common/extras/cropper_extra.rbs create mode 100644 sig/mindee/parsing/common/extras/extras.rbs create mode 100644 sig/mindee/parsing/common/extras/full_text_ocr_extra.rbs create mode 100644 sig/mindee/parsing/common/inference.rbs create mode 100644 sig/mindee/parsing/common/job.rbs create mode 100644 sig/mindee/parsing/common/ocr/mvision_v1.rbs create mode 100644 sig/mindee/parsing/common/ocr/ocr.rbs create mode 100644 sig/mindee/parsing/common/orientation.rbs create mode 100644 sig/mindee/parsing/common/page.rbs create mode 100644 sig/mindee/parsing/common/prediction.rbs create mode 100644 sig/mindee/parsing/common/product.rbs create mode 100644 sig/mindee/parsing/common/workflow_response.rbs create mode 100644 sig/mindee/parsing/standard/abstract_field.rbs create mode 100644 sig/mindee/parsing/standard/amount_field.rbs create mode 100644 sig/mindee/parsing/standard/base_field.rbs create mode 100644 sig/mindee/parsing/standard/boolean_field.rbs create mode 100644 sig/mindee/parsing/standard/classification_field.rbs create mode 100644 sig/mindee/parsing/standard/company_registration_field.rbs create mode 100644 sig/mindee/parsing/standard/date_field.rbs create mode 100644 sig/mindee/parsing/standard/feature_field.rbs create mode 100644 sig/mindee/parsing/standard/locale_field.rbs create mode 100644 sig/mindee/parsing/standard/payment_details_field.rbs create mode 100644 sig/mindee/parsing/standard/position_field.rbs create mode 100644 sig/mindee/parsing/standard/string_field.rbs create mode 100644 sig/mindee/parsing/standard/tax_field.rbs create mode 100644 sig/mindee/parsing/universal/universal_list_field.rbs create mode 100644 sig/mindee/parsing/universal/universal_object_field.rbs create mode 100644 sig/mindee/pdf/extracted_pdf.rbs create mode 100644 sig/mindee/pdf/pdf_compressor.rbs create mode 100644 sig/mindee/pdf/pdf_extractor.rbs create mode 100644 sig/mindee/pdf/pdf_processor.rbs create mode 100644 sig/mindee/pdf/pdf_tools.rbs create mode 100644 sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs create mode 100644 sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs create mode 100644 sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs create mode 100644 sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rbs create mode 100644 sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rbs create mode 100644 sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rbs create mode 100644 sig/mindee/product/universal/universal.rbs create mode 100644 sig/mindee/product/universal/universal_document.rbs create mode 100644 sig/mindee/product/universal/universal_page.rbs create mode 100644 sig/mindee/product/universal/universal_prediction.rbs create mode 100644 sig/mindee/version.rbs delete mode 100644 spec/document/us/us_mail_v2_spec.rb diff --git a/.github/workflows/_test-code-samples.yml b/.github/workflows/_test-code-samples.yml index 87bd4b87..bbd5e8ce 100644 --- a/.github/workflows/_test-code-samples.yml +++ b/.github/workflows/_test-code-samples.yml @@ -15,6 +15,7 @@ jobs: - "3.1" - "3.2" - "3.3" + - "3.4" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.rubocop.yml b/.rubocop.yml index 08564255..1d5a8466 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,6 +8,7 @@ AllCops: - 'bin/*' - _test.rb - local_test/* + - Steepfile TargetRubyVersion: 3.0 SuggestExtensions: false diff --git a/Steepfile b/Steepfile new file mode 100644 index 00000000..0ab6a478 --- /dev/null +++ b/Steepfile @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +D = Steep::Diagnostic + +target :lib do + signature 'sig/custom/*.rbs' + signature 'sig/mindee/*.rbs' + signature 'sig/mindee/http/*.rbs' + signature 'sig/mindee/geometry/*.rbs' + signature 'sig/mindee/errors/*.rbs' + signature 'sig/mindee/extraction/*.rbs' + signature 'sig/mindee/image/**/*.rbs' + signature 'sig/mindee/logging/**/*.rbs' + signature 'sig/mindee/parsing/**/*.rbs' + signature 'sig/mindee/pdf/**/*.rbs' + signature 'sig/mindee/product/invoice_splitter/*.rbs' + signature 'sig/mindee/product/multi_receipts_detector/*.rbs' + signature 'sig/mindee/product/universal/*.rbs' + signature 'sig/mindee/input/**/*.rbs' + + check 'lib/mindee/*.rb' + check 'lib/mindee/http/*.rb' + check 'lib/mindee/geometry/*.rb' + check 'lib/mindee/errors/*.rb' + check 'lib/mindee/extraction/*.rb' + check 'lib/mindee/image/**/*.rb' + check 'lib/mindee/logging/**/*.rb' + check 'lib/mindee/parsing/**/*.rb' + check 'lib/mindee/pdf/**/*.rb' + check 'lib/mindee/product/invoice_splitter/*.rb' + check 'lib/mindee/product/multi_receipts_detector/*.rb' + check 'lib/mindee/product/universal/*.rb' + check 'lib/mindee/input/**/*.rbs' + # check 'bin' # CLI files are ignored + library 'date' + library 'logger' + library 'json' + # library 'net/http' # NOTE: Steep does not support net/http. Do NOT enable. + # Use the stub located at sig/custom/net_http.rbs instead. + library 'pathname' + library 'time' + library 'uri' + + configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default) +end + diff --git a/docs/code_samples/us_mail_v2.txt b/docs/code_samples/us_mail_v2.txt deleted file mode 100644 index 908eed55..00000000 --- a/docs/code_samples/us_mail_v2.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.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/us_mail_v2_async.txt b/docs/code_samples/us_mail_v2_async.txt deleted file mode 100644 index 908eed55..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.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/lib/mindee/client.rb b/lib/mindee/client.rb index a9bc6222..e38376da 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -12,84 +12,89 @@ OTS_OWNER = 'mindee' module Mindee - # Struct for configuration options in parse calls + # Class for page options in parse calls. # - # @!attribute 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. - # - # @!attribute 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. - # - # @!attribute close_file [Boolean] Whether to `close()` the file after parsing it. - # Set to false if you need to access the file after this operation. - # - # @!attribute 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. - # - # @!attribute cropper [Boolean] 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 amount of retries. Defaults to 80. - ParseOptions = Struct.new( - :all_words, - :full_text, - :close_file, - :page_options, - :cropper, - :initial_delay_sec, - :delay_sec, - :max_retries - ) do - def initialize(params = {}) - super( - params.fetch(:all_words, false), - params.fetch(:full_text, false), - params.fetch(:close_file, true), - params.fetch(:page_options, nil), - params.fetch(:cropper, false), - params.fetch(:initial_delay_sec, 2), - params.fetch(:delay_sec, 1.5), - params.fetch(:max_retries, 80) + # @!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.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 - # Struct for configuration options in workflow executions + # 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) + @page_options = raw_page_options.is_a?(Hash) ? PageOptions.new(params: raw_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 [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. - # + # @!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 [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 - WorkflowOptions = Struct.new( - :document_alias, - :priority, - :full_text, - :public_url, - :page_options - ) do - def initialize(params = {}) - super( - params.fetch(:document_alias, nil), - params.fetch(:priority, nil), - params.fetch(:full_text, false), - params.fetch(:public_url, nil), - params.fetch(:page_options, nil) - ) + # 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) + @page_options = raw_page_options.is_a?(Hash) ? PageOptions.new(params: raw_page_options) : raw_page_options end end @@ -109,11 +114,11 @@ def initialize(api_key: '') # @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` [Boolean] Whether to extract all the words on each page. + # * `: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` [Boolean] Whether to include the full OCR text response in compatible APIs. + # * `: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` [Boolean] Whether to `close()` the file after parsing it. + # * `: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. @@ -121,16 +126,16 @@ def initialize(api_key: '') # - `: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` [Boolean, nil] Whether to include cropper results for each page. + # * `: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 [Boolean] Whether to enqueue the file. + # @param enqueue [bool] Whether to enqueue the file. # @return [Mindee::Parsing::Common::ApiResponse] def parse(input_source, product_class, endpoint: nil, options: {}, enqueue: true) opts = normalize_parse_options(options) - process_pdf_if_required(input_source, opts) + 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 @@ -146,11 +151,11 @@ def parse(input_source, product_class, endpoint: nil, options: {}, enqueue: true # @param product_class [Mindee::Inference] 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` [Boolean] Whether to extract all the words on each page. + # * `: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` [Boolean] Whether to include the full OCR text response in compatible APIs. + # * `: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` [Boolean] Whether to `close()` the file after parsing it. + # * `: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. @@ -158,7 +163,7 @@ def parse(input_source, product_class, endpoint: nil, options: {}, enqueue: true # - `: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` [Boolean, nil] Whether to include cropper results for each page. + # * `: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) @@ -183,11 +188,11 @@ def parse_sync(input_source, product_class, endpoint, options) # @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` [Boolean] Whether to extract all the words on each page. + # * `: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` [Boolean] Whether to include the full OCR text response in compatible APIs. + # * `: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` [Boolean] Whether to `close()` the file after parsing it. + # * `: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. @@ -195,7 +200,7 @@ def parse_sync(input_source, product_class, endpoint, options) # - `: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` [Boolean] Whether to include cropper results for each page. + # * `: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] @@ -237,11 +242,11 @@ def parse_queued(job_id, product_class, endpoint: nil) # @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` [Boolean] Whether to extract all the words on each page. + # * `: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` [Boolean] Whether to include the full OCR text response in compatible APIs. + # * `: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` [Boolean] Whether to `close()` the file after parsing it. + # * `: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. @@ -249,7 +254,7 @@ def parse_queued(job_id, product_class, endpoint: nil) # - `: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` [Boolean, nil] Whether to include cropper results for each page. + # * `: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. @@ -274,7 +279,7 @@ def enqueue_and_parse(input_source, product_class, endpoint, options) end if queue_res.job.status != Mindee::Parsing::Common::JobStatus::COMPLETED - elapsed = options.initial_delay_sec + (polling_attempts * options.delay_sec) + 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 @@ -293,7 +298,7 @@ def enqueue_and_parse(input_source, product_class, endpoint, options) # @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` [Boolean] Whether to include the full OCR text response in compatible APIs. + # * `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. @@ -305,8 +310,11 @@ def enqueue_and_parse(input_source, product_class, endpoint, options) # * `: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, options: {}) - opts = options.is_a?(WorkflowOptions) ? options : WorkflowOptions.new(options) - process_pdf_if_required(input_source, opts) if opts.respond_to?(:page_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) logger.debug("Sending document to workflow '#{workflow_id}'") @@ -335,7 +343,7 @@ def load_prediction(product_class, local_response) # 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 fix_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) @@ -344,7 +352,7 @@ def source_from_path(input_path, fix_pdf: false) # 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 fix_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) @@ -353,7 +361,7 @@ def source_from_bytes(input_bytes, filename, fix_pdf: false) # 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 fix_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) @@ -362,7 +370,7 @@ def source_from_b64string(base64_string, filename, fix_pdf: false) # 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 fix_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) @@ -416,7 +424,7 @@ def validate_async_params(initial_delay_sec, delay_sec, max_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. @@ -461,10 +469,18 @@ def fix_version(product_class, version) 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) - options.is_a?(ParseOptions) ? options : ParseOptions.new(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 && 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/http.rb b/lib/mindee/http.rb index 649b58cb..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_handler' +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 03255163..c43b240c 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_handler' +require_relative 'http_error_handler' require_relative '../version' require_relative 'response_validation' @@ -40,7 +40,7 @@ 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).empty? + 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 @@ -50,10 +50,10 @@ def initialize(owner, url_name, version, api_key: '') # 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 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 @@ -64,28 +64,33 @@ 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) + 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 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) + end - ResponseValidation.clean_request!(response) error = ErrorHandler.handle_error(@url_name, response) raise error end @@ -107,15 +112,15 @@ def parse_async(job_id) 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 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) @@ -141,15 +146,15 @@ def predict_req_post(input_source, all_words: false, full_text: false, close_fil 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 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) diff --git a/lib/mindee/http/error_handler.rb b/lib/mindee/http/http_error_handler.rb similarity index 100% rename from lib/mindee/http/error_handler.rb rename to lib/mindee/http/http_error_handler.rb 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 d7274322..a45978e8 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_handler' +require_relative 'http_error_handler' module Mindee module HTTP @@ -26,7 +26,7 @@ def initialize(workflow_id, api_key: '') # @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 = ErrorHandler.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 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) diff --git a/lib/mindee/image/extracted_image.rb b/lib/mindee/image/extracted_image.rb index 5c18705e..635b0c17 100644 --- a/lib/mindee/image/extracted_image.rb +++ b/lib/mindee/image/extracted_image.rb @@ -55,7 +55,7 @@ def write_to_file(output_path, file_format = nil) begin @buffer.rewind image = MiniMagick::Image.read(@buffer) - image.format file_format.downcase + image.format file_format.to_s.downcase image.write resolved_path.to_s logger.info("File saved successfully to '#{resolved_path}'") rescue StandardError diff --git a/lib/mindee/image/image_extractor.rb b/lib/mindee/image/image_extractor.rb index 2da07bb9..3a0ae198 100644 --- a/lib/mindee/image/image_extractor.rb +++ b/lib/mindee/image/image_extractor.rb @@ -109,7 +109,7 @@ def self.create_extracted_image(buffer, file_name, page_id, element_id) 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/input/local_response.rb b/lib/mindee/input/local_response.rb index fafe3fdf..64072d4d 100644 --- a/lib/mindee/input/local_response.rb +++ b/lib/mindee/input/local_response.rb @@ -63,7 +63,7 @@ def get_hmac_signature(secret_key) # @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 0499fa9d..cde908de 100644 --- a/lib/mindee/input/sources/base64_input_source.rb +++ b/lib/mindee/input/sources/base64_input_source.rb @@ -9,7 +9,7 @@ module Source class Base64InputSource < LocalInputSource # @param base64_string [String] # @param filename [String] - # @param fix_pdf [Boolean] + # @param fix_pdf [bool] def initialize(base64_string, filename, fix_pdf: false) io_stream = StringIO.new(base64_string.unpack1('m*')) io_stream.set_encoding Encoding::BINARY @@ -17,7 +17,7 @@ def initialize(base64_string, filename, fix_pdf: false) end # Overload of the same function to prevent a base64 from being re-encoded. - # @param close [Boolean] + # @param close [bool] # @return [Array] def read_contents(close: true) @io_stream.seek(0) diff --git a/lib/mindee/input/sources/bytes_input_source.rb b/lib/mindee/input/sources/bytes_input_source.rb index 601a6f12..89ce6e39 100644 --- a/lib/mindee/input/sources/bytes_input_source.rb +++ b/lib/mindee/input/sources/bytes_input_source.rb @@ -9,7 +9,7 @@ module Source class BytesInputSource < LocalInputSource # @param raw_bytes [String] # @param filename [String] - # @param fix_pdf [Boolean] + # @param fix_pdf [bool] def initialize(raw_bytes, filename, fix_pdf: false) io_stream = StringIO.new(raw_bytes) io_stream.set_encoding Encoding::BINARY diff --git a/lib/mindee/input/sources/file_input_source.rb b/lib/mindee/input/sources/file_input_source.rb index 3705fd57..a58904db 100644 --- a/lib/mindee/input/sources/file_input_source.rb +++ b/lib/mindee/input/sources/file_input_source.rb @@ -9,7 +9,7 @@ module Source class FileInputSource < LocalInputSource # @param input_file [File] # @param filename [String] - # @param fix_pdf [Boolean] + # @param fix_pdf [bool] def initialize(input_file, filename, fix_pdf: false) io_stream = input_file super(io_stream, filename, fix_pdf: fix_pdf) diff --git a/lib/mindee/input/sources/local_input_source.rb b/lib/mindee/input/sources/local_input_source.rb index 532f3cdf..006841e9 100644 --- a/lib/mindee/input/sources/local_input_source.rb +++ b/lib/mindee/input/sources/local_input_source.rb @@ -31,7 +31,7 @@ class LocalInputSource # @param io_stream [StringIO] # @param filename [String] - # @param fix_pdf [Boolean] + # @param fix_pdf [bool] def initialize(io_stream, filename, fix_pdf: false) @io_stream = io_stream @filename = filename @@ -87,11 +87,11 @@ 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 = PDFProcessor.parse(@io_stream, options) end # Reads a document. - # @param close [Boolean] + # @param close [bool] # @return [Array] def read_contents(close: true) logger.debug("Reading data from: #{@filename}") @@ -109,7 +109,7 @@ 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 @@ -117,10 +117,10 @@ def count_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? @@ -143,7 +143,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 diff --git a/lib/mindee/input/sources/path_input_source.rb b/lib/mindee/input/sources/path_input_source.rb index 18438b9a..4f5a25ba 100644 --- a/lib/mindee/input/sources/path_input_source.rb +++ b/lib/mindee/input/sources/path_input_source.rb @@ -9,7 +9,7 @@ module Source # Load a document from a path. class PathInputSource < LocalInputSource # @param filepath [String] - # @param fix_pdf [Boolean] + # @param fix_pdf [bool] def initialize(filepath, fix_pdf: false) io_stream = File.open(filepath, 'rb') super(io_stream, File.basename(filepath), fix_pdf: fix_pdf) diff --git a/lib/mindee/parsing/common/document.rb b/lib/mindee/parsing/common/document.rb index fd4a6714..0c9f6538 100644 --- a/lib/mindee/parsing/common/document.rb +++ b/lib/mindee/parsing/common/document.rb @@ -38,7 +38,7 @@ 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] @@ -73,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 a9f678bd..906505bf 100644 --- a/lib/mindee/parsing/common/execution.rb +++ b/lib/mindee/parsing/common/execution.rb @@ -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 = UniversalDocument.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/extras/cropper_extra.rb b/lib/mindee/parsing/common/extras/cropper_extra.rb index 3183858c..1e5c4976 100644 --- a/lib/mindee/parsing/common/extras/cropper_extra.rb +++ b/lib/mindee/parsing/common/extras/cropper_extra.rb @@ -13,7 +13,7 @@ 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 diff --git a/lib/mindee/parsing/common/extras/extras.rb b/lib/mindee/parsing/common/extras/extras.rb index 3d9c5791..4298880c 100644 --- a/lib/mindee/parsing/common/extras/extras.rb +++ b/lib/mindee/parsing/common/extras/extras.rb @@ -11,12 +11,16 @@ 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) @@ -38,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/inference.rb b/lib/mindee/parsing/common/inference.rb index f5469de0..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] diff --git a/lib/mindee/parsing/common/ocr/mvision_v1.rb b/lib/mindee/parsing/common/ocr/mvision_v1.rb index ff26f0cf..68844e40 100644 --- a/lib/mindee/parsing/common/ocr/mvision_v1.rb +++ b/lib/mindee/parsing/common/ocr/mvision_v1.rb @@ -12,7 +12,7 @@ class MVisionV1 # @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)) end diff --git a/lib/mindee/parsing/common/ocr/ocr.rb b/lib/mindee/parsing/common/ocr/ocr.rb index b5414d35..bff527f2 100644 --- a/lib/mindee/parsing/common/ocr/ocr.rb +++ b/lib/mindee/parsing/common/ocr/ocr.rb @@ -70,8 +70,8 @@ class OcrPage # @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)) end @@ -125,8 +125,8 @@ def parse_one(sorted_words, current, indexes, lines) # @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 } @@ -140,10 +140,10 @@ def to_lines # 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] + # @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 @@ -156,7 +156,7 @@ class Ocr # @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] diff --git a/lib/mindee/parsing/common/page.rb b/lib/mindee/parsing/common/page.rb index e2bcca0a..a3fc2ae7 100644 --- a/lib/mindee/parsing/common/page.rb +++ b/lib/mindee/parsing/common/page.rb @@ -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..4da70082 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); end end end end diff --git a/lib/mindee/parsing/common/workflow_response.rb b/lib/mindee/parsing/common/workflow_response.rb index 3b51cc82..5becd894 100644 --- a/lib/mindee/parsing/common/workflow_response.rb +++ b/lib/mindee/parsing/common/workflow_response.rb @@ -19,7 +19,7 @@ class WorkflowResponse 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::Universal::Universal + product_class ||= Mindee::Product::Universal::Universal @execution = Mindee::Parsing::Common::Execution.new(product_class, http_response['execution']) end end diff --git a/lib/mindee/parsing/standard/base_field.rb b/lib/mindee/parsing/standard/base_field.rb index 20d6ddb4..9aea71f7 100644 --- a/lib/mindee/parsing/standard/base_field.rb +++ b/lib/mindee/parsing/standard/base_field.rb @@ -7,16 +7,16 @@ module Mindee module Parsing module Standard # Base field object. - class BaseField < AbstractField - # @return [String, Numeric, Boolean] + class BaseField < Mindee::Parsing::Standard::AbstractField + # @return [String, Numeric, 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'] diff --git a/lib/mindee/parsing/standard/boolean_field.rb b/lib/mindee/parsing/standard/boolean_field.rb index 1036515c..28e368e2 100644 --- a/lib/mindee/parsing/standard/boolean_field.rb +++ b/lib/mindee/parsing/standard/boolean_field.rb @@ -7,8 +7,8 @@ module Parsing module Standard # Represents basic text information. class BooleanField < BaseField - # Value as Boolean - # @return [Boolean, nil] + # Value as bool + # @return [bool, nil] attr_reader :value def initialize(prediction, page_id = nil, reconstructed: false) diff --git a/lib/mindee/parsing/standard/company_registration_field.rb b/lib/mindee/parsing/standard/company_registration_field.rb index 3a7f058d..e08983de 100644 --- a/lib/mindee/parsing/standard/company_registration_field.rb +++ b/lib/mindee/parsing/standard/company_registration_field.rb @@ -10,7 +10,7 @@ class CompanyRegistrationField < BaseField # @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'] diff --git a/lib/mindee/parsing/standard/date_field.rb b/lib/mindee/parsing/standard/date_field.rb index 9870f111..73e0a5c7 100644 --- a/lib/mindee/parsing/standard/date_field.rb +++ b/lib/mindee/parsing/standard/date_field.rb @@ -19,7 +19,7 @@ class DateField < BaseField # @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 index 5ca8bedf..155c9e51 100644 --- a/lib/mindee/parsing/standard/feature_field.rb +++ b/lib/mindee/parsing/standard/feature_field.rb @@ -6,7 +6,7 @@ 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, Boolean, nil] + # @param in_str [String, bool, nil] # @param max_col_size [int, nil] # @return [String] def format_for_display(in_str, max_col_size = nil) @@ -16,7 +16,7 @@ def format_for_display(in_str, max_col_size = nil) return in_str.to_s if max_col_size.nil? in_str = in_str.gsub(%r{[\n\r\t]}, "\n" => '\\n', "\r" => '\\r', "\t" => '\\t') - in_str.to_s.length <= max_col_size ? in_str.to_s : "#{in_str[0..max_col_size - 4]}..." + 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 diff --git a/lib/mindee/parsing/standard/payment_details_field.rb b/lib/mindee/parsing/standard/payment_details_field.rb index 774f7011..772e50a4 100644 --- a/lib/mindee/parsing/standard/payment_details_field.rb +++ b/lib/mindee/parsing/standard/payment_details_field.rb @@ -18,7 +18,7 @@ class PaymentDetailsField < BaseField # @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 c3cf20c1..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 < BaseField + class StringField < Mindee::Parsing::Standard::BaseField # Value as String # @return [String, nil] attr_reader :value diff --git a/lib/mindee/parsing/universal/universal_list_field.rb b/lib/mindee/parsing/universal/universal_list_field.rb index b16f6a52..54837d58 100644 --- a/lib/mindee/parsing/universal/universal_list_field.rb +++ b/lib/mindee/parsing/universal/universal_list_field.rb @@ -22,17 +22,17 @@ class UniversalListField # 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 Universal.universal_object?(value) - @values.push(UniversalObjectField.new(value, page_id)) + @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/universal/universal_object_field.rb b/lib/mindee/parsing/universal/universal_object_field.rb index 5a1b3b5e..26095d47 100644 --- a/lib/mindee/parsing/universal/universal_object_field.rb +++ b/lib/mindee/parsing/universal/universal_object_field.rb @@ -16,7 +16,7 @@ class UniversalObjectField # 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 @@ -67,8 +67,8 @@ def method_missing(method_name, *_args) # 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 +82,10 @@ 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 }, + value_key: name.to_s, page_id: item_page_id + ) end def handle_default_field(name, value) diff --git a/lib/mindee/pdf/extracted_pdf.rb b/lib/mindee/pdf/extracted_pdf.rb index a8160bf1..d70f9e55 100644 --- a/lib/mindee/pdf/extracted_pdf.rb +++ b/lib/mindee/pdf/extracted_pdf.rb @@ -24,7 +24,7 @@ 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, Origami::InvalidPDFError raise Errors::MindeePDFError, 'Could not retrieve page count from Extracted PDF object.' @@ -32,7 +32,7 @@ def page_count # Writes the contents of the current PDF object to a file. # @param output_path [String] Path to write to. - # @param override [Boolean] Whether to override the destination file. + # @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?( diff --git a/lib/mindee/pdf/pdf_compressor.rb b/lib/mindee/pdf/pdf_compressor.rb index 7ab9c3d8..62ad1764 100644 --- a/lib/mindee/pdf/pdf_compressor.rb +++ b/lib/mindee/pdf/pdf_compressor.rb @@ -10,8 +10,8 @@ module PDF module PDFCompressor # Compresses each page of a provided PDF stream. Skips if force_source_text isn't set and source text is detected. # @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 @@ -44,13 +44,13 @@ 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]) + process_pdf_page(Mindee::PDF::PDFProcessor.get_page(pdf, index), 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 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) diff --git a/lib/mindee/pdf/pdf_extractor.rb b/lib/mindee/pdf/pdf_extractor.rb index 39826c49..b2937a1d 100644 --- a/lib/mindee/pdf/pdf_extractor.rb +++ b/lib/mindee/pdf/pdf_extractor.rb @@ -24,7 +24,7 @@ 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. @@ -35,7 +35,7 @@ def cut_pages(page_indexes) 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. @@ -71,7 +71,7 @@ def extract_sub_documents(page_indexes) # Extracts invoices as complete PDFs from the document. # @param page_indexes [Array, InvoiceSplitterV1PageGroup>] - # @param strict [Boolean] + # @param strict [bool] # @return [Array] def extract_invoices(page_indexes, strict: false) raise Errors::MindeePDFError, 'No indexes provided.' if page_indexes.empty? diff --git a/lib/mindee/pdf/pdf_processor.rb b/lib/mindee/pdf/pdf_processor.rb index f5cf0400..d78e6a55 100644 --- a/lib/mindee/pdf/pdf_processor.rb +++ b/lib/mindee/pdf/pdf_processor.rb @@ -7,7 +7,7 @@ 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 = { @@ -54,7 +54,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 diff --git a/lib/mindee/pdf/pdf_tools.rb b/lib/mindee/pdf/pdf_tools.rb index fab967f1..d11f745b 100644 --- a/lib/mindee/pdf/pdf_tools.rb +++ b/lib/mindee/pdf/pdf_tools.rb @@ -7,9 +7,9 @@ module PDFTools # Converts the current PDF document into a binary-encoded StringIO stream. # # @param [Hash] params Optional settings to override default processing flags. - # - :delinearize [Boolean] (default: true) Whether to convert a linearized PDF to its full form. - # - :recompile [Boolean] (default: true) Whether to recompile the PDF after processing. - # - :decrypt [Boolean] (default: false) Whether to attempt to decrypt the PDF. + # - :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. @@ -18,6 +18,7 @@ def to_io_stream(params = {}) delinearize: true, recompile: true, decrypt: false, + noindent: nil, } options.update(params) @@ -29,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] @@ -41,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? @@ -52,7 +53,7 @@ def self.stream_has_text?(stream) # Checks whether the file has source_text. Sends false if the file isn't a PDF. # @param [StringIO] pdf_data Abinary-encoded stream representing the PDF file. - # @return [Boolean] True if the pdf has source text, false otherwise. + # @return [bool] True if the pdf has source text, false otherwise. def self.source_text?(pdf_data) begin pdf_data.rewind diff --git a/lib/mindee/product.rb b/lib/mindee/product.rb index c4a285bd..1148ab56 100644 --- a/lib/mindee/product.rb +++ b/lib/mindee/product.rb @@ -19,7 +19,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/universal/universal' require_relative 'product/ind/indian_passport/indian_passport_v1' require_relative 'product/invoice/invoice_v4' require_relative 'product/invoice_splitter/invoice_splitter_v1' @@ -29,8 +28,8 @@ require_relative 'product/passport/passport_v1' 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/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/barcode_reader/barcode_reader_v1.rb b/lib/mindee/product/barcode_reader/barcode_reader_v1.rb index 2a69c95c..dc2e0ed2 100644 --- a/lib/mindee/product/barcode_reader/barcode_reader_v1.rb +++ b/lib/mindee/product/barcode_reader/barcode_reader_v1.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..5ee6c8a9 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() + super(prediction) @codes_1d = [] 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 = [] 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/bill_of_lading/bill_of_lading_v1.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1.rb index 25961a6d..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 @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end end 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..bf0519b3 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 @@ -50,12 +50,12 @@ class BillOfLadingV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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)) + @carrier_items.push(BillOfLading::BillOfLadingV1CarrierItem.new(item, page_id)) end @consignee = BillOfLadingV1Consignee.new(prediction['consignee'], page_id) @date_of_issue = DateField.new(prediction['date_of_issue'], page_id) diff --git a/lib/mindee/product/business_card/business_card_v1.rb b/lib/mindee/product/business_card/business_card_v1.rb index d00b2963..79e9b7e4 100644 --- a/lib/mindee/product/business_card/business_card_v1.rb +++ b/lib/mindee/product/business_card/business_card_v1.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..9792809e 100644 --- a/lib/mindee/product/business_card/business_card_v1_document.rb +++ b/lib/mindee/product/business_card/business_card_v1_document.rb @@ -45,7 +45,7 @@ class BusinessCardV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @address = StringField.new(prediction['address'], page_id) @company = StringField.new(prediction['company'], page_id) @email = StringField.new(prediction['email'], page_id) @@ -57,7 +57,7 @@ def initialize(prediction, page_id) @phone_number = StringField.new(prediction['phone_number'], page_id) @social_media = [] 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) end diff --git a/lib/mindee/product/cropper/cropper_v1.rb b/lib/mindee/product/cropper/cropper_v1.rb index 73e30622..8373711b 100644 --- a/lib/mindee/product/cropper/cropper_v1.rb +++ b/lib/mindee/product/cropper/cropper_v1.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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 3e1606e1..f0e561d2 100644 --- a/lib/mindee/product/delivery_note/delivery_note_v1.rb +++ b/lib/mindee/product/delivery_note/delivery_note_v1.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..042ad769 100644 --- a/lib/mindee/product/delivery_note/delivery_note_v1_document.rb +++ b/lib/mindee/product/delivery_note/delivery_note_v1_document.rb @@ -33,7 +33,7 @@ class DeliveryNoteV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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) diff --git a/lib/mindee/product/driver_license/driver_license_v1.rb b/lib/mindee/product/driver_license/driver_license_v1.rb index f099e190..6c1c016d 100644 --- a/lib/mindee/product/driver_license/driver_license_v1.rb +++ b/lib/mindee/product/driver_license/driver_license_v1.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..712168c3 100644 --- a/lib/mindee/product/driver_license/driver_license_v1_document.rb +++ b/lib/mindee/product/driver_license/driver_license_v1_document.rb @@ -51,7 +51,7 @@ class DriverLicenseV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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) 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 17b976aa..b3c3b510 100644 --- a/lib/mindee/product/eu/license_plate/license_plate_v1.rb +++ b/lib/mindee/product/eu/license_plate/license_plate_v1.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..4b8ab4b0 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() + super(prediction) @license_plates = [] 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/financial_document/financial_document_v1.rb b/lib/mindee/product/financial_document/financial_document_v1.rb index 79080fc9..4b8fc8c9 100644 --- a/lib/mindee/product/financial_document/financial_document_v1.rb +++ b/lib/mindee/product/financial_document/financial_document_v1.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..7b00635e 100644 --- a/lib/mindee/product/financial_document/financial_document_v1_document.rb +++ b/lib/mindee/product/financial_document/financial_document_v1_document.rb @@ -109,13 +109,13 @@ class FinancialDocumentV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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 = [] 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) @@ -126,7 +126,7 @@ def initialize(prediction, 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)) + @line_items.push(FinancialDocument::FinancialDocumentV1LineItem.new(item, page_id)) end @locale = LocaleField.new(prediction['locale'], page_id) @payment_date = DateField.new(prediction['payment_date'], page_id) @@ -134,20 +134,20 @@ def initialize(prediction, page_id) @receipt_number = StringField.new(prediction['receipt_number'], page_id) @reference_numbers = [] 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 = [] 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 = [] 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) 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 ade9cd84..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 @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..0d246b64 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,7 +22,7 @@ class BankAccountDetailsV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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) 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 2703f4e8..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 @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end end 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..f536b774 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,7 +26,7 @@ class BankAccountDetailsV2Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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) 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 58ef3f67..72f9f971 100644 --- a/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb +++ b/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..3ac9be43 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,7 +136,7 @@ class CarteGriseV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @a = StringField.new(prediction['a'], page_id) @b = DateField.new(prediction['b'], page_id) @c1 = StringField.new(prediction['c1'], page_id) 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 97c33480..6f7ec95f 100644 --- a/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb +++ b/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..b5e52a45 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 @@ -62,7 +62,7 @@ class EnergyBillV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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) @@ -70,18 +70,18 @@ def initialize(prediction, 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)) + @energy_usage.push(EnergyBill::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)) + @subscription.push(EnergyBill::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)) + @taxes_and_contributions.push(EnergyBill::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) 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 ed9971e8..0869f4d9 100644 --- a/lib/mindee/product/fr/health_card/health_card_v1.rb +++ b/lib/mindee/product/fr/health_card/health_card_v1.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..c6a50081 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,10 +25,10 @@ class HealthCardV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @given_names = [] 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) 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 1dec2c79..63cb3bdc 100644 --- a/lib/mindee/product/fr/id_card/id_card_v1.rb +++ b/lib/mindee/product/fr/id_card/id_card_v1.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..ac3a1f12 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,7 +43,7 @@ class IdCardV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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) @@ -51,7 +51,7 @@ def initialize(prediction, page_id) @gender = StringField.new(prediction['gender'], page_id) @given_names = [] 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) 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 e3a9c1b8..9bf5daf7 100644 --- a/lib/mindee/product/fr/id_card/id_card_v2.rb +++ b/lib/mindee/product/fr/id_card/id_card_v2.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..418a5637 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,7 +58,7 @@ class IdCardV2Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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) @@ -69,7 +69,7 @@ def initialize(prediction, page_id) @gender = StringField.new(prediction['gender'], page_id) @given_names = [] 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) diff --git a/lib/mindee/product/fr/payslip/payslip_v2.rb b/lib/mindee/product/fr/payslip/payslip_v2.rb index 33c3e465..68eb1239 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end end diff --git a/lib/mindee/product/fr/payslip/payslip_v2_document.rb b/lib/mindee/product/fr/payslip/payslip_v2_document.rb index 11b62400..1bf3d9c5 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_document.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_document.rb @@ -45,7 +45,7 @@ class PayslipV2Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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) @@ -55,7 +55,7 @@ def initialize(prediction, 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)) + @salary_details.push(Payslip::PayslipV2SalaryDetail.new(item, page_id)) end end diff --git a/lib/mindee/product/fr/payslip/payslip_v3.rb b/lib/mindee/product/fr/payslip/payslip_v3.rb index beb23f14..6eeabe65 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end end diff --git a/lib/mindee/product/fr/payslip/payslip_v3_document.rb b/lib/mindee/product/fr/payslip/payslip_v3_document.rb index 721de190..9cf9eb6e 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_document.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_document.rb @@ -45,20 +45,20 @@ class PayslipV3Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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)) + @paid_time_off.push(Payslip::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)) + @salary_details.push(Payslip::PayslipV3SalaryDetail.new(item, page_id)) 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 762c69aa..48689564 100644 --- a/lib/mindee/product/ind/indian_passport/indian_passport_v1.rb +++ b/lib/mindee/product/ind/indian_passport/indian_passport_v1.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..a8bfefde 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,7 +82,7 @@ class IndianPassportV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @address1 = StringField.new(prediction['address1'], page_id) @address2 = StringField.new(prediction['address2'], page_id) @address3 = StringField.new(prediction['address3'], page_id) diff --git a/lib/mindee/product/international_id/international_id_v2.rb b/lib/mindee/product/international_id/international_id_v2.rb index c1afecd9..290b9435 100644 --- a/lib/mindee/product/international_id/international_id_v2.rb +++ b/lib/mindee/product/international_id/international_id_v2.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..3d2b1dc0 100644 --- a/lib/mindee/product/international_id/international_id_v2_document.rb +++ b/lib/mindee/product/international_id/international_id_v2_document.rb @@ -63,7 +63,7 @@ class InternationalIdV2Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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) @@ -73,7 +73,7 @@ def initialize(prediction, page_id) @expiry_date = DateField.new(prediction['expiry_date'], page_id) @given_names = [] 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) @@ -85,7 +85,7 @@ def initialize(prediction, page_id) @state_of_issue = StringField.new(prediction['state_of_issue'], page_id) @surnames = [] 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/invoice/invoice_v4.rb b/lib/mindee/product/invoice/invoice_v4.rb index 47734e4a..edf101dd 100644 --- a/lib/mindee/product/invoice/invoice_v4.rb +++ b/lib/mindee/product/invoice/invoice_v4.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end end diff --git a/lib/mindee/product/invoice/invoice_v4_document.rb b/lib/mindee/product/invoice/invoice_v4_document.rb index 31b8e0b9..49785a67 100644 --- a/lib/mindee/product/invoice/invoice_v4_document.rb +++ b/lib/mindee/product/invoice/invoice_v4_document.rb @@ -91,12 +91,12 @@ class InvoiceV4Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @billing_address = StringField.new(prediction['billing_address'], page_id) @customer_address = StringField.new(prediction['customer_address'], page_id) @customer_company_registrations = [] 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) @@ -106,26 +106,26 @@ def initialize(prediction, 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)) + @line_items.push(Invoice::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 = [] 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 = [] 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 = [] 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) diff --git a/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb b/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb index dd7dd79a..893e49a1 100644 --- a/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb +++ b/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..8d340c5b 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) construct_invoice_page_groups_from_prediction(prediction) end 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 0de4c71c..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 @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..d7a62e67 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 @@ -6,7 +6,7 @@ module Mindee module Product module MultiReceiptsDetector # Multi Receipts Detector API version 1.1 document data. - class MultiReceiptsDetectorV1Document < Mindee::Parsing::Common::Prediction + class MultiReceiptsDetectorV1Document < Parsing::Common::Prediction include Mindee::Parsing::Standard # Positions of the receipts on the document. # @return [Array] @@ -14,11 +14,11 @@ class MultiReceiptsDetectorV1Document < 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) @receipts = [] 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/nutrition_facts_label/nutrition_facts_label_v1.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rb index ae48b10c..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 @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end 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..b49eb716 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 @@ -67,14 +67,14 @@ class NutritionFactsLabelV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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)) + @nutrients.push(NutritionFactsLabel::NutritionFactsLabelV1Nutrient.new(item, page_id)) end @protein = NutritionFactsLabelV1Protein.new(prediction['protein'], page_id) @saturated_fat = NutritionFactsLabelV1SaturatedFat.new(prediction['saturated_fat'], page_id) diff --git a/lib/mindee/product/passport/passport_v1.rb b/lib/mindee/product/passport/passport_v1.rb index 7d261844..37802934 100644 --- a/lib/mindee/product/passport/passport_v1.rb +++ b/lib/mindee/product/passport/passport_v1.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end end diff --git a/lib/mindee/product/passport/passport_v1_document.rb b/lib/mindee/product/passport/passport_v1_document.rb index 5de4c473..c40875f0 100644 --- a/lib/mindee/product/passport/passport_v1_document.rb +++ b/lib/mindee/product/passport/passport_v1_document.rb @@ -45,7 +45,7 @@ class PassportV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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) @@ -53,7 +53,7 @@ def initialize(prediction, page_id) @gender = StringField.new(prediction['gender'], page_id) @given_names = [] 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) diff --git a/lib/mindee/product/receipt/receipt_v5.rb b/lib/mindee/product/receipt/receipt_v5.rb index 554b37af..ce1b3c48 100644 --- a/lib/mindee/product/receipt/receipt_v5.rb +++ b/lib/mindee/product/receipt/receipt_v5.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end end diff --git a/lib/mindee/product/receipt/receipt_v5_document.rb b/lib/mindee/product/receipt/receipt_v5_document.rb index 9dad48c0..ebc7ccf9 100644 --- a/lib/mindee/product/receipt/receipt_v5_document.rb +++ b/lib/mindee/product/receipt/receipt_v5_document.rb @@ -64,13 +64,13 @@ class ReceiptV5Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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)) + @line_items.push(Receipt::ReceiptV5LineItem.new(item, page_id)) end @locale = LocaleField.new(prediction['locale'], page_id) @receipt_number = StringField.new(prediction['receipt_number'], page_id) @@ -78,7 +78,7 @@ def initialize(prediction, page_id) @supplier_address = StringField.new(prediction['supplier_address'], page_id) @supplier_company_registrations = [] 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) diff --git a/lib/mindee/product/resume/resume_v1.rb b/lib/mindee/product/resume/resume_v1.rb index 76e58d11..3314ab1c 100644 --- a/lib/mindee/product/resume/resume_v1.rb +++ b/lib/mindee/product/resume/resume_v1.rb @@ -33,10 +33,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end end diff --git a/lib/mindee/product/resume/resume_v1_document.rb b/lib/mindee/product/resume/resume_v1_document.rb index afc2e47a..81ae151e 100644 --- a/lib/mindee/product/resume/resume_v1_document.rb +++ b/lib/mindee/product/resume/resume_v1_document.rb @@ -68,50 +68,50 @@ class ResumeV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @address = StringField.new(prediction['address'], page_id) @certificates = [] prediction['certificates'].each do |item| - @certificates.push(ResumeV1Certificate.new(item, page_id)) + @certificates.push(Resume::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)) + @education.push(Resume::ResumeV1Education.new(item, page_id)) end @email_address = StringField.new(prediction['email_address'], page_id) @given_names = [] 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 = [] prediction['hard_skills'].each do |item| - @hard_skills.push(StringField.new(item, page_id)) + @hard_skills.push(Parsing::Standard::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)) + @languages.push(Resume::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)) + @professional_experiences.push(Resume::ResumeV1ProfessionalExperience.new(item, page_id)) end @social_networks_urls = [] prediction['social_networks_urls'].each do |item| - @social_networks_urls.push(ResumeV1SocialNetworksUrl.new(item, page_id)) + @social_networks_urls.push(Resume::ResumeV1SocialNetworksUrl.new(item, page_id)) end @soft_skills = [] 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 = [] 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/universal/universal.rb b/lib/mindee/product/universal/universal.rb index 99d9f413..7869bfb6 100644 --- a/lib/mindee/product/universal/universal.rb +++ b/lib/mindee/product/universal/universal.rb @@ -18,7 +18,7 @@ class Universal < Mindee::Parsing::Common::Inference def initialize(prediction) super @prediction = UniversalDocument.new(prediction['prediction']) - @pages = [] + @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)) @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end end diff --git a/lib/mindee/product/universal/universal_document.rb b/lib/mindee/product/universal/universal_document.rb index 879290c2..7ea2e9ff 100644 --- a/lib/mindee/product/universal/universal_document.rb +++ b/lib/mindee/product/universal/universal_document.rb @@ -11,10 +11,7 @@ class UniversalDocument < Mindee::Product::Universal::UniversalPrediction include Mindee::Parsing::Standard # @param raw_prediction [Hash] def initialize(raw_prediction) - # Universal document. - - # raw_prediction: Dictionary containing the JSON document response - super() + super raw_prediction.each do |field_name, field_contents| if field_contents.is_a?(Array) @fields[field_name] = Parsing::Universal::UniversalListField.new(field_contents) @@ -25,7 +22,7 @@ def initialize(raw_prediction) 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) + @fields[field_name] = Mindee::Parsing::Standard::StringField.new(field_contents_str) end end end diff --git a/lib/mindee/product/universal/universal_page.rb b/lib/mindee/product/universal/universal_page.rb index 2137834c..7da359e5 100644 --- a/lib/mindee/product/universal/universal_page.rb +++ b/lib/mindee/product/universal/universal_page.rb @@ -23,18 +23,18 @@ class UniversalPagePrediction < UniversalPrediction include Mindee::Parsing::Standard 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] = UniversalListField.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] = UniversalObjectField.new(field_contents, page_id) + @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/universal/universal_prediction.rb b/lib/mindee/product/universal/universal_prediction.rb index 82c1c6bd..37eb2547 100644 --- a/lib/mindee/product/universal/universal_prediction.rb +++ b/lib/mindee/product/universal/universal_prediction.rb @@ -14,9 +14,9 @@ class UniversalPrediction < Mindee::Parsing::Common::Prediction # @return [Hash] attr_reader :fields - def initialize + def initialize(_ = nil) super - @fields = {} + @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?(UniversalListField) && 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 @@ -66,7 +68,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?(UniversalObjectField) + 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,9 +78,9 @@ 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 @@ -86,9 +88,9 @@ def single_fields # Returns a hash of all list-like fields # @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?(UniversalListField) + list_fields[field_name] = field_value if field_value.is_a?(Mindee::Parsing::Universal::UniversalListField) end list_fields end @@ -96,9 +98,12 @@ def list_fields # Returns a hash of all object-like fields # @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?(UniversalObjectField) + 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 f6e1a05d..8dd0008f 100644 --- a/lib/mindee/product/us/bank_check/bank_check_v1.rb +++ b/lib/mindee/product/us/bank_check/bank_check_v1.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..166a4b9b 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,14 +31,14 @@ class BankCheckV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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 = [] 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) 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 1f899538..75c0bcd3 100644 --- a/lib/mindee/product/us/healthcare_card/healthcare_card_v1.rb +++ b/lib/mindee/product/us/healthcare_card/healthcare_card_v1.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..f2633d05 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 @@ -50,15 +50,15 @@ class HealthcareCardV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @company_name = StringField.new(prediction['company_name'], page_id) @copays = [] prediction['copays'].each do |item| - @copays.push(HealthcareCardV1Copay.new(item, page_id)) + @copays.push(HealthcareCard::HealthcareCardV1Copay.new(item, page_id)) end @dependents = [] 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) 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 0fad49b0..00000000 --- a/lib/mindee/product/us/us_mail/us_mail_v2.rb +++ /dev/null @@ -1,47 +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' - @has_async = true - @has_sync = false - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = UsMailV2Document.new(prediction['prediction'], nil) - @pages = [] - prediction['pages'].each do |page| - @pages.push(UsMailV2Page.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 - # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] - attr_reader :has_async - # Whether this product has access to synchronous endpoint. - # @return [Boolean] - attr_reader :has_sync - 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 b3d3596e..00000000 --- a/lib/mindee/product/us/us_mail/us_mail_v2_page.rb +++ /dev/null @@ -1,38 +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 = if prediction['prediction'].empty? - nil - else - UsMailV2PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) - end - 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 811574d1..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 - @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 41439080..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 - @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 9d9b10da..02557697 100644 --- a/lib/mindee/product/us/us_mail/us_mail_v3.rb +++ b/lib/mindee/product/us/us_mail/us_mail_v3.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync 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..eb9a3036 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 @@ -30,15 +30,15 @@ class UsMailV3Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super() + super(prediction) @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)) + @recipient_addresses.push(UsMail::UsMailV3RecipientAddress.new(item, page_id)) end @recipient_names = [] 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) 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 9f59eecb..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] diff --git a/lib/mindee/product/us/w9/w9_v1.rb b/lib/mindee/product/us/w9/w9_v1.rb index d479cd18..9bf1fa27 100644 --- a/lib/mindee/product/us/w9/w9_v1.rb +++ b/lib/mindee/product/us/w9/w9_v1.rb @@ -34,10 +34,10 @@ class << self # @return [String] attr_reader :endpoint_version # Whether this product has access to an asynchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_async # Whether this product has access to synchronous endpoint. - # @return [Boolean] + # @return [bool] attr_reader :has_sync end end 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 d0633871..78fbab57 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 @@ -30,12 +28,15 @@ Gem::Specification.new do |spec| spec.required_ruby_version = Gem::Requirement.new('>= 3.0') spec.add_dependency 'marcel', '~> 1.0.4' - spec.add_dependency 'mini_magick', '>=4', '< 6' + spec.add_dependency 'mini_magick', '>= 4', '< 6' spec.add_dependency 'origamindee', '~> 3.1.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/mini_magick.rbs b/sig/custom/mini_magick.rbs new file mode 100644 index 00000000..1d829a68 --- /dev/null +++ b/sig/custom/mini_magick.rbs @@ -0,0 +1,12 @@ +# 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.read: (StringIO) -> self + def self.resolution: () -> Array[Float | Integer] + def self.write: (String) -> Net::BufferedIO + def self.to_blob: () -> String + 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..cbac9f58 --- /dev/null +++ b/sig/custom/net_http.rbs @@ -0,0 +1,26 @@ +# 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 + end + 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..5a0cf9e8 --- /dev/null +++ b/sig/custom/origami.rbs @@ -0,0 +1,49 @@ +# 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 + class LinearParser + def initialize: (Hash[Symbol, untyped]) -> void + def new: (Hash[Symbol, untyped]) -> void + def parse: (StringIO) -> untyped + end + end + + class Page + def initialize: () -> void + def add_xobject: (Graphics::ImageXObject, String) -> 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..37f9ff73 --- /dev/null +++ b/sig/mindee/client.rbs @@ -0,0 +1,112 @@ +OTS_OWNER: String + +module Mindee + # Redeclare OTS_OWNER inside the module for internal use. + 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 | Hash[Symbol | String, untyped]?) + 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 + + # WorkflowOptions is defined via a Struct in client.rb. + 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 | Hash[Symbol | String, untyped]?) + + def initialize: (params: Hash[Symbol | String, untyped]) -> void + end + + class Client + # Clients are initialized with a keyword api_key. + def initialize: (api_key: String) -> void + + # The client internally uses a logger; its return type is left untyped. + def logger: () -> untyped + + # Enqueue a document for parsing. + def parse: (Input::Source::LocalInputSource | Input::Source::UrlInputSource, untyped, ?endpoint: (HTTP::Endpoint?), options: ParseOptions | Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse + + # Synchronous parsing call. + # Note: options is expected to be a ParseOptions instance. + def parse_sync: (Input::Source::LocalInputSource | Input::Source::UrlInputSource, untyped, HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse + + # Asynchronous enqueuing of a document. + def enqueue: (Input::Source::LocalInputSource | Input::Source::UrlInputSource, untyped, ?endpoint: (HTTP::Endpoint?), options: ParseOptions|Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse + + # Polls for a queued document using its job_id. + def parse_queued: (String, singleton(Parsing::Common::Inference), ?endpoint: HTTP::Endpoint?) -> Parsing::Common::ApiResponse + + # Enqueue and then continually poll for the parsing result. + def enqueue_and_parse: (Input::Source::UrlInputSource|Input::Source::LocalInputSource, untyped, HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse + + # Sends a document to a workflow. + # The options parameter is either a Hash with symbol keys or a WorkflowOptions. + def execute_workflow: (Input::Source::UrlInputSource|Input::Source::LocalInputSource, String, options: (Hash[Symbol | String, untyped] | WorkflowOptions)) -> Parsing::Common::WorkflowResponse + + # Loads a prediction from a local response. + def load_prediction: (singleton(Parsing::Common::Inference), Input::LocalResponse) -> Parsing::Common::ApiResponse + + # Creates an input source from a file path. + def source_from_path: (String, ?fix_pdf: bool) -> Input::Source::PathInputSource + + # Creates an input source from raw bytes. + def source_from_bytes: (String, String, ?fix_pdf: bool) -> Input::Source::BytesInputSource + + # Creates an input source from a base64 encoded string. + def source_from_b64string: (String, String, ?fix_pdf: bool) -> Input::Source::Base64InputSource + + # Creates an input source from a Ruby File. + def source_from_file: (File, String, ?fix_pdf: bool) -> Input::Source::FileInputSource + + # Creates an input source from a URL. + def source_from_url: (String) -> Input::Source::UrlInputSource + + # Creates a custom endpoint. + # The parameters are provided as keywords in client.rb but here they are declared as required. + def create_endpoint: (endpoint_name: String, account_name: String, version: String) -> HTTP::Endpoint + + private + + # Returns a ParseOptions instance given either a Hash or an existing ParseOptions. + def normalize_parse_options: ((Hash[Symbol | String, untyped] | ParseOptions)) -> ParseOptions + + # Process the PDF if required. + def process_pdf_if_required: (Input::Source::LocalInputSource, ParseOptions | WorkflowOptions) -> void + + # Creates an endpoint using the product class and supplied values. + def initialize_endpoint: (singleton(Parsing::Common::Inference), ?endpoint_name: String, ?account_name: String, ?version: String) -> HTTP::Endpoint + + # Validates asynchronous polling parameters. + def validate_async_params: (Integer | Float, Integer | Float, Integer) -> void + + # Helper to fix an endpoint name when not provided. + def fix_endpoint_name: (singleton(Parsing::Common::Inference), String?) -> String? + + # Helper to fix the account name. + def fix_account_name: (String) -> String + + # Helper to fix the version. + # Note: leave untyped, as RBS isn't able to recognize inherited class attributes yet. + 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..0b54d961 --- /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: -> untyped + def top_left=: (untyped) -> untyped + def top_right: -> untyped + def top_right=: (untyped) -> untyped + def bottom_right: -> untyped + def bottom_right=: (untyped) -> untyped + def bottom_left: -> untyped + def bottom_left=: (untyped) -> untyped + def initialize: (untyped, untyped, untyped, untyped) -> untyped + def []: (untyped) -> bot + 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..d5e92f63 --- /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) -> untyped + 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..c65071db --- /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: -> untyped + def element_id: -> Integer + def buffer: -> StringIO + def internal_file_name: -> String + def initialize: (untyped, untyped, untyped) -> Integer + def write_to_file: (untyped, ?nil) -> nil + def as_source: -> untyped + 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..353da19f --- /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: (untyped, ?quality: Integer, ?max_width: nil, ?max_height: nil) -> untyped + 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..ea05be78 --- /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: (untyped, untyped, untyped) -> nil + def self.compress_image_quality: (untyped, untyped) -> untyped + def self.to_image: (untyped) -> (singleton(MiniMagick::Image) | MiniMagick::Image) + def self.image_to_stringio: (untyped, ?String) -> StringIO + def self.calculate_new_dimensions: (untyped, ?max_width: nil, ?max_height: nil) -> [untyped, untyped] + def self.calculate_dimensions_from_media_box: (untyped, untyped) -> [untyped, untyped] + def self.pdf_to_magick_image: (untyped, untyped) -> untyped + def self.normalize_polygon: (untyped) -> untyped + def self.read_page_content: (untyped) -> untyped + def self.crop_image: (untyped, untyped, untyped) -> untyped + def self.write_image_to_buffer: (untyped, untyped) -> untyped + def self.determine_file_extension: (untyped) -> 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..a256d9c7 --- /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 # failed to identify its superclass + def initialize: (untyped, untyped, ?fix_pdf: bool) -> untyped + def read_contents: (?close: true) -> [String, String, Hash[:filename, 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..a363e9f4 --- /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 # failed to identify its superclass + def initialize: (untyped, untyped, ?fix_pdf: bool) -> untyped + 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..7ce1cb92 --- /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 # failed to identify its superclass + def initialize: (untyped, untyped, ?fix_pdf: bool) -> untyped + 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..95bb8e76 --- /dev/null +++ b/sig/mindee/input/sources/local_input_source.rbs @@ -0,0 +1,22 @@ +# lib/mindee/input/sources/local_input_source.rb +module Mindee + module Input + module Source + ALLOWED_MIME_TYPES: Array[String] + class LocalInputSource + def filename: -> untyped + def file_mimetype: -> untyped + def io_stream: -> StringIO + def initialize: (untyped, untyped, ?fix_pdf: bool) -> nil + def rescue_broken_pdf: (StringIO) -> StringIO + def pdf?: -> untyped + def process_pdf: (untyped) -> untyped + def read_contents: (?close: true) -> [String, String?, Hash[:filename, String]] + def count_pages: -> Integer + def compress!: (?quality: Integer, ?max_width: nil, ?max_height: nil, ?force_source_text: false, ?disable_source_text: true) -> Integer + def source_text?: -> untyped + end + def self.convert_to_unicode_escape: (untyped) -> 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..236ac4ef --- /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 # failed to identify its superclass + def initialize: (untyped, ?fix_pdf: bool) -> untyped + 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..403d29e6 --- /dev/null +++ b/sig/mindee/input/sources/url_input_source.rbs @@ -0,0 +1,19 @@ +# lib/mindee/input/sources/url_input_source.rb +module Mindee + module Input + module Source + class UrlInputSource + def url: -> untyped + def initialize: (untyped) -> untyped + def write_to_file: (untyped, ?filename: nil, ?username: nil, ?password: nil, ?token: nil, ?max_redirects: Integer) -> String + def as_local_input_source: (?filename: nil, ?username: nil, ?password: nil, ?token: nil, ?max_redirects: Integer) -> untyped + def fetch_file_content: (?username: nil, ?password: nil, ?token: nil, ?max_redirects: Integer) -> untyped + def extract_filename_from_url: (untyped) -> String + def fill_filename: (nil) -> String + def make_request: (untyped, untyped, Integer) -> untyped + 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..a8662221 --- /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: -> untyped + def job: -> 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/common/document.rbs b/sig/mindee/parsing/common/document.rbs new file mode 100644 index 00000000..44280ee6 --- /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..7533d821 --- /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: -> untyped + def issued_at: -> untyped + def available_at: -> untyped + def status: -> untyped + def millisecs_taken: -> Integer + def error: -> untyped + def initialize: (untyped) -> untyped + 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..64f10c40 --- /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..9f2cadcc --- /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) -> nil + 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..2c4c6b13 --- /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?) -> 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..70b04681 --- /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: -> untyped + def polygon: -> untyped + def page_id: -> untyped + def confidence: -> untyped + def confidence=: (untyped) -> untyped + def initialize: (untyped, untyped) -> untyped + def to_s: -> String + def self.array_confidence: (untyped) -> Float + def self.array_sum: (untyped) -> Float + def self.float_to_string: (untyped, ?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..d8866971 --- /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 value: -> untyped + def reconstructed: -> false + def initialize: (untyped, untyped, ?reconstructed: false) -> false + 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..769822d0 --- /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: -> untyped + def initialize: (untyped, ?nil, ?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..8e3ef431 --- /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 # failed to identify its superclass + def value: -> untyped + 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..e71046eb --- /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 # failed to identify its superclass + def format_for_display: (untyped, ?nil) -> 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..297b0073 --- /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: -> untyped + def language: -> untyped + def country: -> untyped + def currency: -> untyped + def value: -> untyped + def initialize: (untyped, ?nil) -> untyped + 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..a30c3e4c --- /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: -> untyped + def value: -> untyped + def quadrangle: -> nil + def rectangle: -> nil + def bounding_box: -> nil + def initialize: (untyped, untyped) -> untyped + def to_s: -> String + def to_quadrilateral: (untyped, String) -> nil + 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..2803d133 --- /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 # failed to identify its superclass + def value: -> untyped + def raw_value: -> untyped + def initialize: (untyped, ?nil, ?reconstructed: false) -> untyped + 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..47d546f6 --- /dev/null +++ b/sig/mindee/parsing/universal/universal_list_field.rbs @@ -0,0 +1,18 @@ +# lib/mindee/parsing/universal/universal_list_field.rb +module Mindee + module Parsing + module Universal + class UniversalListField + include Universal + def page_id: -> untyped + def page_id=: (untyped) -> untyped + def values: -> [] + def values=: (untyped) -> [] + def initialize: (untyped, ?nil) -> untyped + def contents_list: -> Array[untyped] + 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..61f8a325 --- /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: -> untyped + def page_id=: (untyped) -> untyped + def confidence: -> untyped + def confidence=: (untyped) -> untyped + def raw_value: -> untyped + def raw_value=: (untyped) -> untyped + def initialize: (untyped, ?nil) -> untyped + def str_level: (?Integer) -> String + def method_missing: (untyped, *untyped) -> nil + def respond_to_missing?: (untyped, ?false) -> bool + def to_s: -> String + def handle_position_field: (untyped, untyped, untyped) -> untyped + def handle_default_field: (untyped, untyped) -> nil + end + def self.universal_object?: (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..04038aad --- /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: (untyped, ?quality: Integer, ?force_source_text_compression: false, ?disable_source_text: true) -> StringIO + def self.process_pdf_pages: (untyped, Integer) -> untyped + def self.create_output_pdf: (untyped, true, untyped) -> untyped + def self.inject_text: (untyped, untyped) -> nil + def self.process_pdf_page: (untyped, untyped, Integer, untyped) -> untyped + 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..2710e62e --- /dev/null +++ b/sig/mindee/pdf/pdf_processor.rbs @@ -0,0 +1,13 @@ +# lib/mindee/pdf/pdf_processor.rb +module Mindee + module PDF + module PDFProcessor + DEFAULT_OPTIONS: Hash[Symbol, untyped] + def self.parse: (StringIO, Hash[Symbol, Array[untyped]]) -> nil + 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) -> untyped + def self.get_page: (untyped, untyped) -> nil + 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/invoice_splitter/invoice_splitter_v1.rbs b/sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs new file mode 100644 index 00000000..baa48e6a --- /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: (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/invoice_splitter/invoice_splitter_v1_document.rbs b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs new file mode 100644 index 00000000..9b23ddcf --- /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: -> untyped + def confidence: -> Float? + def initialize: (untyped) -> Float? + def to_s: -> String + end + class InvoiceSplitterV1Document < Parsing::Common::Prediction + def invoice_page_groups: -> Array[untyped] + def initialize: (untyped, untyped?) -> void + def construct_invoice_page_groups_from_prediction: (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..3eaef4aa --- /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: (untyped) -> untyped + 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..d01b77a1 --- /dev/null +++ b/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rbs @@ -0,0 +1,14 @@ +# lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rb +module Mindee + module Product + module MultiReceiptsDetector + class MultiReceiptsDetectorV1 < 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/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..076aaf21 --- /dev/null +++ b/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rbs @@ -0,0 +1,12 @@ +# lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb +module Mindee + module Product + module MultiReceiptsDetector + class MultiReceiptsDetectorV1Document < Parsing::Common::Prediction + def receipts: -> [] + def initialize: (untyped, ?untyped) -> void + 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..f033194f --- /dev/null +++ b/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rbs @@ -0,0 +1,13 @@ +# 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: (untyped) -> void + end + class MultiReceiptsDetectorV1PagePrediction < MultiReceiptsDetectorV1Document + 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..68c3242e --- /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: (untyped) -> untyped + 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..d7313559 --- /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: (untyped) -> untyped + end + class UniversalPagePrediction < UniversalPrediction + def initialize: (untyped, ?nil) -> untyped + 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..6cc7f0b4 --- /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[untyped, untyped] + def initialize: (untyped?) -> void + def to_s: -> String + def generate_field_string: (untyped, untyped, Regexp) -> String + def generate_list_field_string: (untyped, untyped, untyped) -> String + def generate_sub_value_string: (untyped, untyped, untyped) -> String + def single_fields: -> Hash[untyped, 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/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/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/pdf/extracted_pdf_spec.rb b/spec/pdf/extracted_pdf_spec.rb index afccf91c..8bcda736 100644 --- a/spec/pdf/extracted_pdf_spec.rb +++ b/spec/pdf/extracted_pdf_spec.rb @@ -40,7 +40,7 @@ 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])) + 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) diff --git a/spec/pdf/pdf_processor_spec.rb b/spec/pdf/pdf_processor_spec.rb index 0ef77fe1..a5b4143f 100644 --- a/spec/pdf/pdf_processor_spec.rb +++ b/spec/pdf/pdf_processor_spec.rb @@ -22,7 +22,7 @@ def open_pdf(io_stream) operation: :KEEP_ONLY, on_min_pages: 0, } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) new_pdf = open_pdf(new_stream) expect(new_pdf.pages.size).to eq(1) end @@ -35,7 +35,7 @@ def open_pdf(io_stream) operation: :KEEP_ONLY, on_min_pages: 0, } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) new_pdf = open_pdf(new_stream) expect(new_pdf.pages.size).to eq(1) end @@ -52,7 +52,7 @@ def open_pdf(io_stream) operation: :KEEP_ONLY, on_min_pages: 0, } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) new_pdf = open_pdf(new_stream) expect(new_pdf.pages.size).to eq(1) end @@ -65,7 +65,7 @@ def open_pdf(io_stream) operation: :KEEP_ONLY, on_min_pages: 0, } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) new_pdf = open_pdf(new_stream) expect(new_pdf.pages.size).to eq(1) end @@ -78,7 +78,7 @@ def open_pdf(io_stream) operation: :KEEP_ONLY, on_min_pages: 0, } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) new_pdf = open_pdf(new_stream) expect(new_pdf.pages.size).to eq(3) end @@ -91,7 +91,7 @@ def open_pdf(io_stream) operation: :KEEP_ONLY, on_min_pages: 0, } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) new_pdf = open_pdf(new_stream) expect(new_pdf.pages.size).to eq(5) end @@ -104,7 +104,7 @@ def open_pdf(io_stream) operation: :REMOVE, on_min_pages: 0, } - new_stream = Mindee::PDF::PdfProcessor.parse(io_stream, options) + new_stream = Mindee::PDF::PDFProcessor.parse(io_stream, options) new_pdf = open_pdf(new_stream) expect(new_pdf.pages.size).to eq(9) end @@ -118,7 +118,7 @@ def open_pdf(io_stream) on_min_pages: 0, } expect do - Mindee::PDF::PdfProcessor.parse(io_stream, options) + Mindee::PDF::PDFProcessor.parse(io_stream, options) end.to raise_error ArgumentError end end From e121c612647cef856186d4608fc54234cacc2195 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Thu, 13 Feb 2025 15:12:08 +0100 Subject: [PATCH 13/17] :recycle: temporarily remove support for ruby 3.4 until origamindee is fixed (#153) --- .github/workflows/_test-code-samples.yml | 1 - .github/workflows/_test-integrations.yml | 1 - .github/workflows/_test-units.yml | 1 - 3 files changed, 3 deletions(-) diff --git a/.github/workflows/_test-code-samples.yml b/.github/workflows/_test-code-samples.yml index bbd5e8ce..87bd4b87 100644 --- a/.github/workflows/_test-code-samples.yml +++ b/.github/workflows/_test-code-samples.yml @@ -15,7 +15,6 @@ jobs: - "3.1" - "3.2" - "3.3" - - "3.4" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/_test-integrations.yml b/.github/workflows/_test-integrations.yml index 5f5b88b5..377493fe 100644 --- a/.github/workflows/_test-integrations.yml +++ b/.github/workflows/_test-integrations.yml @@ -22,7 +22,6 @@ jobs: - "3.1" - "3.2" - "3.3" - - "3.4" steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/_test-units.yml b/.github/workflows/_test-units.yml index 5f40538a..a13ff5ff 100644 --- a/.github/workflows/_test-units.yml +++ b/.github/workflows/_test-units.yml @@ -22,7 +22,6 @@ jobs: - "3.1" - "3.2" - "3.3" - - "3.4" steps: - uses: actions/checkout@v4 with: From cb0fd3caa2315973ce5c095cc131c778e0d0ad0f Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 18 Feb 2025 09:32:18 +0100 Subject: [PATCH 14/17] :recycle: add type signatures for products (#154) --- README.md | 9 +- Steepfile | 40 ++---- bin/mindee.rb | 20 +-- docs/bank_account_details_v2.md | 15 +- docs/bank_check_v1.md | 4 +- docs/bank_statement_fr_v1.md | 83 ++++++++++- docs/barcode_reader_v1.md | 4 +- docs/bill_of_lading_v1.md | 60 +++++++- docs/business_card_v1.md | 4 +- docs/carte_grise_v1.md | 4 +- .../bank_statement_fr_v1_async.txt | 19 +++ docs/cropper_v1.md | 4 +- docs/delivery_notes_v1.md | 4 +- docs/driver_license_v1.md | 4 +- docs/energy_bill_fra_v1.md | 78 +++++++++- docs/expense_receipts_v5.md | 15 +- docs/financial_document_v1.md | 19 ++- docs/french_healthcard_v1.md | 4 +- docs/idcard_fr_v2.md | 4 +- docs/ind_passport_v1.md | 4 +- docs/international_id_v2.md | 4 +- docs/invoices_v4.md | 19 ++- docs/license_plates_v1.md | 4 +- docs/multi_receipts_detector_v1.md | 4 +- docs/nutrition_facts_v1.md | 136 +++++++++++++++++- docs/passport_v1.md | 4 +- docs/payslip_fra_v3.md | 121 +++++++++++++++- docs/resume_v1.md | 78 +++++++++- docs/us_healthcare_cards_v1.md | 13 +- docs/us_mail_v3.md | 35 ++++- docs/us_w9_v1.md | 4 +- lib/mindee/client.rb | 29 +++- lib/mindee/geometry/utils.rb | 2 +- lib/mindee/image/extracted_image.rb | 2 +- lib/mindee/image/image_extractor.rb | 4 +- lib/mindee/image/image_utils.rb | 21 +-- lib/mindee/input/local_response.rb | 8 +- .../input/sources/base64_input_source.rb | 2 +- .../input/sources/local_input_source.rb | 8 +- lib/mindee/input/sources/url_input_source.rb | 4 +- lib/mindee/parsing/common/api_response.rb | 10 +- lib/mindee/parsing/common/document.rb | 8 +- lib/mindee/parsing/common/job.rb | 2 +- lib/mindee/parsing/common/ocr/mvision_v1.rb | 12 +- lib/mindee/parsing/common/ocr/ocr.rb | 52 +++---- lib/mindee/parsing/common/prediction.rb | 2 +- lib/mindee/parsing/standard/base_field.rb | 2 +- lib/mindee/parsing/standard/feature_field.rb | 2 +- lib/mindee/pdf/pdf_compressor.rb | 6 +- lib/mindee/pdf/pdf_extractor.rb | 6 +- lib/mindee/pdf/pdf_processor.rb | 29 ++-- lib/mindee/product/.rubocop.yml | 3 + .../barcode_reader_v1_document.rb | 6 +- .../bill_of_lading_v1_carrier_item.rb | 18 ++- .../bill_of_lading_v1_document.rb | 54 +++++-- .../business_card_v1_document.rb | 51 +++++-- lib/mindee/product/cropper/cropper_v1.rb | 2 +- lib/mindee/product/cropper/cropper_v1_page.rb | 4 +- .../delivery_note_v1_document.rb | 37 +++-- .../driver_license_v1_document.rb | 58 ++++++-- .../license_plate_v1_document.rb | 4 +- .../financial_document_v1_document.rb | 135 ++++++++++++----- .../financial_document_v1_line_item.rb | 30 ++-- .../bank_account_details_v1_document.rb | 11 +- .../bank_account_details_v2_document.rb | 16 ++- .../fr/bank_statement/bank_statement_v1.rb | 16 ++- .../bank_statement_v1_document.rb | 70 ++++++--- .../bank_statement/bank_statement_v1_page.rb | 16 ++- .../bank_statement_v1_transaction.rb | 17 ++- .../fr/carte_grise/carte_grise_v1_document.rb | 93 ++++++------ .../fr/energy_bill/energy_bill_v1_document.rb | 63 ++++++-- .../energy_bill_v1_energy_usage.rb | 18 ++- .../energy_bill_v1_subscription.rb | 18 ++- .../energy_bill_v1_taxes_and_contribution.rb | 18 ++- .../fr/health_card/health_card_v1_document.rb | 19 ++- .../product/fr/id_card/id_card_v1_document.rb | 43 ++++-- .../product/fr/id_card/id_card_v1_page.rb | 5 +- .../product/fr/id_card/id_card_v2_document.rb | 65 ++++++--- .../product/fr/id_card/id_card_v2_page.rb | 10 +- .../product/fr/payslip/payslip_v2_document.rb | 36 +++-- .../fr/payslip/payslip_v2_employment.rb | 3 +- .../fr/payslip/payslip_v2_pay_detail.rb | 42 ++++-- .../product/fr/payslip/payslip_v2_pto.rb | 15 +- .../fr/payslip/payslip_v2_salary_detail.rb | 18 ++- .../product/fr/payslip/payslip_v3_document.rb | 36 +++-- .../fr/payslip/payslip_v3_paid_time_off.rb | 18 ++- .../fr/payslip/payslip_v3_pay_detail.rb | 42 ++++-- .../fr/payslip/payslip_v3_salary_detail.rb | 24 ++-- .../indian_passport_v1_document.rb | 111 ++++++++++---- .../international_id_v2_document.rb | 78 +++++++--- .../product/invoice/invoice_v4_document.rb | 111 ++++++++++---- .../product/invoice/invoice_v4_line_item.rb | 30 ++-- .../invoice_splitter_v1_document.rb | 2 +- .../multi_receipts_detector_v1_document.rb | 8 +- .../nutrition_facts_label_v1_added_sugar.rb | 9 +- .../nutrition_facts_label_v1_calorie.rb | 9 +- .../nutrition_facts_label_v1_cholesterol.rb | 9 +- .../nutrition_facts_label_v1_dietary_fiber.rb | 9 +- .../nutrition_facts_label_v1_document.rb | 69 +++++++-- .../nutrition_facts_label_v1_nutrient.rb | 18 ++- .../nutrition_facts_label_v1_protein.rb | 9 +- .../nutrition_facts_label_v1_saturated_fat.rb | 9 +- .../nutrition_facts_label_v1_serving_size.rb | 3 +- .../nutrition_facts_label_v1_sodium.rb | 9 +- ...ition_facts_label_v1_total_carbohydrate.rb | 9 +- .../nutrition_facts_label_v1_total_fat.rb | 9 +- .../nutrition_facts_label_v1_total_sugar.rb | 9 +- .../nutrition_facts_label_v1_trans_fat.rb | 9 +- .../product/passport/passport_v1_document.rb | 48 +++++-- .../product/receipt/receipt_v5_document.rb | 69 ++++++--- .../product/receipt/receipt_v5_line_item.rb | 18 ++- .../product/resume/resume_v1_document.rb | 60 +++++--- .../product/universal/universal_prediction.rb | 13 +- .../us/bank_check/bank_check_v1_document.rb | 26 +++- .../us/bank_check/bank_check_v1_page.rb | 7 +- .../healthcare_card_v1_copay.rb | 6 +- .../healthcare_card_v1_document.rb | 56 ++++++-- .../product/us/us_mail/us_mail_v3_document.rb | 21 ++- lib/mindee/product/us/w9/w9_v1.rb | 2 +- lib/mindee/product/us/w9/w9_v1_page.rb | 53 +++++-- sig/custom/marcel.rbs | 3 + sig/custom/mini_magick.rbs | 16 ++- sig/custom/net_http.rbs | 12 +- sig/custom/origami.rbs | 7 +- sig/mindee/client.rbs | 4 +- sig/mindee/geometry/quadrilateral.rbs | 20 +-- sig/mindee/geometry/utils.rbs | 2 +- sig/mindee/image/extracted_image.rbs | 8 +- sig/mindee/image/image_compressor.rbs | 2 +- sig/mindee/image/image_utils.rbs | 24 ++-- .../input/sources/base64_input_source.rbs | 6 +- .../input/sources/bytes_input_source.rbs | 4 +- .../input/sources/file_input_source.rbs | 4 +- .../input/sources/local_input_source.rbs | 19 +-- .../input/sources/path_input_source.rbs | 4 +- sig/mindee/input/sources/url_input_source.rbs | 17 +-- sig/mindee/parsing/common/api_response.rbs | 12 +- sig/mindee/parsing/common/document.rbs | 2 +- sig/mindee/parsing/common/job.rbs | 12 +- sig/mindee/parsing/common/ocr/mvision_v1.rbs | 2 +- sig/mindee/parsing/common/ocr/ocr.rbs | 18 +-- sig/mindee/parsing/common/prediction.rbs | 2 +- .../parsing/standard/abstract_field.rbs | 18 +-- sig/mindee/parsing/standard/base_field.rbs | 6 +- sig/mindee/parsing/standard/boolean_field.rbs | 4 +- .../parsing/standard/classification_field.rbs | 4 +- sig/mindee/parsing/standard/feature_field.rbs | 4 +- sig/mindee/parsing/standard/locale_field.rbs | 12 +- sig/mindee/parsing/standard/string_field.rbs | 8 +- .../universal/universal_list_field.rbs | 10 +- sig/mindee/pdf/pdf_compressor.rbs | 10 +- sig/mindee/pdf/pdf_processor.rbs | 7 +- .../barcode_reader/barcode_reader_v1.rbs | 11 ++ .../barcode_reader_v1_document.rbs | 14 ++ .../barcode_reader/barcode_reader_v1_page.rbs | 15 ++ .../bill_of_lading/bill_of_lading_v1.rbs | 11 ++ .../bill_of_lading_v1_carrier.rbs | 14 ++ .../bill_of_lading_v1_carrier_item.rbs | 19 +++ .../bill_of_lading_v1_consignee.rbs | 15 ++ .../bill_of_lading_v1_document.rbs | 25 ++++ .../bill_of_lading_v1_notify_party.rbs | 15 ++ .../bill_of_lading/bill_of_lading_v1_page.rbs | 15 ++ .../bill_of_lading_v1_shipper.rbs | 15 ++ .../business_card/business_card_v1.rbs | 11 ++ .../business_card_v1_document.rbs | 23 +++ .../business_card/business_card_v1_page.rbs | 15 ++ sig/mindee/product/cropper/cropper_v1.rbs | 11 ++ .../product/cropper/cropper_v1_document.rbs | 12 ++ .../product/cropper/cropper_v1_page.rbs | 16 +++ .../delivery_note/delivery_note_v1.rbs | 11 ++ .../delivery_note_v1_document.rbs | 19 +++ .../delivery_note/delivery_note_v1_page.rbs | 15 ++ .../driver_license/driver_license_v1.rbs | 11 ++ .../driver_license_v1_document.rbs | 25 ++++ .../driver_license/driver_license_v1_page.rbs | 15 ++ .../eu/license_plate/license_plate_v1.rbs | 13 ++ .../license_plate_v1_document.rbs | 15 ++ .../license_plate/license_plate_v1_page.rbs | 17 +++ .../financial_document_v1.rbs | 11 ++ .../financial_document_v1_document.rbs | 46 ++++++ .../financial_document_v1_line_item.rbs | 21 +++ .../financial_document_v1_page.rbs | 15 ++ .../bank_account_details_v1.rbs | 13 ++ .../bank_account_details_v1_document.rbs | 17 +++ .../bank_account_details_v1_page.rbs | 17 +++ .../bank_account_details_v2.rbs | 13 ++ .../bank_account_details_v2_bban.rbs | 17 +++ .../bank_account_details_v2_document.rbs | 18 +++ .../bank_account_details_v2_page.rbs | 17 +++ .../fr/bank_statement/bank_statement_v1.rbs | 13 ++ .../bank_statement_v1_document.rbs | 29 ++++ .../bank_statement/bank_statement_v1_page.rbs | 17 +++ .../bank_statement_v1_transaction.rbs | 18 +++ .../product/fr/carte_grise/carte_grise_v1.rbs | 13 ++ .../carte_grise/carte_grise_v1_document.rbs | 55 +++++++ .../fr/carte_grise/carte_grise_v1_page.rbs | 17 +++ .../product/fr/energy_bill/energy_bill_v1.rbs | 13 ++ .../energy_bill/energy_bill_v1_document.rbs | 34 +++++ .../energy_bill_v1_energy_consumer.rbs | 15 ++ .../energy_bill_v1_energy_supplier.rbs | 15 ++ .../energy_bill_v1_energy_usage.rbs | 21 +++ .../energy_bill_v1_meter_detail.rbs | 16 +++ .../fr/energy_bill/energy_bill_v1_page.rbs | 17 +++ .../energy_bill_v1_subscription.rbs | 21 +++ .../energy_bill_v1_taxes_and_contribution.rbs | 21 +++ .../product/fr/health_card/health_card_v1.rbs | 13 ++ .../health_card/health_card_v1_document.rbs | 18 +++ .../fr/health_card/health_card_v1_page.rbs | 17 +++ sig/mindee/product/fr/id_card/id_card_v1.rbs | 13 ++ .../fr/id_card/id_card_v1_document.rbs | 24 ++++ .../product/fr/id_card/id_card_v1_page.rbs | 18 +++ sig/mindee/product/fr/id_card/id_card_v2.rbs | 13 ++ .../fr/id_card/id_card_v2_document.rbs | 29 ++++ .../product/fr/id_card/id_card_v2_page.rbs | 19 +++ sig/mindee/product/fr/payslip/payslip_v2.rbs | 13 ++ .../payslip_v2_bank_account_detail.rbs | 16 +++ .../fr/payslip/payslip_v2_document.rbs | 24 ++++ .../fr/payslip/payslip_v2_employee.rbs | 20 +++ .../fr/payslip/payslip_v2_employer.rbs | 20 +++ .../fr/payslip/payslip_v2_employment.rbs | 19 +++ .../product/fr/payslip/payslip_v2_page.rbs | 17 +++ .../fr/payslip/payslip_v2_pay_detail.rbs | 23 +++ .../fr/payslip/payslip_v2_pay_period.rbs | 18 +++ .../product/fr/payslip/payslip_v2_pto.rbs | 16 +++ .../fr/payslip/payslip_v2_salary_detail.rbs | 19 +++ sig/mindee/product/fr/payslip/payslip_v3.rbs | 13 ++ .../payslip_v3_bank_account_detail.rbs | 16 +++ .../fr/payslip/payslip_v3_document.rbs | 26 ++++ .../fr/payslip/payslip_v3_employee.rbs | 20 +++ .../fr/payslip/payslip_v3_employer.rbs | 20 +++ .../fr/payslip/payslip_v3_employment.rbs | 20 +++ .../product/fr/payslip/payslip_v3_page.rbs | 17 +++ .../fr/payslip/payslip_v3_paid_time_off.rbs | 20 +++ .../fr/payslip/payslip_v3_pay_detail.rbs | 23 +++ .../fr/payslip/payslip_v3_pay_period.rbs | 18 +++ .../fr/payslip/payslip_v3_salary_detail.rbs | 20 +++ .../indian_passport/indian_passport_v1.rbs | 13 ++ .../indian_passport_v1_document.rbs | 37 +++++ .../indian_passport_v1_page.rbs | 17 +++ .../international_id/international_id_v2.rbs | 11 ++ .../international_id_v2_document.rbs | 29 ++++ .../international_id_v2_page.rbs | 15 ++ sig/mindee/product/invoice/invoice_v4.rbs | 11 ++ .../product/invoice/invoice_v4_document.rbs | 40 ++++++ .../product/invoice/invoice_v4_line_item.rbs | 21 +++ .../product/invoice/invoice_v4_page.rbs | 15 ++ .../invoice_splitter/invoice_splitter_v1.rbs | 10 +- .../invoice_splitter_v1_document.rbs | 10 +- .../invoice_splitter_v1_page.rbs | 2 +- .../multi_receipts_detector_v1.rbs | 7 +- .../multi_receipts_detector_v1_document.rbs | 5 +- .../multi_receipts_detector_v1_page.rbs | 4 +- .../nutrition_facts_label_v1.rbs | 11 ++ .../nutrition_facts_label_v1_added_sugar.rbs | 14 ++ .../nutrition_facts_label_v1_calorie.rbs | 14 ++ .../nutrition_facts_label_v1_cholesterol.rbs | 14 ++ ...nutrition_facts_label_v1_dietary_fiber.rbs | 14 ++ .../nutrition_facts_label_v1_document.rbs | 28 ++++ .../nutrition_facts_label_v1_nutrient.rbs | 18 +++ .../nutrition_facts_label_v1_page.rbs | 15 ++ .../nutrition_facts_label_v1_protein.rbs | 14 ++ ...nutrition_facts_label_v1_saturated_fat.rbs | 14 ++ .../nutrition_facts_label_v1_serving_size.rbs | 13 ++ .../nutrition_facts_label_v1_sodium.rbs | 15 ++ ...tion_facts_label_v1_total_carbohydrate.rbs | 14 ++ .../nutrition_facts_label_v1_total_fat.rbs | 14 ++ .../nutrition_facts_label_v1_total_sugar.rbs | 14 ++ .../nutrition_facts_label_v1_trans_fat.rbs | 14 ++ sig/mindee/product/passport/passport_v1.rbs | 11 ++ .../product/passport/passport_v1_document.rbs | 23 +++ .../product/passport/passport_v1_page.rbs | 15 ++ sig/mindee/product/receipt/receipt_v5.rbs | 11 ++ .../product/receipt/receipt_v5_document.rbs | 31 ++++ .../product/receipt/receipt_v5_line_item.rbs | 17 +++ .../product/receipt/receipt_v5_page.rbs | 15 ++ sig/mindee/product/resume/resume_v1.rbs | 11 ++ .../product/resume/resume_v1_certificate.rbs | 17 +++ .../product/resume/resume_v1_document.rbs | 39 +++++ .../product/resume/resume_v1_education.rbs | 20 +++ .../product/resume/resume_v1_language.rbs | 15 ++ sig/mindee/product/resume/resume_v1_page.rbs | 15 ++ .../resume_v1_professional_experience.rbs | 22 +++ .../resume/resume_v1_social_networks_url.rbs | 15 ++ .../product/universal/universal_document.rbs | 2 +- .../product/universal/universal_page.rbs | 4 +- .../universal/universal_prediction.rbs | 10 +- .../product/us/bank_check/bank_check_v1.rbs | 13 ++ .../us/bank_check/bank_check_v1_document.rbs | 20 +++ .../us/bank_check/bank_check_v1_page.rbs | 19 +++ .../us/healthcare_card/healthcare_card_v1.rbs | 13 ++ .../healthcare_card_v1_copay.rbs | 17 +++ .../healthcare_card_v1_document.rbs | 28 ++++ .../healthcare_card_v1_page.rbs | 17 +++ sig/mindee/product/us/us_mail/us_mail_v3.rbs | 13 ++ .../us/us_mail/us_mail_v3_document.rbs | 21 +++ .../product/us/us_mail/us_mail_v3_page.rbs | 17 +++ .../us_mail/us_mail_v3_recipient_address.rbs | 23 +++ .../us/us_mail/us_mail_v3_sender_address.rbs | 18 +++ sig/mindee/product/us/w9/w9_v1.rbs | 13 ++ sig/mindee/product/us/w9/w9_v1_document.rbs | 14 ++ sig/mindee/product/us/w9/w9_v1_page.rbs | 29 ++++ spec/document/fr/bank_statement_v1_spec.rb | 2 +- spec/extras/full_text_ocr_spec.rb | 3 +- spec/ocr_spec.rb | 2 +- spec/pdf/pdf_processor_spec.rb | 80 +++++------ 305 files changed, 5056 insertions(+), 962 deletions(-) create mode 100644 docs/code_samples/bank_statement_fr_v1_async.txt create mode 100644 sig/custom/marcel.rbs create mode 100644 sig/mindee/product/barcode_reader/barcode_reader_v1.rbs create mode 100644 sig/mindee/product/barcode_reader/barcode_reader_v1_document.rbs create mode 100644 sig/mindee/product/barcode_reader/barcode_reader_v1_page.rbs create mode 100644 sig/mindee/product/bill_of_lading/bill_of_lading_v1.rbs create mode 100644 sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rbs create mode 100644 sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rbs create mode 100644 sig/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rbs create mode 100644 sig/mindee/product/bill_of_lading/bill_of_lading_v1_document.rbs create mode 100644 sig/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rbs create mode 100644 sig/mindee/product/bill_of_lading/bill_of_lading_v1_page.rbs create mode 100644 sig/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rbs create mode 100644 sig/mindee/product/business_card/business_card_v1.rbs create mode 100644 sig/mindee/product/business_card/business_card_v1_document.rbs create mode 100644 sig/mindee/product/business_card/business_card_v1_page.rbs create mode 100644 sig/mindee/product/cropper/cropper_v1.rbs create mode 100644 sig/mindee/product/cropper/cropper_v1_document.rbs create mode 100644 sig/mindee/product/cropper/cropper_v1_page.rbs create mode 100644 sig/mindee/product/delivery_note/delivery_note_v1.rbs create mode 100644 sig/mindee/product/delivery_note/delivery_note_v1_document.rbs create mode 100644 sig/mindee/product/delivery_note/delivery_note_v1_page.rbs create mode 100644 sig/mindee/product/driver_license/driver_license_v1.rbs create mode 100644 sig/mindee/product/driver_license/driver_license_v1_document.rbs create mode 100644 sig/mindee/product/driver_license/driver_license_v1_page.rbs create mode 100644 sig/mindee/product/eu/license_plate/license_plate_v1.rbs create mode 100644 sig/mindee/product/eu/license_plate/license_plate_v1_document.rbs create mode 100644 sig/mindee/product/eu/license_plate/license_plate_v1_page.rbs create mode 100644 sig/mindee/product/financial_document/financial_document_v1.rbs create mode 100644 sig/mindee/product/financial_document/financial_document_v1_document.rbs create mode 100644 sig/mindee/product/financial_document/financial_document_v1_line_item.rbs create mode 100644 sig/mindee/product/financial_document/financial_document_v1_page.rbs create mode 100644 sig/mindee/product/fr/bank_account_details/bank_account_details_v1.rbs create mode 100644 sig/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rbs create mode 100644 sig/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rbs create mode 100644 sig/mindee/product/fr/bank_account_details/bank_account_details_v2.rbs create mode 100644 sig/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rbs create mode 100644 sig/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rbs create mode 100644 sig/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rbs create mode 100644 sig/mindee/product/fr/bank_statement/bank_statement_v1.rbs create mode 100644 sig/mindee/product/fr/bank_statement/bank_statement_v1_document.rbs create mode 100644 sig/mindee/product/fr/bank_statement/bank_statement_v1_page.rbs create mode 100644 sig/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rbs create mode 100644 sig/mindee/product/fr/carte_grise/carte_grise_v1.rbs create mode 100644 sig/mindee/product/fr/carte_grise/carte_grise_v1_document.rbs create mode 100644 sig/mindee/product/fr/carte_grise/carte_grise_v1_page.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_document.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_page.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rbs create mode 100644 sig/mindee/product/fr/health_card/health_card_v1.rbs create mode 100644 sig/mindee/product/fr/health_card/health_card_v1_document.rbs create mode 100644 sig/mindee/product/fr/health_card/health_card_v1_page.rbs create mode 100644 sig/mindee/product/fr/id_card/id_card_v1.rbs create mode 100644 sig/mindee/product/fr/id_card/id_card_v1_document.rbs create mode 100644 sig/mindee/product/fr/id_card/id_card_v1_page.rbs create mode 100644 sig/mindee/product/fr/id_card/id_card_v2.rbs create mode 100644 sig/mindee/product/fr/id_card/id_card_v2_document.rbs create mode 100644 sig/mindee/product/fr/id_card/id_card_v2_page.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_document.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_employee.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_employer.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_employment.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_page.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_pay_detail.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_pay_period.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_pto.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_salary_detail.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_document.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_employee.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_employer.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_employment.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_page.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_paid_time_off.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_pay_detail.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_pay_period.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_salary_detail.rbs create mode 100644 sig/mindee/product/ind/indian_passport/indian_passport_v1.rbs create mode 100644 sig/mindee/product/ind/indian_passport/indian_passport_v1_document.rbs create mode 100644 sig/mindee/product/ind/indian_passport/indian_passport_v1_page.rbs create mode 100644 sig/mindee/product/international_id/international_id_v2.rbs create mode 100644 sig/mindee/product/international_id/international_id_v2_document.rbs create mode 100644 sig/mindee/product/international_id/international_id_v2_page.rbs create mode 100644 sig/mindee/product/invoice/invoice_v4.rbs create mode 100644 sig/mindee/product/invoice/invoice_v4_document.rbs create mode 100644 sig/mindee/product/invoice/invoice_v4_line_item.rbs create mode 100644 sig/mindee/product/invoice/invoice_v4_page.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rbs create mode 100644 sig/mindee/product/passport/passport_v1.rbs create mode 100644 sig/mindee/product/passport/passport_v1_document.rbs create mode 100644 sig/mindee/product/passport/passport_v1_page.rbs create mode 100644 sig/mindee/product/receipt/receipt_v5.rbs create mode 100644 sig/mindee/product/receipt/receipt_v5_document.rbs create mode 100644 sig/mindee/product/receipt/receipt_v5_line_item.rbs create mode 100644 sig/mindee/product/receipt/receipt_v5_page.rbs create mode 100644 sig/mindee/product/resume/resume_v1.rbs create mode 100644 sig/mindee/product/resume/resume_v1_certificate.rbs create mode 100644 sig/mindee/product/resume/resume_v1_document.rbs create mode 100644 sig/mindee/product/resume/resume_v1_education.rbs create mode 100644 sig/mindee/product/resume/resume_v1_language.rbs create mode 100644 sig/mindee/product/resume/resume_v1_page.rbs create mode 100644 sig/mindee/product/resume/resume_v1_professional_experience.rbs create mode 100644 sig/mindee/product/resume/resume_v1_social_networks_url.rbs create mode 100644 sig/mindee/product/us/bank_check/bank_check_v1.rbs create mode 100644 sig/mindee/product/us/bank_check/bank_check_v1_document.rbs create mode 100644 sig/mindee/product/us/bank_check/bank_check_v1_page.rbs create mode 100644 sig/mindee/product/us/healthcare_card/healthcare_card_v1.rbs create mode 100644 sig/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rbs create mode 100644 sig/mindee/product/us/healthcare_card/healthcare_card_v1_document.rbs create mode 100644 sig/mindee/product/us/healthcare_card/healthcare_card_v1_page.rbs create mode 100644 sig/mindee/product/us/us_mail/us_mail_v3.rbs create mode 100644 sig/mindee/product/us/us_mail/us_mail_v3_document.rbs create mode 100644 sig/mindee/product/us/us_mail/us_mail_v3_page.rbs create mode 100644 sig/mindee/product/us/us_mail/us_mail_v3_recipient_address.rbs create mode 100644 sig/mindee/product/us/us_mail/us_mail_v3_sender_address.rbs create mode 100644 sig/mindee/product/us/w9/w9_v1.rbs create mode 100644 sig/mindee/product/us/w9/w9_v1_document.rbs create mode 100644 sig/mindee/product/us/w9/w9_v1_page.rbs diff --git a/README.md b/README.md index a0295c7e..456231c5 100644 --- a/README.md +++ b/README.md @@ -149,15 +149,8 @@ result.document.inference.prediction.fields.each do |field_name, field_data| puts field_data.to_s end ``` -## Asynchronously Parsing a File +## Enqueue and Parse a Webhook Response -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. - - -### Enqueue and Parse a Webhook Response This is an optional way of handling asynchronous APIs. ```rb diff --git a/Steepfile b/Steepfile index 0ab6a478..ed43b765 100644 --- a/Steepfile +++ b/Steepfile @@ -4,40 +4,24 @@ D = Steep::Diagnostic target :lib do signature 'sig/custom/*.rbs' - signature 'sig/mindee/*.rbs' - signature 'sig/mindee/http/*.rbs' - signature 'sig/mindee/geometry/*.rbs' - signature 'sig/mindee/errors/*.rbs' - signature 'sig/mindee/extraction/*.rbs' - signature 'sig/mindee/image/**/*.rbs' - signature 'sig/mindee/logging/**/*.rbs' - signature 'sig/mindee/parsing/**/*.rbs' - signature 'sig/mindee/pdf/**/*.rbs' - signature 'sig/mindee/product/invoice_splitter/*.rbs' - signature 'sig/mindee/product/multi_receipts_detector/*.rbs' - signature 'sig/mindee/product/universal/*.rbs' - signature 'sig/mindee/input/**/*.rbs' + signature 'sig/mindee/**/*.rbs' - check 'lib/mindee/*.rb' - check 'lib/mindee/http/*.rb' - check 'lib/mindee/geometry/*.rb' - check 'lib/mindee/errors/*.rb' - check 'lib/mindee/extraction/*.rb' - check 'lib/mindee/image/**/*.rb' - check 'lib/mindee/logging/**/*.rb' - check 'lib/mindee/parsing/**/*.rb' - check 'lib/mindee/pdf/**/*.rb' - check 'lib/mindee/product/invoice_splitter/*.rb' - check 'lib/mindee/product/multi_receipts_detector/*.rb' - check 'lib/mindee/product/universal/*.rb' - check 'lib/mindee/input/**/*.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 'logger' library 'json' - # library 'net/http' # NOTE: Steep does not support net/http. Do NOT enable. - # Use the stub located at sig/custom/net_http.rbs instead. + library 'openssl' library 'pathname' + library 'tempfile' library 'time' library 'uri' diff --git a/bin/mindee.rb b/bin/mindee.rb index 2240b5c2..8cda0c98 100755 --- a/bin/mindee.rb +++ b/bin/mindee.rb @@ -123,11 +123,6 @@ } options = {} -DEFAULT_CUTTING = { - page_indexes: [0, 1, 2, 3, 4], - operation: :KEEP_ONLY, - on_min_pages: 0, -} # Initializes universal-specific options # @param cli_parser [OptionParser] @@ -146,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| @@ -218,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 @@ -230,7 +234,7 @@ def custom_subcommand(cli_parser, options) input_source, doc_class, options: { endpoint: custom_endpoint, - page_options: page_options, enqueue: options[:parse_async] } + options: Mindee::ParseOptions.new(params: { page_options: page_options }), enqueue: options[:parse_async] } ) if options[:print_full] diff --git a/docs/bank_account_details_v2.md b/docs/bank_account_details_v2.md index 7497034b..1c88b518 100644 --- a/docs/bank_account_details_v2.md +++ b/docs/bank_account_details_v2.md @@ -79,12 +79,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. @@ -100,6 +100,17 @@ Full extraction of BBAN, including: branch code, bank code, account and key. A `BankAccountDetailsV2Bban` implements the following attributes: +* `bban_bank_code` (String): The BBAN bank code outputted as a string. +* `bban_branch_code` (String): The BBAN branch code outputted as a string. +* `bban_key` (String): The BBAN key outputted as a string. +* `bban_number` (String): The BBAN Account number outputted as a string. +Fields which are specific to this product; they are not used in any other product. + +### Basic Bank Account Number Field +Full extraction of BBAN, including: branch code, bank code, account and key. + +A `BankAccountDetailsV2Bban` implements the following attributes: + * `bban_bank_code` (String): The BBAN bank code outputted as a string. * `bban_branch_code` (String): The BBAN branch code outputted as a string. * `bban_key` (String): The BBAN key outputted as a string. diff --git a/docs/bank_check_v1.md b/docs/bank_check_v1.md index 4c3854c1..6756e6ca 100644 --- a/docs/bank_check_v1.md +++ b/docs/bank_check_v1.md @@ -79,12 +79,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_statement_fr_v1.md b/docs/bank_statement_fr_v1.md index 0344d488..53f40a20 100644 --- a/docs/bank_statement_fr_v1.md +++ b/docs/bank_statement_fr_v1.md @@ -1,13 +1,13 @@ --- -title: FR Bank Statement (FR) OCR Ruby +title: FR Bank Statement 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). +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. -![Bank Statement (FR) sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_statement_fr/default_sample.jpg?raw=true) +![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 @@ -34,6 +34,65 @@ puts result.document **Output (RST):** ```rst +######## +Document +######## +:Mindee ID: b9bdb0fd-87bd-4a76-b488-1da3ce53d11d +:Filename: default_sample.jpg + +Inference +######### +:Product: mindee/bank_statement_fr v1.0 +:Rotation applied: No + +Prediction +========== +:Account Number: XXXXXXXXXXXXX +:Bank Name: lafinancepourtous +:Bank Address: 1 rue de la Banque, 100210 Cassette +:Client Name: Karine Plume +:Client Address: 1 rue des Cigales, 100210 Cassette +:Statement Date: 2002-02-28 +:Statement Start Date: 2002-02-01 +:Statement End Date: 2002-02-28 +:Opening Balance: 22.15 +:Closing Balance: -278.96 +:Transactions: + +-----------+------------+--------------------------------------+ + | Amount | Date | Description | + +===========+============+======================================+ + | 1240.00 | 2002-02-01 | Virement salaire | + +-----------+------------+--------------------------------------+ + | 520.00 | 2002-02-02 | Virement loyer | + +-----------+------------+--------------------------------------+ + | -312.00 | 2002-02-03 | Débit Carte nºxxxxx xxxxxxxxxxxx | + +-----------+------------+--------------------------------------+ + | 65.00 | 2002-02-05 | Virement APL | + +-----------+------------+--------------------------------------+ + | -3.30 | 2002-02-08 | Cotisation mensuelle carte bancaire | + +-----------+------------+--------------------------------------+ + | -120.00 | 2002-02-09 | Chèque nº xxxxxxx98 | + +-----------+------------+--------------------------------------+ + | -60.00 | 2002-02-09 | Retrait espèces DAB | + +-----------+------------+--------------------------------------+ + | -55.00 | 2002-02-15 | Chèque n ° xxxxxxXx99 | + +-----------+------------+--------------------------------------+ + | -80.00 | 2002-02-16 | Prélèvement supercrédit | + +-----------+------------+--------------------------------------+ + | -120.00 | 2002-02-17 | Chèque n ° xxxxx100 | + +-----------+------------+--------------------------------------+ + | -163.25 | 2002-02-20 | Débit Carte n ° xxxxxxxxxxxxxxxxxx | + +-----------+------------+--------------------------------------+ + | -25.50 | 2002-02-21 | Débit Carte nºxxxxxxxxxxxxxxxxx | + +-----------+------------+--------------------------------------+ + | -30.00 | 2002-02-24 | Prélèvement Opérateur téléphonique | + +-----------+------------+--------------------------------------+ + | -6.53 | 2002-02-25 | Agios | + +-----------+------------+--------------------------------------+ + | -13.00 | 2002-02-28 | Frais irrégularités et incidents ... | + +-----------+------------+--------------------------------------+ +:Total Debits: 1618.58 +:Total Credits: 1339.62 ``` # Field Types @@ -44,12 +103,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, is `nil` when at document-level. -* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). +* **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. +* **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. @@ -74,12 +133,22 @@ The list of values that represent the financial transactions recorded in a bank 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. +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: +The following fields are extracted for Bank Statement V1: ## Account Number **account_number** ([StringField](#string-field)): The unique identifier for a customer's account in the bank's system. diff --git a/docs/barcode_reader_v1.md b/docs/barcode_reader_v1.md index 98ff5de7..c512a5f0 100644 --- a/docs/barcode_reader_v1.md +++ b/docs/barcode_reader_v1.md @@ -69,12 +69,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/bill_of_lading_v1.md b/docs/bill_of_lading_v1.md index ae2b02dd..49b4ef8a 100644 --- a/docs/bill_of_lading_v1.md +++ b/docs/bill_of_lading_v1.md @@ -88,12 +88,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. @@ -119,6 +119,27 @@ A `BillOfLadingV1Carrier` implements the following attributes: * `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. +### Carrier Field +The shipping company responsible for transporting the goods. + +A `BillOfLadingV1Carrier` 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. +Fields which are specific to this product; they are not used in any other product. + +### Consignee Field +The party to whom the goods are being shipped. + +A `BillOfLadingV1Consignee` implements the following attributes: + +* `address` (String): The address of the consignee. +* `email` (String): The email of the shipper. +* `name` (String): The name of the consignee. +* `phone` (String): The phone number of the consignee. +Fields which are specific to this product; they are not used in any other product. + ### Consignee Field The party to whom the goods are being shipped. @@ -143,6 +164,30 @@ A `BillOfLadingV1CarrierItem` implements the following attributes: * `weight_unit` (String): The unit of measurement for weights. 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. + +A `BillOfLadingV1NotifyParty` implements the following attributes: + +* `address` (String): The address of the notify party. +* `email` (String): The email of the shipper. +* `name` (String): The name of the notify party. +* `phone` (String): The phone number of the notify party. +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. @@ -159,6 +204,17 @@ The party responsible for shipping the goods. A `BillOfLadingV1Shipper` 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. +Fields which are specific to this product; they are not used in any other product. + +### Shipper Field +The party responsible for shipping the goods. + +A `BillOfLadingV1Shipper` 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. diff --git a/docs/business_card_v1.md b/docs/business_card_v1.md index ac5ec510..b8da6bdb 100644 --- a/docs/business_card_v1.md +++ b/docs/business_card_v1.md @@ -69,12 +69,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/carte_grise_v1.md b/docs/carte_grise_v1.md index ac31ce66..23fec839 100644 --- a/docs/carte_grise_v1.md +++ b/docs/carte_grise_v1.md @@ -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. diff --git a/docs/code_samples/bank_statement_fr_v1_async.txt b/docs/code_samples/bank_statement_fr_v1_async.txt new file mode 100644 index 00000000..76002339 --- /dev/null +++ b/docs/code_samples/bank_statement_fr_v1_async.txt @@ -0,0 +1,19 @@ +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::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/cropper_v1.md b/docs/cropper_v1.md index d8591056..55f49b36 100644 --- a/docs/cropper_v1.md +++ b/docs/cropper_v1.md @@ -62,12 +62,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/delivery_notes_v1.md b/docs/delivery_notes_v1.md index 4336a929..874c659b 100644 --- a/docs/delivery_notes_v1.md +++ b/docs/delivery_notes_v1.md @@ -64,12 +64,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/driver_license_v1.md b/docs/driver_license_v1.md index eeb57d20..72f1bcf6 100644 --- a/docs/driver_license_v1.md +++ b/docs/driver_license_v1.md @@ -70,12 +70,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/energy_bill_fra_v1.md b/docs/energy_bill_fra_v1.md index 4af3c00b..d74ed066 100644 --- a/docs/energy_bill_fra_v1.md +++ b/docs/energy_bill_fra_v1.md @@ -99,12 +99,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. @@ -133,6 +133,24 @@ 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 Consumer Field +The entity that consumes the energy. + +A `EnergyBillV1EnergyConsumer` implements the following attributes: + +* `address` (String): The address of the energy consumer. +* `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. + +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 Supplier Field The company that supplies the energy. @@ -155,6 +173,36 @@ 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. +### Energy Usage Field +Details of energy consumption. + +A `EnergyBillV1EnergyUsage` implements the following attributes: + +* `description` (String): Description or details of the energy usage. +* `end_date` (String): The end date of the energy usage. +* `start_date` (String): The start date of the energy usage. +* `tax_rate` (Float): The rate of tax applied to the total cost. +* `total` (Float): The total cost of energy consumed. +* `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. + +### Meter Details Field +Information about the energy meter. + +A `EnergyBillV1MeterDetail` implements the following attributes: + +* `meter_number` (String): The unique identifier of the energy meter. +* `meter_type` (String): The type of energy meter. + +#### Possible values include: + - electricity + - 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. + ### Meter Details Field Information about the energy meter. @@ -185,6 +233,32 @@ A `EnergyBillV1Subscription` implements the following attributes: * `unit_price` (Float): The price per unit of subscription. 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. +Fields which are specific to this product; they are not used in any other product. + ### Taxes and Contributions Field Details of Taxes and Contributions. diff --git a/docs/expense_receipts_v5.md b/docs/expense_receipts_v5.md index 09dc85c5..e1ee889e 100644 --- a/docs/expense_receipts_v5.md +++ b/docs/expense_receipts_v5.md @@ -119,12 +119,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. @@ -181,6 +181,17 @@ List of line item details. A `ReceiptV5LineItem` implements the following attributes: +* `description` (String): The item description. +* `quantity` (Float): The item quantity. +* `total_amount` (Float): The item total amount. +* `unit_price` (Float): The item unit price. +Fields which are specific to this product; they are not used in any other product. + +### Line Items Field +List of line item details. + +A `ReceiptV5LineItem` implements the following attributes: + * `description` (String): The item description. * `quantity` (Float): The item quantity. * `total_amount` (Float): The item total amount. diff --git a/docs/financial_document_v1.md b/docs/financial_document_v1.md index f7db6832..d38114b7 100644 --- a/docs/financial_document_v1.md +++ b/docs/financial_document_v1.md @@ -155,12 +155,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. @@ -225,6 +225,21 @@ List of line item details. A `FinancialDocumentV1LineItem` implements the following attributes: +* `description` (String): The item description. +* `product_code` (String): The product code referring to the item. +* `quantity` (Float): The item quantity +* `tax_amount` (Float): The item tax amount. +* `tax_rate` (Float): The item tax rate in percentage. +* `total_amount` (Float): The item total amount. +* `unit_measure` (String): The item unit of measure. +* `unit_price` (Float): The item unit price. +Fields which are specific to this product; they are not used in any other product. + +### Line Items Field +List of line item details. + +A `FinancialDocumentV1LineItem` implements the following attributes: + * `description` (String): The item description. * `product_code` (String): The product code referring to the item. * `quantity` (Float): The item quantity diff --git a/docs/french_healthcard_v1.md b/docs/french_healthcard_v1.md index 21a19bbd..3a55f65a 100644 --- a/docs/french_healthcard_v1.md +++ b/docs/french_healthcard_v1.md @@ -61,12 +61,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/idcard_fr_v2.md b/docs/idcard_fr_v2.md index c63f310c..c4bf9bd9 100644 --- a/docs/idcard_fr_v2.md +++ b/docs/idcard_fr_v2.md @@ -97,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/ind_passport_v1.md b/docs/ind_passport_v1.md index b505185c..4f53c759 100644 --- a/docs/ind_passport_v1.md +++ b/docs/ind_passport_v1.md @@ -80,12 +80,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/international_id_v2.md b/docs/international_id_v2.md index b8298ddd..9d2bf4fb 100644 --- a/docs/international_id_v2.md +++ b/docs/international_id_v2.md @@ -75,12 +75,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/invoices_v4.md b/docs/invoices_v4.md index 36f77a20..15a0d645 100644 --- a/docs/invoices_v4.md +++ b/docs/invoices_v4.md @@ -143,12 +143,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. @@ -213,6 +213,21 @@ List of line item details. A `InvoiceV4LineItem` implements the following attributes: +* `description` (String): The item description. +* `product_code` (String): The product code referring to the item. +* `quantity` (Float): The item quantity +* `tax_amount` (Float): The item tax amount. +* `tax_rate` (Float): The item tax rate in percentage. +* `total_amount` (Float): The item total amount. +* `unit_measure` (String): The item unit of measure. +* `unit_price` (Float): The item unit price. +Fields which are specific to this product; they are not used in any other product. + +### Line Items Field +List of line item details. + +A `InvoiceV4LineItem` implements the following attributes: + * `description` (String): The item description. * `product_code` (String): The product code referring to the item. * `quantity` (Float): The item quantity diff --git a/docs/license_plates_v1.md b/docs/license_plates_v1.md index 7dc3c0b2..b8e268c1 100644 --- a/docs/license_plates_v1.md +++ b/docs/license_plates_v1.md @@ -65,12 +65,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/multi_receipts_detector_v1.md b/docs/multi_receipts_detector_v1.md index 7e766e35..be9cc19d 100644 --- a/docs/multi_receipts_detector_v1.md +++ b/docs/multi_receipts_detector_v1.md @@ -75,12 +75,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/nutrition_facts_v1.md b/docs/nutrition_facts_v1.md index 9890c0a0..877366f0 100644 --- a/docs/nutrition_facts_v1.md +++ b/docs/nutrition_facts_v1.md @@ -118,12 +118,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. @@ -145,6 +145,16 @@ A `NutritionFactsLabelV1AddedSugar` implements the following attributes: * `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. +### Added Sugars Field +The amount of added sugars in the product. + +A `NutritionFactsLabelV1AddedSugar` 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. +Fields which are specific to this product; they are not used in any other product. + ### Calories Field The amount of calories in the product. @@ -155,6 +165,26 @@ 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. +### Calories Field +The amount of calories in the product. + +A `NutritionFactsLabelV1Calorie` implements the following attributes: + +* `daily_value` (Float): DVs are the recommended amounts of calories to consume or not to exceed each day. +* `per_100g` (Float): The amount of calories per 100g of the product. +* `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. + ### Cholesterol Field The amount of cholesterol in the product. @@ -175,6 +205,16 @@ A `NutritionFactsLabelV1DietaryFiber` implements the following attributes: * `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. +### 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. @@ -187,6 +227,28 @@ A `NutritionFactsLabelV1Nutrient` implements the following attributes: * `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. +### 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. + +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. + ### Protein Field The amount of protein in the product. @@ -207,6 +269,25 @@ 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. +### Saturated Fat Field +The amount of saturated fat in the product. + +A `NutritionFactsLabelV1SaturatedFat` implements the following attributes: + +* `daily_value` (Float): DVs are the recommended amounts of saturated fat to consume or not to exceed each day. +* `per_100g` (Float): The amount of saturated fat per 100g of the product. +* `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. + +A `NutritionFactsLabelV1ServingSize` implements the following attributes: + +* `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. + ### Serving Size Field The size of a single serving of the product. @@ -227,6 +308,27 @@ A `NutritionFactsLabelV1Sodium` implements the following attributes: * `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. +### 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. + +### Total Carbohydrate Field +The total amount of carbohydrates in the product. + +A `NutritionFactsLabelV1TotalCarbohydrate` implements the following attributes: + +* `daily_value` (Float): DVs are the recommended amounts of total carbohydrates to consume or not to exceed each day. +* `per_100g` (Float): The amount of total carbohydrates per 100g of the product. +* `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 Carbohydrate Field The total amount of carbohydrates in the product. @@ -247,6 +349,16 @@ A `NutritionFactsLabelV1TotalFat` implements the following attributes: * `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. +### Total Fat Field +The total amount of fat in the product. + +A `NutritionFactsLabelV1TotalFat` 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. +Fields which are specific to this product; they are not used in any other product. + ### Total Sugars Field The total amount of sugars in the product. @@ -257,6 +369,26 @@ 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. +### Total Sugars Field +The total amount of sugars in the product. + +A `NutritionFactsLabelV1TotalSugar` implements the following attributes: + +* `daily_value` (Float): DVs are the recommended amounts of total sugars to consume or not to exceed each day. +* `per_100g` (Float): The amount of total sugars per 100g of the product. +* `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. + +A `NutritionFactsLabelV1TransFat` 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. +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. diff --git a/docs/passport_v1.md b/docs/passport_v1.md index 795d18b7..c03964db 100644 --- a/docs/passport_v1.md +++ b/docs/passport_v1.md @@ -85,12 +85,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/payslip_fra_v3.md b/docs/payslip_fra_v3.md index 1796bab4..f27dd5d8 100644 --- a/docs/payslip_fra_v3.md +++ b/docs/payslip_fra_v3.md @@ -122,12 +122,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. @@ -145,6 +145,30 @@ A `PayslipV3BankAccountDetail` implements the following attributes: * `swift` (String): The SWIFT code of the bank. 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. + +### Employee Field +Information about the employee. + +A `PayslipV3Employee` 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. + ### Employee Field Information about the employee. @@ -173,6 +197,34 @@ 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. +### Employer Field +Information about the employer. + +A `PayslipV3Employer` 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 `PayslipV3Employment` implements the following attributes: + +* `category` (String): The category of the employment. +* `coefficient` (String): 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. +* `seniority_date` (String): The seniority date 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. + ### Employment Field Information about the employment. @@ -211,6 +263,47 @@ A `PayslipV3PaidTimeOff` implements the following attributes: * `used` (Float): The amount of paid time off used in the period. 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. + +#### 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. +Fields which are specific to this product; they are not used in any other product. + +### Pay Detail Field +Detailed information about the pay. + +A `PayslipV3PayDetail` 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 Detail Field Detailed information about the pay. @@ -240,6 +333,30 @@ A `PayslipV3PayPeriod` implements the following attributes: * `year` (String): The year of the pay period. 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: + +* `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. + +### Salary Details Field +Detailed information about the earnings. + +A `PayslipV3SalaryDetail` implements the following attributes: + +* `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. + ### Salary Details Field Detailed information about the earnings. diff --git a/docs/resume_v1.md b/docs/resume_v1.md index 6ed2eebe..ba38141f 100644 --- a/docs/resume_v1.md +++ b/docs/resume_v1.md @@ -113,12 +113,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. @@ -146,6 +146,17 @@ A `ResumeV1Certificate` implements the following attributes: * `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. +### 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. @@ -160,6 +171,37 @@ A `ResumeV1Education` implements the following attributes: * `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. +### 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. + +### Languages Field +The list of languages that the candidate is proficient in. + +A `ResumeV1Language` implements the following attributes: + +* `language` (String): The language's ISO 639 code. +* `level` (String): The candidate's level for the language. + +#### Possible values include: + - Native + - Fluent + - Proficient + - Intermediate + - Beginner + +Fields which are specific to this product; they are not used in any other product. + ### Languages Field The list of languages that the candidate is proficient in. @@ -200,6 +242,38 @@ 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. +### Professional Experiences Field +The list of the candidate's professional experiences. + +A `ResumeV1ProfessionalExperience` implements the following attributes: + +* `contract_type` (String): The type of contract for the professional experience. + +#### Possible values include: + - Full-Time + - 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. +* `end_month` (String): The month when the professional experience ended. +* `end_year` (String): The year when the professional experience ended. +* `role` (String): The position or job title held by the candidate. +* `start_month` (String): The month when the professional experience began. +* `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. + +A `ResumeV1SocialNetworksUrl` implements the following attributes: + +* `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. + ### Social Networks Field The list of social network profiles of the candidate. diff --git a/docs/us_healthcare_cards_v1.md b/docs/us_healthcare_cards_v1.md index 770888d7..db0d9474 100644 --- a/docs/us_healthcare_cards_v1.md +++ b/docs/us_healthcare_cards_v1.md @@ -83,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. @@ -109,6 +109,15 @@ Is a fixed amount for a covered service. A `HealthcareCardV1Copay` implements the following attributes: +* `service_fees` (Float): The price of service. +* `service_name` (String): The name of service of the copay. +Fields which are specific to this product; they are not used in any other product. + +### copays Field +Is a fixed amount for a covered service. + +A `HealthcareCardV1Copay` implements the following attributes: + * `service_fees` (Float): The price of service. * `service_name` (String): The name of service of the copay. diff --git a/docs/us_mail_v3.md b/docs/us_mail_v3.md index 004ac614..b1a23fbb 100644 --- a/docs/us_mail_v3.md +++ b/docs/us_mail_v3.md @@ -72,12 +72,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,7 +95,7 @@ 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. @@ -103,6 +103,33 @@ A `UsMailV3RecipientAddress` implements the following attributes: * `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. +### Recipient Addresses Field +The addresses of the recipients. + +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` (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. +Fields which are specific to this product; they are not used in any other product. + ### Sender Address Field The address of the sender. @@ -118,7 +145,7 @@ A `UsMailV3SenderAddress` implements the following attributes: The following fields are extracted for US Mail V3: ## Return to Sender -**is_return_to_sender** ([BooleanField](#boolean-field)): Whether the mailing is marked as return to sender. +**is_return_to_sender** ([BooleanField](#bool-field)): Whether the mailing is marked as return to sender. ```rb puts result.document.inference.prediction.is_return_to_sender.value diff --git a/docs/us_w9_v1.md b/docs/us_w9_v1.md index 18f060eb..fdbf501d 100644 --- a/docs/us_w9_v1.md +++ b/docs/us_w9_v1.md @@ -72,12 +72,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/lib/mindee/client.rb b/lib/mindee/client.rb index e38376da..c24dc6b8 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -23,6 +23,7 @@ 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, @@ -62,7 +63,8 @@ def initialize(params: {}) @full_text = params.fetch(:full_text, false) @close_file = params.fetch(:close_file, true) raw_page_options = params.fetch(:page_options, nil) - @page_options = raw_page_options.is_a?(Hash) ? PageOptions.new(params: raw_page_options) : raw_page_options + 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) @@ -94,7 +96,8 @@ def initialize(params: {}) @full_text = params.fetch(:full_text, false) @public_url = params.fetch(:public_url, nil) raw_page_options = params.fetch(:page_options, nil) - @page_options = raw_page_options.is_a?(Hash) ? PageOptions.new(params: raw_page_options) : raw_page_options + raw_page_options = PageOptions.new(params: raw_page_options) unless raw_page_options.is_a?(PageOptions) + @page_options = raw_page_options end end @@ -264,21 +267,28 @@ def parse_queued(job_id, product_class, endpoint: nil) 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_id = enqueue_res.job.id + 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 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 < options.max_retries + 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 + 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)" @@ -336,7 +346,12 @@ def execute_workflow(input_source, workflow_id, options: {}) # @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) + 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 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/image/extracted_image.rb b/lib/mindee/image/extracted_image.rb index 635b0c17..ff764de6 100644 --- a/lib/mindee/image/extracted_image.rb +++ b/lib/mindee/image/extracted_image.rb @@ -26,7 +26,7 @@ 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' diff --git a/lib/mindee/image/image_extractor.rb b/lib/mindee/image/image_extractor.rb index 3a0ae198..6f0f1173 100644 --- a/lib/mindee/image/image_extractor.rb +++ b/lib/mindee/image/image_extractor.rb @@ -73,7 +73,7 @@ def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygon 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 @@ -95,7 +95,7 @@ def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygon 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 ) diff --git a/lib/mindee/image/image_utils.rb b/lib/mindee/image/image_utils.rb index ce8cc4cf..5accd8f1 100644 --- a/lib/mindee/image/image_utils.rb +++ b/lib/mindee/image/image_utils.rb @@ -30,11 +30,11 @@ 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 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." @@ -69,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 @@ -105,10 +105,13 @@ def self.pdf_to_magick_image(pdf_stream, image_quality) # # @param [Array, Mindee::Geometry::Polygon] polygon def self.normalize_polygon(polygon) - if polygon.is_a?(Mindee::Geometry::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) - else + elsif polygon.is_a?(Mindee::Geometry::Quadrilateral) polygon + else + raise Errors::MindeeGeometryError, 'Provided polygon has an invalid type.' end end @@ -149,12 +152,12 @@ def self.write_image_to_buffer(image, buffer) # 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. + # @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).strip.downcase[1..] + File.extname(input_source.filename.to_s).strip.downcase[1..].to_s end end end diff --git a/lib/mindee/input/local_response.rb b/lib/mindee/input/local_response.rb index 64072d4d..e4b4df29 100644 --- a/lib/mindee/input/local_response.rb +++ b/lib/mindee/input/local_response.rb @@ -16,14 +16,14 @@ 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 diff --git a/lib/mindee/input/sources/base64_input_source.rb b/lib/mindee/input/sources/base64_input_source.rb index cde908de..387b3c00 100644 --- a/lib/mindee/input/sources/base64_input_source.rb +++ b/lib/mindee/input/sources/base64_input_source.rb @@ -11,7 +11,7 @@ class Base64InputSource < LocalInputSource # @param filename [String] # @param fix_pdf [bool] def initialize(base64_string, filename, fix_pdf: false) - io_stream = StringIO.new(base64_string.unpack1('m*')) + io_stream = StringIO.new(base64_string.unpack1('m*').to_s) io_stream.set_encoding Encoding::BINARY super(io_stream, filename, fix_pdf: fix_pdf) end diff --git a/lib/mindee/input/sources/local_input_source.rb b/lib/mindee/input/sources/local_input_source.rb index 006841e9..3f4e5c97 100644 --- a/lib/mindee/input/sources/local_input_source.rb +++ b/lib/mindee/input/sources/local_input_source.rb @@ -29,7 +29,7 @@ class LocalInputSource # @return [StringIO] attr_reader :io_stream - # @param io_stream [StringIO] + # @param io_stream [StringIO, File] # @param filename [String] # @param fix_pdf [bool] def initialize(io_stream, filename, fix_pdf: false) @@ -78,7 +78,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: @@ -87,7 +87,7 @@ 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. @@ -156,7 +156,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/url_input_source.rb b/lib/mindee/input/sources/url_input_source.rb index b80dfc42..e494bd67 100644 --- a/lib/mindee/input/sources/url_input_source.rb +++ b/lib/mindee/input/sources/url_input_source.rb @@ -56,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. @@ -86,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 diff --git a/lib/mindee/parsing/common/api_response.rb b/lib/mindee/parsing/common/api_response.rb index d13679db..9456badb 100644 --- a/lib/mindee/parsing/common/api_response.rb +++ b/lib/mindee/parsing/common/api_response.rb @@ -8,14 +8,10 @@ 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. diff --git a/lib/mindee/parsing/common/document.rb b/lib/mindee/parsing/common/document.rb index 0c9f6538..ad1d7c1c 100644 --- a/lib/mindee/parsing/common/document.rb +++ b/lib/mindee/parsing/common/document.rb @@ -16,24 +16,24 @@ 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 # Loads the MVision OCR response. # @param http_response [Hash] Full HTTP contents of the response. - # @return [Mindee::Parsing::Common::Ocr::Ocr] + # @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 # Loads extras into the document prediction. # @param http_response [Hash] Full HTTP contents of the response. - # @return [Mindee::Parsing::Common::Ocr::Ocr] + # @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? diff --git a/lib/mindee/parsing/common/job.rb b/lib/mindee/parsing/common/job.rb index 31e79bf3..a48dad19 100644 --- a/lib/mindee/parsing/common/job.rb +++ b/lib/mindee/parsing/common/job.rb @@ -9,7 +9,7 @@ module Common class Job # @return [String] Mindee ID of the document attr_reader :id - # @return [Mindee::Parsing::Standard::DateField] + # @return [Time] attr_reader :issued_at # @return [Time, nil] attr_reader :available_at diff --git a/lib/mindee/parsing/common/ocr/mvision_v1.rb b/lib/mindee/parsing/common/ocr/mvision_v1.rb index 68844e40..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 = [] # : Array[Mindee::Parsing::Common::Ocr::OcrPage] + @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 bff527f2..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 = [] # : Array[Mindee::Parsing::Common::Ocr::OcrLine] - @all_words = [] # : Array[Mindee::Parsing::Common::Ocr::OcrWord] + @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 = [] # : Array[Integer] - lines = [] # : Array[Mindee::Parsing::Common::Ocr::OcrLine] + 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,8 +138,8 @@ 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] + # @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) @@ -149,14 +149,14 @@ def words_on_same_line?(current_word, next_word) 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 = Mindee::Parsing::Common::Ocr::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/prediction.rb b/lib/mindee/parsing/common/prediction.rb index 4da70082..3f455ebd 100644 --- a/lib/mindee/parsing/common/prediction.rb +++ b/lib/mindee/parsing/common/prediction.rb @@ -10,7 +10,7 @@ def to_s '' end - def initialize(_ = nil); end + def initialize(_ = nil, _ = nil); end end end end diff --git a/lib/mindee/parsing/standard/base_field.rb b/lib/mindee/parsing/standard/base_field.rb index 9aea71f7..caf01aa6 100644 --- a/lib/mindee/parsing/standard/base_field.rb +++ b/lib/mindee/parsing/standard/base_field.rb @@ -8,7 +8,7 @@ module Parsing module Standard # Base field object. class BaseField < Mindee::Parsing::Standard::AbstractField - # @return [String, Numeric, bool] + # @return [String, Float, Integer, bool] attr_reader :value # true if the field was reconstructed or computed using other fields. # @return [bool] diff --git a/lib/mindee/parsing/standard/feature_field.rb b/lib/mindee/parsing/standard/feature_field.rb index 155c9e51..4280104b 100644 --- a/lib/mindee/parsing/standard/feature_field.rb +++ b/lib/mindee/parsing/standard/feature_field.rb @@ -15,7 +15,7 @@ def format_for_display(in_str, max_col_size = nil) return '' if in_str.nil? return in_str.to_s if max_col_size.nil? - in_str = in_str.gsub(%r{[\n\r\t]}, "\n" => '\\n', "\r" => '\\r', "\t" => '\\t') + 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 diff --git a/lib/mindee/pdf/pdf_compressor.rb b/lib/mindee/pdf/pdf_compressor.rb index 62ad1764..33a105e0 100644 --- a/lib/mindee/pdf/pdf_compressor.rb +++ b/lib/mindee/pdf/pdf_compressor.rb @@ -9,6 +9,7 @@ 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 [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. @@ -44,12 +45,13 @@ 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 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. diff --git a/lib/mindee/pdf/pdf_extractor.rb b/lib/mindee/pdf/pdf_extractor.rb index b2937a1d..e1560dbb 100644 --- a/lib/mindee/pdf/pdf_extractor.rb +++ b/lib/mindee/pdf/pdf_extractor.rb @@ -31,9 +31,9 @@ def page_count # @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) end diff --git a/lib/mindee/pdf/pdf_processor.rb b/lib/mindee/pdf/pdf_processor.rb index d78e6a55..1d7e38eb 100644 --- a/lib/mindee/pdf/pdf_processor.rb +++ b/lib/mindee/pdf/pdf_processor.rb @@ -9,31 +9,22 @@ module PDF # PDF document processing 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 - 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) + 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 ArgumentError, "operation must be one of :KEEP_ONLY or :REMOVE, sent '#{options[:operation]}'" + 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 @@ -84,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/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_document.rb b/lib/mindee/product/barcode_reader/barcode_reader_v1_document.rb index 5ee6c8a9..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,12 +18,12 @@ class BarcodeReaderV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @codes_1d = [] + super + @codes_1d = [] # : Array[Parsing::Standard::StringField] prediction['codes_1d'].each do |item| @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(Parsing::Standard::StringField.new(item, page_id)) end 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 d88c9fe1..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 @@ -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? ? '' : BaseField.float_to_string(@gross_weight) - printable[:measurement] = @measurement.nil? ? '' : BaseField.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? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@gross_weight) - printable[:measurement] = @measurement.nil? ? '' : BaseField.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? ? '' : BaseField.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_document.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_document.rb index bf0519b3..21c488fc 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 @@ -50,21 +50,51 @@ class BillOfLadingV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @bill_of_lading_number = StringField.new(prediction['bill_of_lading_number'], page_id) - @carrier = BillOfLadingV1Carrier.new(prediction['carrier'], page_id) - @carrier_items = [] + 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 = [] # : Array[BillOfLading::BillOfLadingV1CarrierItem] prediction['carrier_items'].each do |item| @carrier_items.push(BillOfLading::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) + @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/business_card/business_card_v1_document.rb b/lib/mindee/product/business_card/business_card_v1_document.rb index 9792809e..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(prediction) - @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(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/cropper/cropper_v1.rb b/lib/mindee/product/cropper/cropper_v1.rb index 8373711b..83f312ab 100644 --- a/lib/mindee/product/cropper/cropper_v1.rb +++ b/lib/mindee/product/cropper/cropper_v1.rb @@ -18,7 +18,7 @@ class CropperV1 < Mindee::Parsing::Common::Inference # @param prediction [Hash] def initialize(prediction) super - @prediction = CropperV1Document.new + @prediction = CropperV1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| @pages.push(CropperV1Page.new(page)) diff --git a/lib/mindee/product/cropper/cropper_v1_page.rb b/lib/mindee/product/cropper/cropper_v1_page.rb index b401f0c6..bff5ebe4 100644 --- a/lib/mindee/product/cropper/cropper_v1_page.rb +++ b/lib/mindee/product/cropper/cropper_v1_page.rb @@ -35,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/delivery_note/delivery_note_v1_document.rb b/lib/mindee/product/delivery_note/delivery_note_v1_document.rb index 042ad769..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(prediction) - @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/driver_license/driver_license_v1_document.rb b/lib/mindee/product/driver_license/driver_license_v1_document.rb index 712168c3..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(prediction) - @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/eu/license_plate/license_plate_v1_document.rb b/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb index 4b8ab4b0..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,8 +16,8 @@ class LicensePlateV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @license_plates = [] + super + @license_plates = [] # : Array[Parsing::Standard::StringField] prediction['license_plates'].each do |item| @license_plates.push(Parsing::Standard::StringField.new(item, page_id)) 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 7b00635e..ec8df7ed 100644 --- a/lib/mindee/product/financial_document/financial_document_v1_document.rb +++ b/lib/mindee/product/financial_document/financial_document_v1_document.rb @@ -109,54 +109,123 @@ class FinancialDocumentV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @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(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 = [] + @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 = [] # : Array[FinancialDocument::FinancialDocumentV1LineItem] prediction['line_items'].each do |item| @line_items.push(FinancialDocument::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 = [] + @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(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(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(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 6c48d527..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 @@ -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? ? '' : BaseField.float_to_string(@quantity) - printable[:tax_amount] = @tax_amount.nil? ? '' : BaseField.float_to_string(@tax_amount) - printable[:tax_rate] = @tax_rate.nil? ? '' : BaseField.float_to_string(@tax_rate) - printable[:total_amount] = @total_amount.nil? ? '' : BaseField.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? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@quantity) - printable[:tax_amount] = @tax_amount.nil? ? '' : BaseField.float_to_string(@tax_amount) - printable[:tax_rate] = @tax_rate.nil? ? '' : BaseField.float_to_string(@tax_rate) - printable[:total_amount] = @total_amount.nil? ? '' : BaseField.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? ? '' : BaseField.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/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 0d246b64..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(prediction) - @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_v2_document.rb b/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb index f536b774..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(prediction) - @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_statement/bank_statement_v1.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v1.rb index 5da9f781..3264a75c 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v1.rb @@ -7,12 +7,14 @@ module Mindee module Product module FR - # Bank Statement (FR) module. + # Bank Statement module. module BankStatement - # Bank Statement (FR) V1 prediction inference. + # Bank Statement API version 1 inference prediction. class BankStatementV1 < Mindee::Parsing::Common::Inference @endpoint_name = 'bank_statement_fr' @endpoint_version = '1' + @has_async = true + @has_sync = false # @param prediction [Hash] def initialize(prediction) @@ -20,9 +22,7 @@ def initialize(prediction) @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 + @pages.push(BankStatementV1Page.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_v1_document.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb index c4ca7ce1..bced6caf 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb @@ -7,7 +7,7 @@ module Mindee module Product module FR module BankStatement - # Bank Statement (FR) V1 document prediction. + # Bank Statement API version 1.1 document data. class BankStatementV1Document < Mindee::Parsing::Common::Prediction include Mindee::Parsing::Standard # The unique identifier for a customer's account in the bank's system. @@ -31,7 +31,7 @@ class BankStatementV1Document < Mindee::Parsing::Common::Prediction # 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 universal. + # 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. @@ -53,22 +53,58 @@ class BankStatementV1Document < 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) - @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 = [] + 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_name = Parsing::Standard::StringField.new( + prediction['client_name'], + page_id + ) + @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 = [] # : Array[BankStatement::BankStatementV1Transaction] prediction['transactions'].each do |item| - @transactions.push(BankStatementV1Transaction.new(item, page_id)) + @transactions.push(BankStatement::BankStatementV1Transaction.new(item, page_id)) 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 index 3b7fad59..44ec229a 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_page.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v1_page.rb @@ -7,19 +7,23 @@ module Mindee module Product module FR module BankStatement - # Bank Statement (FR) V1 page. + # Bank Statement API version 1.1 page data. class BankStatementV1Page < Mindee::Parsing::Common::Page # @param prediction [Hash] def initialize(prediction) super - @prediction = BankStatementV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) + @prediction = if prediction['prediction'].empty? + nil + else + BankStatementV1PagePrediction.new( + prediction['prediction'], + prediction['id'] + ) + end end end - # Bank Statement (FR) V1 page prediction. + # Bank Statement V1 page prediction. class BankStatementV1PagePrediction < BankStatementV1Document # @return [String] def to_s 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 index 0c85f539..5f10583e 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb @@ -32,15 +32,26 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : BaseField.float_to_string(@amount) - printable[:date] = format_for_display(@date, nil) + printable[:amount] = + @amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@amount) + printable[:date] = format_for_display(@date) + printable[:description] = format_for_display(@description) + printable + end + + # @return [Hash] + def table_printable_values + printable = {} + 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 end # @return [String] def to_table_line - printable = printable_values + printable = table_printable_values out_str = String.new out_str << format('| %- 10s', printable[:amount]) out_str << format('| %- 11s', printable[:date]) 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 3ac9be43..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(prediction) - @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/energy_bill/energy_bill_v1_document.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_document.rb index b5e52a45..bcd0b5fb 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 @@ -62,30 +62,63 @@ class EnergyBillV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @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 = [] + 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 = [] # : Array[EnergyBill::EnergyBillV1EnergyUsage] prediction['energy_usage'].each do |item| @energy_usage.push(EnergyBill::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 = [] + @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 = [] # : Array[EnergyBill::EnergyBillV1Subscription] prediction['subscription'].each do |item| @subscription.push(EnergyBill::EnergyBillV1Subscription.new(item, page_id)) end - @taxes_and_contributions = [] + @taxes_and_contributions = [] # : Array[EnergyBill::EnergyBillV1TaxesAndContribution] prediction['taxes_and_contributions'].each do |item| @taxes_and_contributions.push(EnergyBill::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) + @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_usage.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb index d9be4276..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 @@ -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? ? '' : BaseField.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : BaseField.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_subscription.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rb index 9f686038..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 @@ -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? ? '' : BaseField.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : BaseField.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_contribution.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rb index b14ccaee..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 @@ -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? ? '' : BaseField.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@tax_rate) - printable[:total] = @total.nil? ? '' : BaseField.float_to_string(@total) - printable[:unit_price] = @unit_price.nil? ? '' : BaseField.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/health_card/health_card_v1_document.rb b/lib/mindee/product/fr/health_card/health_card_v1_document.rb index c6a50081..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(prediction) - @given_names = [] + super + @given_names = [] # : Array[Parsing::Standard::StringField] prediction['given_names'].each do |item| @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/id_card/id_card_v1_document.rb b/lib/mindee/product/fr/id_card/id_card_v1_document.rb index ac3a1f12..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(prediction) - @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(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 caac1a49..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 @@ -34,7 +34,10 @@ 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) + @document_side = Parsing::Standard::ClassificationField.new( + prediction['document_side'], + page_id + ) super 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 418a5637..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(prediction) - @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(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 08a538cf..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 @@ -37,8 +37,14 @@ 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) + @document_side = Parsing::Standard::ClassificationField.new( + prediction['document_side'], + page_id + ) + @document_type = Parsing::Standard::ClassificationField.new( + prediction['document_type'], + page_id + ) super end diff --git a/lib/mindee/product/fr/payslip/payslip_v2_document.rb b/lib/mindee/product/fr/payslip/payslip_v2_document.rb index 1bf3d9c5..fe9d9f07 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_document.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_document.rb @@ -45,15 +45,33 @@ class PayslipV2Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @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 = [] + 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 = [] # : Array[Payslip::PayslipV2SalaryDetail] prediction['salary_details'].each do |item| @salary_details.push(Payslip::PayslipV2SalaryDetail.new(item, page_id)) end diff --git a/lib/mindee/product/fr/payslip/payslip_v2_employment.rb b/lib/mindee/product/fr/payslip/payslip_v2_employment.rb index 9dcfa085..1221a046 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_employment.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_employment.rb @@ -45,7 +45,8 @@ def initialize(prediction, page_id) def printable_values printable = {} printable[:category] = format_for_display(@category) - printable[:coefficient] = @coefficient.nil? ? '' : BaseField.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_pay_detail.rb b/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb index 2f5e85a8..8ebe6ca0 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb @@ -60,20 +60,42 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:gross_salary] = @gross_salary.nil? ? '' : BaseField.float_to_string(@gross_salary) - printable[:gross_salary_ytd] = @gross_salary_ytd.nil? ? '' : BaseField.float_to_string(@gross_salary_ytd) - printable[:income_tax_rate] = @income_tax_rate.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@income_tax_withheld) - printable[:net_paid] = @net_paid.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@net_paid_before_tax) - printable[:net_taxable] = @net_taxable.nil? ? '' : BaseField.float_to_string(@net_taxable) - printable[:net_taxable_ytd] = @net_taxable_ytd.nil? ? '' : BaseField.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? ? '' : BaseField.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? ? '' : BaseField.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_pto.rb b/lib/mindee/product/fr/payslip/payslip_v2_pto.rb index 4089b230..22387410 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_pto.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_pto.rb @@ -33,10 +33,19 @@ def initialize(prediction, page_id) def printable_values printable = {} printable[:accrued_this_period] = - @accrued_this_period.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@balance_end_of_period) - printable[:used_this_period] = @used_this_period.nil? ? '' : BaseField.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 e4828b55..48328cf1 100644 --- a/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb @@ -36,20 +36,26 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : BaseField.float_to_string(@amount) - printable[:base] = @base.nil? ? '' : BaseField.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? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@amount) - printable[:base] = @base.nil? ? '' : BaseField.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? ? '' : BaseField.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_v3_document.rb b/lib/mindee/product/fr/payslip/payslip_v3_document.rb index 9cf9eb6e..55a8aa26 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_document.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_document.rb @@ -45,18 +45,36 @@ class PayslipV3Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @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 = [] + 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 = [] # : Array[Payslip::PayslipV3PaidTimeOff] prediction['paid_time_off'].each do |item| @paid_time_off.push(Payslip::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 = [] + @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 = [] # : Array[Payslip::PayslipV3SalaryDetail] prediction['salary_details'].each do |item| @salary_details.push(Payslip::PayslipV3SalaryDetail.new(item, page_id)) 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 7fa5e0b6..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 @@ -40,22 +40,28 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:accrued] = @accrued.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@remaining) - printable[:used] = @used.nil? ? '' : BaseField.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? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@remaining) - printable[:used] = @used.nil? ? '' : BaseField.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_pay_detail.rb b/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb index 555f8fde..5d706add 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb @@ -60,20 +60,42 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:gross_salary] = @gross_salary.nil? ? '' : BaseField.float_to_string(@gross_salary) - printable[:gross_salary_ytd] = @gross_salary_ytd.nil? ? '' : BaseField.float_to_string(@gross_salary_ytd) - printable[:income_tax_rate] = @income_tax_rate.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@income_tax_withheld) - printable[:net_paid] = @net_paid.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@net_paid_before_tax) - printable[:net_taxable] = @net_taxable.nil? ? '' : BaseField.float_to_string(@net_taxable) - printable[:net_taxable_ytd] = @net_taxable_ytd.nil? ? '' : BaseField.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? ? '' : BaseField.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? ? '' : BaseField.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_salary_detail.rb b/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb index 86a78aa4..5e4b9b71 100644 --- a/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb +++ b/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb @@ -40,22 +40,30 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : BaseField.float_to_string(@amount) - printable[:base] = @base.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@number) - printable[:rate] = @rate.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@amount) - printable[:base] = @base.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@number) - printable[:rate] = @rate.nil? ? '' : BaseField.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/ind/indian_passport/indian_passport_v1_document.rb b/lib/mindee/product/ind/indian_passport/indian_passport_v1_document.rb index a8bfefde..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(prediction) - @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/international_id/international_id_v2_document.rb b/lib/mindee/product/international_id/international_id_v2_document.rb index 3d2b1dc0..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,27 +63,69 @@ class InternationalIdV2Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @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(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(Parsing::Standard::StringField.new(item, page_id)) end diff --git a/lib/mindee/product/invoice/invoice_v4_document.rb b/lib/mindee/product/invoice/invoice_v4_document.rb index 49785a67..3ab5ec10 100644 --- a/lib/mindee/product/invoice/invoice_v4_document.rb +++ b/lib/mindee/product/invoice/invoice_v4_document.rb @@ -91,48 +91,105 @@ class InvoiceV4Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @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(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 = [] + @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 = [] # : Array[Invoice::InvoiceV4LineItem] prediction['line_items'].each do |item| @line_items.push(Invoice::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 = [] + @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(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(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(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 a36aa237..5c72964d 100644 --- a/lib/mindee/product/invoice/invoice_v4_line_item.rb +++ b/lib/mindee/product/invoice/invoice_v4_line_item.rb @@ -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? ? '' : BaseField.float_to_string(@quantity) - printable[:tax_amount] = @tax_amount.nil? ? '' : BaseField.float_to_string(@tax_amount) - printable[:tax_rate] = @tax_rate.nil? ? '' : BaseField.float_to_string(@tax_rate) - printable[:total_amount] = @total_amount.nil? ? '' : BaseField.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? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@quantity) - printable[:tax_amount] = @tax_amount.nil? ? '' : BaseField.float_to_string(@tax_amount) - printable[:tax_rate] = @tax_rate.nil? ? '' : BaseField.float_to_string(@tax_rate) - printable[:total_amount] = @total_amount.nil? ? '' : BaseField.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? ? '' : BaseField.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_splitter/invoice_splitter_v1_document.rb b/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb index 8d340c5b..a7544984 100644 --- a/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +++ b/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb @@ -35,7 +35,7 @@ class InvoiceSplitterV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param _page_id [Integer, nil] def initialize(prediction, _page_id = nil) - super(prediction) + super(prediction, nil) construct_invoice_page_groups_from_prediction(prediction) 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 d7a62e67..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 @@ -6,7 +6,7 @@ module Mindee module Product module MultiReceiptsDetector # Multi Receipts Detector API version 1.1 document data. - class MultiReceiptsDetectorV1Document < Parsing::Common::Prediction + class MultiReceiptsDetectorV1Document < Mindee::Parsing::Common::Prediction include Mindee::Parsing::Standard # Positions of the receipts on the document. # @return [Array] @@ -14,9 +14,9 @@ class MultiReceiptsDetectorV1Document < Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] - def initialize(prediction, page_id = nil) - super(prediction) - @receipts = [] + def initialize(prediction, page_id) + super + @receipts = [] # : Array[Parsing::Standard::PositionField] prediction['receipts'].each do |item| @receipts.push(Parsing::Standard::PositionField.new(item, page_id)) 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 a090cab0..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 @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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 6aafe190..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 @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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 edae3c87..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 @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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 1d3359b4..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 @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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 b49eb716..e644c6ac 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 @@ -67,24 +67,63 @@ class NutritionFactsLabelV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @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 = [] + 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 = [] # : Array[NutritionFactsLabel::NutritionFactsLabelV1Nutrient] prediction['nutrients'].each do |item| @nutrients.push(NutritionFactsLabel::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) + @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 0bf5ad64..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 @@ -39,10 +39,13 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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_protein.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rb index 547c3dcd..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 @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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 a56e57a7..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 @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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 a4120bcc..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 @@ -27,7 +27,8 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:amount] = @amount.nil? ? '' : BaseField.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 9084994b..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 @@ -35,9 +35,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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 61ec6e57..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 @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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 0e92cedf..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 @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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 e9b464ee..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 @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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 b48dd9d0..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 @@ -31,9 +31,12 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:daily_value] = @daily_value.nil? ? '' : BaseField.float_to_string(@daily_value) - printable[:per_100g] = @per_100g.nil? ? '' : BaseField.float_to_string(@per_100g) - printable[:per_serving] = @per_serving.nil? ? '' : BaseField.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_document.rb b/lib/mindee/product/passport/passport_v1_document.rb index c40875f0..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(prediction) - @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(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/receipt/receipt_v5_document.rb b/lib/mindee/product/receipt/receipt_v5_document.rb index ebc7ccf9..66aad93b 100644 --- a/lib/mindee/product/receipt/receipt_v5_document.rb +++ b/lib/mindee/product/receipt/receipt_v5_document.rb @@ -64,30 +64,63 @@ class ReceiptV5Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @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 = [] + 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 = [] # : Array[Receipt::ReceiptV5LineItem] prediction['line_items'].each do |item| @line_items.push(Receipt::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 = [] + @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(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 66e1c65d..de0f54e3 100644 --- a/lib/mindee/product/receipt/receipt_v5_line_item.rb +++ b/lib/mindee/product/receipt/receipt_v5_line_item.rb @@ -36,9 +36,12 @@ def initialize(prediction, page_id) def printable_values printable = {} printable[:description] = format_for_display(@description) - printable[:quantity] = @quantity.nil? ? '' : BaseField.float_to_string(@quantity) - printable[:total_amount] = @total_amount.nil? ? '' : BaseField.float_to_string(@total_amount) - printable[:unit_price] = @unit_price.nil? ? '' : BaseField.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? ? '' : BaseField.float_to_string(@quantity) - printable[:total_amount] = @total_amount.nil? ? '' : BaseField.float_to_string(@total_amount) - printable[:unit_price] = @unit_price.nil? ? '' : BaseField.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/resume/resume_v1_document.rb b/lib/mindee/product/resume/resume_v1_document.rb index 81ae151e..77f4817e 100644 --- a/lib/mindee/product/resume/resume_v1_document.rb +++ b/lib/mindee/product/resume/resume_v1_document.rb @@ -68,48 +68,72 @@ class ResumeV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @address = StringField.new(prediction['address'], page_id) - @certificates = [] + super + @address = Parsing::Standard::StringField.new( + prediction['address'], + page_id + ) + @certificates = [] # : Array[Resume::ResumeV1Certificate] prediction['certificates'].each do |item| @certificates.push(Resume::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 = [] + @document_language = Parsing::Standard::StringField.new( + prediction['document_language'], + page_id + ) + @document_type = Parsing::Standard::ClassificationField.new( + prediction['document_type'], + page_id + ) + @education = [] # : Array[Resume::ResumeV1Education] prediction['education'].each do |item| @education.push(Resume::ResumeV1Education.new(item, page_id)) end - @email_address = StringField.new(prediction['email_address'], page_id) - @given_names = [] + @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(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(Parsing::Standard::StringField.new(item, page_id)) end - @job_applied = StringField.new(prediction['job_applied'], page_id) - @languages = [] + @job_applied = Parsing::Standard::StringField.new( + prediction['job_applied'], + page_id + ) + @languages = [] # : Array[Resume::ResumeV1Language] prediction['languages'].each do |item| @languages.push(Resume::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 = [] + @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 = [] # : Array[Resume::ResumeV1ProfessionalExperience] prediction['professional_experiences'].each do |item| @professional_experiences.push(Resume::ResumeV1ProfessionalExperience.new(item, page_id)) end - @social_networks_urls = [] + @social_networks_urls = [] # : Array[Resume::ResumeV1SocialNetworksUrl] prediction['social_networks_urls'].each do |item| @social_networks_urls.push(Resume::ResumeV1SocialNetworksUrl.new(item, page_id)) end - @soft_skills = [] + @soft_skills = [] # : Array[Parsing::Standard::StringField] prediction['soft_skills'].each do |item| @soft_skills.push(Parsing::Standard::StringField.new(item, page_id)) end - @surnames = [] + @surnames = [] # : Array[Parsing::Standard::StringField] prediction['surnames'].each do |item| @surnames.push(Parsing::Standard::StringField.new(item, page_id)) end diff --git a/lib/mindee/product/universal/universal_prediction.rb b/lib/mindee/product/universal/universal_prediction.rb index 37eb2547..144d0a58 100644 --- a/lib/mindee/product/universal/universal_prediction.rb +++ b/lib/mindee/product/universal/universal_prediction.rb @@ -41,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::Universal::UniversalObjectField) - 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| + 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 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 166a4b9b..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(prediction) - @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(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 f391a61f..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 @@ -37,10 +37,13 @@ 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 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 3606355d..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 @@ -28,7 +28,8 @@ def initialize(prediction, page_id) # @return [Hash] def printable_values printable = {} - printable[:service_fees] = @service_fees.nil? ? '' : BaseField.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? ? '' : BaseField.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_document.rb b/lib/mindee/product/us/healthcare_card/healthcare_card_v1_document.rb index f2633d05..71c5902d 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 @@ -50,25 +50,55 @@ class HealthcareCardV1Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @company_name = StringField.new(prediction['company_name'], page_id) - @copays = [] + super + @company_name = Parsing::Standard::StringField.new( + prediction['company_name'], + page_id + ) + @copays = [] # : Array[HealthcareCard::HealthcareCardV1Copay] prediction['copays'].each do |item| @copays.push(HealthcareCard::HealthcareCardV1Copay.new(item, page_id)) end - @dependents = [] + @dependents = [] # : Array[Parsing::Standard::StringField] prediction['dependents'].each do |item| @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/us_mail/us_mail_v3_document.rb b/lib/mindee/product/us/us_mail/us_mail_v3_document.rb index eb9a3036..68b5c725 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 @@ -30,18 +30,27 @@ class UsMailV3Document < Mindee::Parsing::Common::Prediction # @param prediction [Hash] # @param page_id [Integer, nil] def initialize(prediction, page_id) - super(prediction) - @is_return_to_sender = BooleanField.new(prediction['is_return_to_sender'], page_id) - @recipient_addresses = [] + super + @is_return_to_sender = Parsing::Standard::BooleanField.new( + prediction['is_return_to_sender'], + page_id + ) + @recipient_addresses = [] # : Array[UsMail::UsMailV3RecipientAddress] prediction['recipient_addresses'].each do |item| @recipient_addresses.push(UsMail::UsMailV3RecipientAddress.new(item, page_id)) end - @recipient_names = [] + @recipient_names = [] # : Array[Parsing::Standard::StringField] prediction['recipient_names'].each do |item| @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/w9/w9_v1.rb b/lib/mindee/product/us/w9/w9_v1.rb index 9bf1fa27..dcafdaa0 100644 --- a/lib/mindee/product/us/w9/w9_v1.rb +++ b/lib/mindee/product/us/w9/w9_v1.rb @@ -19,7 +19,7 @@ class W9V1 < Mindee::Parsing::Common::Inference # @param prediction [Hash] def initialize(prediction) super - @prediction = W9V1Document.new + @prediction = W9V1Document.new(prediction['prediction'], nil) @pages = [] prediction['pages'].each do |page| @pages.push(W9V1Page.new(page)) diff --git a/lib/mindee/product/us/w9/w9_v1_page.rb b/lib/mindee/product/us/w9/w9_v1_page.rb index 3733d19a..e2c17d8f 100644 --- a/lib/mindee/product/us/w9/w9_v1_page.rb +++ b/lib/mindee/product/us/w9/w9_v1_page.rb @@ -67,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/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 index 1d829a68..d52fbfad 100644 --- a/sig/custom/mini_magick.rbs +++ b/sig/custom/mini_magick.rbs @@ -4,9 +4,21 @@ module MiniMagick 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.read: (StringIO) -> self + 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: (String) -> Net::BufferedIO + 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 index cbac9f58..e842655a 100644 --- a/sig/custom/net_http.rbs +++ b/sig/custom/net_http.rbs @@ -6,7 +6,7 @@ module Net class BufferedIO end class HTTP - def self.start: [T] (String?, Integer?, use_ssl: bool?, read_timeout: Integer) { (HTTP) -> T } -> T + def self.start: [T] (String?, Integer?, use_ssl: bool?, ?read_timeout: Integer) { (HTTP) -> T } -> T def request: (untyped) -> untyped @@ -19,8 +19,16 @@ module Net # Stub for the HTTP GET request class. class Get - def initialize: (untyped, Hash[String, String]?) -> void + 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 index 5a0cf9e8..2f9b1e4e 100644 --- a/sig/custom/origami.rbs +++ b/sig/custom/origami.rbs @@ -8,16 +8,21 @@ module Origami 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) -> untyped + 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 diff --git a/sig/mindee/client.rbs b/sig/mindee/client.rbs index 37f9ff73..16e5fe76 100644 --- a/sig/mindee/client.rbs +++ b/sig/mindee/client.rbs @@ -16,7 +16,7 @@ module Mindee attr_accessor all_words: bool attr_accessor full_text: bool attr_accessor close_file: bool - attr_accessor page_options: (PageOptions | Hash[Symbol | String, untyped]?) + attr_accessor page_options: PageOptions attr_accessor cropper: bool attr_accessor initial_delay_sec: Integer | Float attr_accessor delay_sec: Integer | Float @@ -31,7 +31,7 @@ module Mindee attr_accessor priority: (Symbol?) attr_accessor full_text: bool attr_accessor public_url: (String?) - attr_accessor page_options: (PageOptions | Hash[Symbol | String, untyped]?) + attr_accessor page_options: (PageOptions) def initialize: (params: Hash[Symbol | String, untyped]) -> void end diff --git a/sig/mindee/geometry/quadrilateral.rbs b/sig/mindee/geometry/quadrilateral.rbs index 0b54d961..421ce916 100644 --- a/sig/mindee/geometry/quadrilateral.rbs +++ b/sig/mindee/geometry/quadrilateral.rbs @@ -2,16 +2,16 @@ module Mindee module Geometry class Quadrilateral - def top_left: -> untyped - def top_left=: (untyped) -> untyped - def top_right: -> untyped - def top_right=: (untyped) -> untyped - def bottom_right: -> untyped - def bottom_right=: (untyped) -> untyped - def bottom_left: -> untyped - def bottom_left=: (untyped) -> untyped - def initialize: (untyped, untyped, untyped, untyped) -> untyped - def []: (untyped) -> bot + 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 diff --git a/sig/mindee/geometry/utils.rbs b/sig/mindee/geometry/utils.rbs index d5e92f63..cfb2f36b 100644 --- a/sig/mindee/geometry/utils.rbs +++ b/sig/mindee/geometry/utils.rbs @@ -4,7 +4,7 @@ module Mindee 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) -> 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 diff --git a/sig/mindee/image/extracted_image.rbs b/sig/mindee/image/extracted_image.rbs index c65071db..2ad71f56 100644 --- a/sig/mindee/image/extracted_image.rbs +++ b/sig/mindee/image/extracted_image.rbs @@ -3,13 +3,13 @@ module Mindee module Image class ExtractedImage def logger: () -> untyped - def page_id: -> untyped + def page_id: -> Integer def element_id: -> Integer def buffer: -> StringIO def internal_file_name: -> String - def initialize: (untyped, untyped, untyped) -> Integer - def write_to_file: (untyped, ?nil) -> nil - def as_source: -> untyped + 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 index 353da19f..dd4eda57 100644 --- a/sig/mindee/image/image_compressor.rbs +++ b/sig/mindee/image/image_compressor.rbs @@ -2,7 +2,7 @@ module Mindee module Image module ImageCompressor - def self.compress_image: (untyped, ?quality: Integer, ?max_width: nil, ?max_height: nil) -> untyped + 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_utils.rbs b/sig/mindee/image/image_utils.rbs index ea05be78..24bdaa88 100644 --- a/sig/mindee/image/image_utils.rbs +++ b/sig/mindee/image/image_utils.rbs @@ -2,18 +2,18 @@ module Mindee module Image module ImageUtils - def self.resize_image: (untyped, untyped, untyped) -> nil - def self.compress_image_quality: (untyped, untyped) -> untyped - def self.to_image: (untyped) -> (singleton(MiniMagick::Image) | MiniMagick::Image) - def self.image_to_stringio: (untyped, ?String) -> StringIO - def self.calculate_new_dimensions: (untyped, ?max_width: nil, ?max_height: nil) -> [untyped, untyped] - def self.calculate_dimensions_from_media_box: (untyped, untyped) -> [untyped, untyped] - def self.pdf_to_magick_image: (untyped, untyped) -> untyped - def self.normalize_polygon: (untyped) -> untyped - def self.read_page_content: (untyped) -> untyped - def self.crop_image: (untyped, untyped, untyped) -> untyped - def self.write_image_to_buffer: (untyped, untyped) -> untyped - def self.determine_file_extension: (untyped) -> String? + 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/sources/base64_input_source.rbs b/sig/mindee/input/sources/base64_input_source.rbs index a256d9c7..6df97dd5 100644 --- a/sig/mindee/input/sources/base64_input_source.rbs +++ b/sig/mindee/input/sources/base64_input_source.rbs @@ -2,9 +2,9 @@ module Mindee module Input module Source - class Base64InputSource # failed to identify its superclass - def initialize: (untyped, untyped, ?fix_pdf: bool) -> untyped - def read_contents: (?close: true) -> [String, String, Hash[:filename, untyped]] + class Base64InputSource < LocalInputSource + def initialize: (String, String, ?fix_pdf: bool) -> void + def read_contents: (?close: bool) -> [String, String, Hash[Symbol, untyped]] end end end diff --git a/sig/mindee/input/sources/bytes_input_source.rbs b/sig/mindee/input/sources/bytes_input_source.rbs index a363e9f4..5af51d57 100644 --- a/sig/mindee/input/sources/bytes_input_source.rbs +++ b/sig/mindee/input/sources/bytes_input_source.rbs @@ -2,8 +2,8 @@ module Mindee module Input module Source - class BytesInputSource # failed to identify its superclass - def initialize: (untyped, untyped, ?fix_pdf: bool) -> untyped + class BytesInputSource < LocalInputSource + def initialize: (String, String, ?fix_pdf: bool) -> void end end end diff --git a/sig/mindee/input/sources/file_input_source.rbs b/sig/mindee/input/sources/file_input_source.rbs index 7ce1cb92..039dc0ee 100644 --- a/sig/mindee/input/sources/file_input_source.rbs +++ b/sig/mindee/input/sources/file_input_source.rbs @@ -2,8 +2,8 @@ module Mindee module Input module Source - class FileInputSource # failed to identify its superclass - def initialize: (untyped, untyped, ?fix_pdf: bool) -> untyped + class FileInputSource < LocalInputSource + def initialize: (File, String, ?fix_pdf: bool) -> void end end end diff --git a/sig/mindee/input/sources/local_input_source.rbs b/sig/mindee/input/sources/local_input_source.rbs index 95bb8e76..d7151dde 100644 --- a/sig/mindee/input/sources/local_input_source.rbs +++ b/sig/mindee/input/sources/local_input_source.rbs @@ -4,19 +4,20 @@ module Mindee module Source ALLOWED_MIME_TYPES: Array[String] class LocalInputSource - def filename: -> untyped - def file_mimetype: -> untyped + def filename: -> String + def file_mimetype: -> String def io_stream: -> StringIO - def initialize: (untyped, untyped, ?fix_pdf: bool) -> nil + def initialize: (StringIO | File, String, ?fix_pdf: bool) -> void + def logger: () -> untyped def rescue_broken_pdf: (StringIO) -> StringIO - def pdf?: -> untyped - def process_pdf: (untyped) -> untyped - def read_contents: (?close: true) -> [String, String?, Hash[:filename, String]] + def pdf?: -> bool + def process_pdf: (PageOptions) -> StringIO? + def read_contents: (?close: bool) -> [String, String?, Hash[:filename, String]] def count_pages: -> Integer - def compress!: (?quality: Integer, ?max_width: nil, ?max_height: nil, ?force_source_text: false, ?disable_source_text: true) -> Integer - def source_text?: -> untyped + 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: (untyped) -> String + 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 index 236ac4ef..f4cd1e6c 100644 --- a/sig/mindee/input/sources/path_input_source.rbs +++ b/sig/mindee/input/sources/path_input_source.rbs @@ -2,8 +2,8 @@ module Mindee module Input module Source - class PathInputSource # failed to identify its superclass - def initialize: (untyped, ?fix_pdf: bool) -> untyped + class PathInputSource < LocalInputSource + def initialize: (String, ?fix_pdf: bool) -> void end end end diff --git a/sig/mindee/input/sources/url_input_source.rbs b/sig/mindee/input/sources/url_input_source.rbs index 403d29e6..649d8631 100644 --- a/sig/mindee/input/sources/url_input_source.rbs +++ b/sig/mindee/input/sources/url_input_source.rbs @@ -3,14 +3,15 @@ module Mindee module Input module Source class UrlInputSource - def url: -> untyped - def initialize: (untyped) -> untyped - def write_to_file: (untyped, ?filename: nil, ?username: nil, ?password: nil, ?token: nil, ?max_redirects: Integer) -> String - def as_local_input_source: (?filename: nil, ?username: nil, ?password: nil, ?token: nil, ?max_redirects: Integer) -> untyped - def fetch_file_content: (?username: nil, ?password: nil, ?token: nil, ?max_redirects: Integer) -> untyped - def extract_filename_from_url: (untyped) -> String - def fill_filename: (nil) -> String - def make_request: (untyped, untyped, Integer) -> untyped + 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 diff --git a/sig/mindee/parsing/common/api_response.rbs b/sig/mindee/parsing/common/api_response.rbs index a8662221..0e4c7198 100644 --- a/sig/mindee/parsing/common/api_response.rbs +++ b/sig/mindee/parsing/common/api_response.rbs @@ -7,7 +7,7 @@ module Mindee PROCESSING: :processing COMPLETED: :completed FAILURE: :failed - end + end module RequestStatus FAILURE: :failure SUCCESS: :success @@ -16,11 +16,11 @@ module Mindee class ApiResponse def logger: () -> untyped - def document: -> untyped - def job: -> untyped - def api_request: -> untyped - def raw_http: -> untyped - def initialize: (untyped, untyped, untyped) -> 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 diff --git a/sig/mindee/parsing/common/document.rbs b/sig/mindee/parsing/common/document.rbs index 44280ee6..f7a0cb65 100644 --- a/sig/mindee/parsing/common/document.rbs +++ b/sig/mindee/parsing/common/document.rbs @@ -9,7 +9,7 @@ module Mindee def extras: -> nil def ocr: -> nil def n_pages: -> untyped - def self.load_ocr: (untyped) -> Parsing::Common::Ocr::Ocr? + 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 diff --git a/sig/mindee/parsing/common/job.rbs b/sig/mindee/parsing/common/job.rbs index 7533d821..2b764519 100644 --- a/sig/mindee/parsing/common/job.rbs +++ b/sig/mindee/parsing/common/job.rbs @@ -3,13 +3,13 @@ module Mindee module Parsing module Common class Job - def id: -> untyped - def issued_at: -> untyped - def available_at: -> untyped - def status: -> untyped + def id: -> String + def issued_at: -> Time + def available_at: -> Time + def status: () -> (:waiting | :processing | :completed | :failed) def millisecs_taken: -> Integer - def error: -> untyped - def initialize: (untyped) -> untyped + def error: -> Hash[Symbol | String, untyped] + def initialize: (Hash[Symbol | String, untyped]) -> void end end end diff --git a/sig/mindee/parsing/common/ocr/mvision_v1.rbs b/sig/mindee/parsing/common/ocr/mvision_v1.rbs index 64f10c40..e178c3e0 100644 --- a/sig/mindee/parsing/common/ocr/mvision_v1.rbs +++ b/sig/mindee/parsing/common/ocr/mvision_v1.rbs @@ -2,7 +2,7 @@ module Mindee module Parsing module Common - module Ocr + module OCR class MVisionV1 def pages: -> [] def initialize: (untyped) -> untyped diff --git a/sig/mindee/parsing/common/ocr/ocr.rbs b/sig/mindee/parsing/common/ocr/ocr.rbs index 9f2cadcc..dbf97e19 100644 --- a/sig/mindee/parsing/common/ocr/ocr.rbs +++ b/sig/mindee/parsing/common/ocr/ocr.rbs @@ -2,32 +2,32 @@ module Mindee module Parsing module Common - module Ocr - class OcrWord + module OCR + class OCRWord def confidence: -> untyped def confidence=: (untyped) -> untyped def text: -> untyped def bounding_box: -> untyped def polygon: -> untyped - def initialize: (untyped) -> nil + def initialize: (untyped) -> void def to_s: -> untyped end - class OcrLine < Array[untyped] + class OCRLine < Array[untyped] def initialize: (?Array[untyped]?, ?Array[untyped]?) -> void - def sort_on_x: -> OcrLine + def sort_on_x: -> OCRLine def to_s: -> String end - class OcrPage + 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 parse_one: (Array[OCRWord], untyped, Array[untyped], Array[untyped]) -> Array[OCRLine]? def to_lines: -> Array[untyped] - def words_on_same_line?: (OcrWord, OcrWord) -> untyped + def words_on_same_line?: (OCRWord, OCRWord) -> untyped end - class Ocr + class OCR def mvision_v1: -> untyped def initialize: (untyped) -> untyped def to_s: -> untyped diff --git a/sig/mindee/parsing/common/prediction.rbs b/sig/mindee/parsing/common/prediction.rbs index 2c4c6b13..20902f7c 100644 --- a/sig/mindee/parsing/common/prediction.rbs +++ b/sig/mindee/parsing/common/prediction.rbs @@ -4,7 +4,7 @@ module Mindee module Common class Prediction def to_s: -> String - def initialize: (untyped?) -> void + def initialize: (untyped?, untyped?) -> void end end end diff --git a/sig/mindee/parsing/standard/abstract_field.rbs b/sig/mindee/parsing/standard/abstract_field.rbs index 70b04681..0374fa1e 100644 --- a/sig/mindee/parsing/standard/abstract_field.rbs +++ b/sig/mindee/parsing/standard/abstract_field.rbs @@ -3,16 +3,16 @@ module Mindee module Parsing module Standard class AbstractField - def bounding_box: -> untyped - def polygon: -> untyped - def page_id: -> untyped - def confidence: -> untyped - def confidence=: (untyped) -> untyped - def initialize: (untyped, untyped) -> untyped + 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: (untyped) -> Float - def self.array_sum: (untyped) -> Float - def self.float_to_string: (untyped, ?Integer) -> 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 diff --git a/sig/mindee/parsing/standard/base_field.rbs b/sig/mindee/parsing/standard/base_field.rbs index d8866971..a92fb08f 100644 --- a/sig/mindee/parsing/standard/base_field.rbs +++ b/sig/mindee/parsing/standard/base_field.rbs @@ -3,9 +3,9 @@ module Mindee module Parsing module Standard class BaseField < Parsing::Standard::AbstractField - def value: -> untyped - def reconstructed: -> false - def initialize: (untyped, untyped, ?reconstructed: false) -> false + def initialize: (Hash[Symbol | String, untyped], Integer?, ?reconstructed: bool) -> void + def value: -> (String | Float | Integer | bool) + def reconstructed: -> bool end end end diff --git a/sig/mindee/parsing/standard/boolean_field.rbs b/sig/mindee/parsing/standard/boolean_field.rbs index 769822d0..77fdeca6 100644 --- a/sig/mindee/parsing/standard/boolean_field.rbs +++ b/sig/mindee/parsing/standard/boolean_field.rbs @@ -3,8 +3,8 @@ module Mindee module Parsing module Standard class BooleanField < BaseField - def value: -> untyped - def initialize: (untyped, ?nil, ?reconstructed: false) -> void + def value: -> bool? + def initialize: (Hash[Symbol | String, untyped], ?Integer?, ?reconstructed: false) -> void def to_s: -> String end end diff --git a/sig/mindee/parsing/standard/classification_field.rbs b/sig/mindee/parsing/standard/classification_field.rbs index 8e3ef431..81cfd536 100644 --- a/sig/mindee/parsing/standard/classification_field.rbs +++ b/sig/mindee/parsing/standard/classification_field.rbs @@ -2,8 +2,8 @@ module Mindee module Parsing module Standard - class ClassificationField # failed to identify its superclass - def value: -> untyped + class ClassificationField < BaseField + def value: -> String end end end diff --git a/sig/mindee/parsing/standard/feature_field.rbs b/sig/mindee/parsing/standard/feature_field.rbs index e71046eb..863439e1 100644 --- a/sig/mindee/parsing/standard/feature_field.rbs +++ b/sig/mindee/parsing/standard/feature_field.rbs @@ -2,8 +2,8 @@ module Mindee module Parsing module Standard - class FeatureField # failed to identify its superclass - def format_for_display: (untyped, ?nil) -> String + class FeatureField < BaseField + def format_for_display: (String | bool?, ?Integer?) -> String end end end diff --git a/sig/mindee/parsing/standard/locale_field.rbs b/sig/mindee/parsing/standard/locale_field.rbs index 297b0073..d806cd77 100644 --- a/sig/mindee/parsing/standard/locale_field.rbs +++ b/sig/mindee/parsing/standard/locale_field.rbs @@ -3,12 +3,12 @@ module Mindee module Parsing module Standard class LocaleField - def confidence: -> untyped - def language: -> untyped - def country: -> untyped - def currency: -> untyped - def value: -> untyped - def initialize: (untyped, ?nil) -> untyped + 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 diff --git a/sig/mindee/parsing/standard/string_field.rbs b/sig/mindee/parsing/standard/string_field.rbs index 2803d133..9ff2314a 100644 --- a/sig/mindee/parsing/standard/string_field.rbs +++ b/sig/mindee/parsing/standard/string_field.rbs @@ -2,10 +2,10 @@ module Mindee module Parsing module Standard - class StringField # failed to identify its superclass - def value: -> untyped - def raw_value: -> untyped - def initialize: (untyped, ?nil, ?reconstructed: false) -> untyped + class StringField < BaseField + def value: -> String + def raw_value: -> String + def initialize: (Hash[Symbol | String, untyped], ?Integer?, ?reconstructed: bool) -> void end end end diff --git a/sig/mindee/parsing/universal/universal_list_field.rbs b/sig/mindee/parsing/universal/universal_list_field.rbs index 47d546f6..65616258 100644 --- a/sig/mindee/parsing/universal/universal_list_field.rbs +++ b/sig/mindee/parsing/universal/universal_list_field.rbs @@ -4,11 +4,11 @@ module Mindee module Universal class UniversalListField include Universal - def page_id: -> untyped - def page_id=: (untyped) -> untyped - def values: -> [] - def values=: (untyped) -> [] - def initialize: (untyped, ?nil) -> untyped + def page_id: -> Integer? + def page_id=: (Integer?) -> Integer? + def values: -> Array[untyped] + def values=: (untyped) -> Array[untyped] + def initialize: (Array[Hash[Symbol | String, untyped]], ?nil) -> untyped def contents_list: -> Array[untyped] def contents_string: (?String) -> String def to_s: -> String diff --git a/sig/mindee/pdf/pdf_compressor.rbs b/sig/mindee/pdf/pdf_compressor.rbs index 04038aad..91e0bbfe 100644 --- a/sig/mindee/pdf/pdf_compressor.rbs +++ b/sig/mindee/pdf/pdf_compressor.rbs @@ -5,11 +5,11 @@ module Mindee module PDF module PDFCompressor def self.logger: () -> untyped - def self.compress_pdf: (untyped, ?quality: Integer, ?force_source_text_compression: false, ?disable_source_text: true) -> StringIO - def self.process_pdf_pages: (untyped, Integer) -> untyped - def self.create_output_pdf: (untyped, true, untyped) -> untyped - def self.inject_text: (untyped, untyped) -> nil - def self.process_pdf_page: (untyped, untyped, Integer, untyped) -> 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_processor.rbs b/sig/mindee/pdf/pdf_processor.rbs index 2710e62e..3697527a 100644 --- a/sig/mindee/pdf/pdf_processor.rbs +++ b/sig/mindee/pdf/pdf_processor.rbs @@ -2,12 +2,11 @@ module Mindee module PDF module PDFProcessor - DEFAULT_OPTIONS: Hash[Symbol, untyped] - def self.parse: (StringIO, Hash[Symbol, Array[untyped]]) -> nil + 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) -> untyped - def self.get_page: (untyped, untyped) -> nil + def self.open_pdf: (StringIO) -> Origami::PDF + def self.get_page: (Origami::PDF, Integer) -> StringIO 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_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..7bb7dd8b --- /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: -> (Array[Product::BillOfLading::BillOfLadingV1CarrierItem]) + 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..3502fdd4 --- /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: -> (Array[Product::FinancialDocument::FinancialDocumentV1LineItem]) + 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_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_v1.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v1.rbs new file mode 100644 index 00000000..ea9010a4 --- /dev/null +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v1.rbs @@ -0,0 +1,13 @@ +# lib/mindee/product/../bank_statement/bank_statement_v1.rb + +module Mindee + module Product + module FR + module BankStatement + class BankStatementV1 < 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_v1_document.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v1_document.rbs new file mode 100644 index 00000000..59f359f7 --- /dev/null +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v1_document.rbs @@ -0,0 +1,29 @@ +# lib/mindee/product/../bank_statement/bank_statement_v1_document.rb + +module Mindee + module Product + module FR + module BankStatement + class BankStatementV1Document < 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_name: -> (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: -> (Array[Product::FR::BankStatement::BankStatementV1Transaction]) + 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_v1_page.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v1_page.rbs new file mode 100644 index 00000000..6566b0aa --- /dev/null +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v1_page.rbs @@ -0,0 +1,17 @@ +# lib/mindee/product/../bank_statement/bank_statement_v1_page.rb + +module Mindee + module Product + module FR + module BankStatement + class BankStatementV1Page < Parsing::Common::Page + def initialize: (Hash[Symbol | String, untyped]) -> void + end + class BankStatementV1PagePrediction < BankStatementV1Document + 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_v1_transaction.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rbs new file mode 100644 index 00000000..731d130c --- /dev/null +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rbs @@ -0,0 +1,18 @@ +module Mindee + module Product + module FR + module BankStatement + class BankStatementV1Transaction < 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/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..db6f9b3c --- /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: -> (Array[Product::FR::EnergyBill::EnergyBillV1EnergyUsage]) + def invoice_date: -> (Parsing::Standard::DateField) + def invoice_number: -> (Parsing::Standard::StringField) + def meter_details: -> (Product::FR::EnergyBill::EnergyBillV1MeterDetail) + def subscription: -> (Array[Product::FR::EnergyBill::EnergyBillV1Subscription]) + def taxes_and_contributions: -> (Array[Product::FR::EnergyBill::EnergyBillV1TaxesAndContribution]) + 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_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_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/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..0228a9d4 --- /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: -> (Array[Product::FR::Payslip::PayslipV2SalaryDetail]) + 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_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..9cb0cb26 --- /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: -> (Array[Product::FR::Payslip::PayslipV3PaidTimeOff]) + def pay_detail: -> (Product::FR::Payslip::PayslipV3PayDetail) + def pay_period: -> (Product::FR::Payslip::PayslipV3PayPeriod) + def salary_details: -> (Array[Product::FR::Payslip::PayslipV3SalaryDetail]) + 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_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/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..cfe3efae --- /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: -> (Array[Product::Invoice::InvoiceV4LineItem]) + 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_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 index baa48e6a..6c736b6b 100644 --- a/sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs +++ b/sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs @@ -3,11 +3,11 @@ module Mindee module Product module InvoiceSplitter class InvoiceSplitterV1 < Parsing::Common::Inference - def initialize: (untyped) -> untyped - def endpoint_name: -> untyped - def endpoint_version: -> untyped - def has_async: -> untyped - def has_sync: -> untyped + 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 diff --git a/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs index 9b23ddcf..cf07f28f 100644 --- a/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs +++ b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs @@ -3,15 +3,15 @@ module Mindee module Product module InvoiceSplitter class InvoiceSplitterV1PageGroup - def page_indexes: -> untyped + def page_indexes: -> Array[Integer] def confidence: -> Float? - def initialize: (untyped) -> Float? + def initialize: (Hash[Symbol | String, untyped]) -> void def to_s: -> String end class InvoiceSplitterV1Document < Parsing::Common::Prediction - def invoice_page_groups: -> Array[untyped] - def initialize: (untyped, untyped?) -> void - def construct_invoice_page_groups_from_prediction: (untyped) -> nil + 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 diff --git a/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs index 3eaef4aa..b2cf0c34 100644 --- a/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs +++ b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs @@ -3,7 +3,7 @@ module Mindee module Product module InvoiceSplitter class InvoiceSplitterV1Page < Parsing::Common::Page - def initialize: (untyped) -> untyped + def initialize: (Hash[Symbol | String, untyped]) -> void end class InvoiceSplitterV1PagePrediction < InvoiceSplitterV1Document def to_s: -> String 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 index d01b77a1..d433be3f 100644 --- a/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rbs +++ b/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rbs @@ -1,13 +1,10 @@ # lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rb + module Mindee module Product module MultiReceiptsDetector class MultiReceiptsDetectorV1 < Parsing::Common::Inference - def initialize: (untyped) -> untyped - def endpoint_name: -> untyped - def endpoint_version: -> untyped - def has_async: -> untyped - def has_sync: -> untyped + def initialize: (Hash[Symbol | String, untyped]) -> void 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 index 076aaf21..22e75d25 100644 --- 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 @@ -1,10 +1,11 @@ # lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb + module Mindee module Product module MultiReceiptsDetector class MultiReceiptsDetectorV1Document < Parsing::Common::Prediction - def receipts: -> [] - def initialize: (untyped, ?untyped) -> void + def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def receipts: -> (Array[Parsing::Standard::PositionField]) def to_s: -> String 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 index f033194f..2c677dcd 100644 --- 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 @@ -1,11 +1,13 @@ # 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: (untyped) -> void + 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 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..043ce4f6 --- /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: -> (Array[Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrient]) + 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_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..17673b31 --- /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: -> (Array[Product::Receipt::ReceiptV5LineItem]) + 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_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_document.rbs b/sig/mindee/product/resume/resume_v1_document.rbs new file mode 100644 index 00000000..24bf0c59 --- /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: -> (Array[Product::Resume::ResumeV1Certificate]) + def document_language: -> (Parsing::Standard::StringField) + def document_type: -> (Parsing::Standard::ClassificationField) + def education: -> (Array[Product::Resume::ResumeV1Education]) + 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: -> (Array[Product::Resume::ResumeV1Language]) + def nationality: -> (Parsing::Standard::StringField) + def phone_number: -> (Parsing::Standard::StringField) + def profession: -> (Parsing::Standard::StringField) + def professional_experiences: -> (Array[Product::Resume::ResumeV1ProfessionalExperience]) + def social_networks_urls: -> (Array[Product::Resume::ResumeV1SocialNetworksUrl]) + 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_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_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_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/universal/universal_document.rbs b/sig/mindee/product/universal/universal_document.rbs index 68c3242e..dfed539b 100644 --- a/sig/mindee/product/universal/universal_document.rbs +++ b/sig/mindee/product/universal/universal_document.rbs @@ -3,7 +3,7 @@ module Mindee module Product module Universal class UniversalDocument < Parsing::Common::Document - def initialize: (untyped) -> untyped + def initialize: (Hash[Symbol | String, untyped]) -> void end end end diff --git a/sig/mindee/product/universal/universal_page.rbs b/sig/mindee/product/universal/universal_page.rbs index d7313559..f928c8eb 100644 --- a/sig/mindee/product/universal/universal_page.rbs +++ b/sig/mindee/product/universal/universal_page.rbs @@ -3,10 +3,10 @@ module Mindee module Product module Universal class UniversalPage < Parsing::Common::Page - def initialize: (untyped) -> untyped + def initialize: (Hash[Symbol | String, untyped]) -> void end class UniversalPagePrediction < UniversalPrediction - def initialize: (untyped, ?nil) -> untyped + def initialize: (Hash[Symbol | String, untyped], ?nil) -> void def to_s: -> String end end diff --git a/sig/mindee/product/universal/universal_prediction.rbs b/sig/mindee/product/universal/universal_prediction.rbs index 6cc7f0b4..176e4904 100644 --- a/sig/mindee/product/universal/universal_prediction.rbs +++ b/sig/mindee/product/universal/universal_prediction.rbs @@ -3,13 +3,13 @@ module Mindee module Product module Universal class UniversalPrediction < Parsing::Common::Prediction - def fields: -> Hash[untyped, untyped] + def fields: -> Hash[Symbol | String, untyped] def initialize: (untyped?) -> void def to_s: -> String - def generate_field_string: (untyped, untyped, Regexp) -> String - def generate_list_field_string: (untyped, untyped, untyped) -> String - def generate_sub_value_string: (untyped, untyped, untyped) -> String - def single_fields: -> Hash[untyped, untyped] + 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] 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_document.rbs b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_document.rbs new file mode 100644 index 00000000..1a275099 --- /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: -> (Array[Product::US::HealthcareCard::HealthcareCardV1Copay]) + 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..1dcb7cbc --- /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: -> (Array[Product::US::UsMail::UsMailV3RecipientAddress]) + 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_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/spec/document/fr/bank_statement_v1_spec.rb b/spec/document/fr/bank_statement_v1_spec.rb index 21c66fb6..e643acb8 100644 --- a/spec/document/fr/bank_statement_v1_spec.rb +++ b/spec/document/fr/bank_statement_v1_spec.rb @@ -9,7 +9,7 @@ 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 + context 'A Bank Statement 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( diff --git a/spec/extras/full_text_ocr_spec.rb b/spec/extras/full_text_ocr_spec.rb index 35140b13..685d93b3 100644 --- a/spec/extras/full_text_ocr_spec.rb +++ b/spec/extras/full_text_ocr_spec.rb @@ -69,12 +69,11 @@ 'version' => 'mock_version', }, 'pages' => [ - {}, { 'extras' => {}, 'id' => 0, 'orientation' => { - 'value' => nil, + 'value' => 0, }, 'prediction' => {}, }, 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/pdf/pdf_processor_spec.rb b/spec/pdf/pdf_processor_spec.rb index a5b4143f..63eda9b4 100644 --- a/spec/pdf/pdf_processor_spec.rb +++ b/spec/pdf/pdf_processor_spec.rb @@ -17,11 +17,11 @@ def open_pdf(io_stream) 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, - } + 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) @@ -30,11 +30,11 @@ def open_pdf(io_stream) 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, - } + 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) @@ -47,11 +47,11 @@ def open_pdf(io_stream) 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, - } + 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) @@ -60,11 +60,11 @@ def open_pdf(io_stream) 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, - } + 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) @@ -73,11 +73,11 @@ def open_pdf(io_stream) 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, - } + 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) @@ -86,11 +86,11 @@ def open_pdf(io_stream) 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, - } + 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) @@ -99,11 +99,11 @@ def open_pdf(io_stream) 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, - } + 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) @@ -112,11 +112,11 @@ def open_pdf(io_stream) it 'Should fail on invalid operation' do io_stream = File.open(filepath, 'rb') io_stream.seek(0) - options = { - page_indexes: [1], - operation: :broken, - on_min_pages: 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 From 7edf4a6989b907f4e86ff9d48ad7cedb078de518 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 18 Feb 2025 10:26:27 +0100 Subject: [PATCH 15/17] :sparkles: add support for multiple fields (#155) --- Steepfile | 1 + .../input/sources/local_input_source.rb | 17 ++++ lib/mindee/logging/logger.rb | 2 + .../universal/universal_object_field.rb | 20 +++-- .../bill_of_lading_v1_carrier_items.rb | 62 ++++++++++++++ .../bill_of_lading_v1_document.rb | 9 +- .../financial_document_v1_document.rb | 11 ++- .../financial_document_v1_line_items.rb | 62 ++++++++++++++ .../bank_statement_v1_document.rb | 11 ++- .../bank_statement_v1_transactions.rb | 54 ++++++++++++ .../fr/energy_bill/energy_bill_v1_document.rb | 29 +++---- .../energy_bill_v1_energy_usages.rb | 65 +++++++++++++++ .../energy_bill_v1_subscriptions.rb | 65 +++++++++++++++ .../energy_bill_v1_taxes_and_contributions.rb | 65 +++++++++++++++ .../product/fr/payslip/payslip_v2_document.rb | 9 +- .../fr/payslip/payslip_v2_salary_details.rb | 63 ++++++++++++++ .../product/fr/payslip/payslip_v3_document.rb | 18 ++-- .../fr/payslip/payslip_v3_paid_time_offs.rb | 65 +++++++++++++++ .../fr/payslip/payslip_v3_salary_details.rb | 65 +++++++++++++++ .../product/invoice/invoice_v4_document.rb | 9 +- .../product/invoice/invoice_v4_line_items.rb | 62 ++++++++++++++ .../nutrition_facts_label_v1_document.rb | 11 ++- .../nutrition_facts_label_v1_nutrients.rb | 68 +++++++++++++++ .../product/receipt/receipt_v5_document.rb | 9 +- .../product/receipt/receipt_v5_line_items.rb | 54 ++++++++++++ .../product/resume/resume_v1_certificates.rb | 58 +++++++++++++ .../product/resume/resume_v1_document.rb | 49 +++++------ .../product/resume/resume_v1_educations.rb | 64 ++++++++++++++ .../product/resume/resume_v1_languages.rb | 54 ++++++++++++ .../resume_v1_professional_experiences.rb | 68 +++++++++++++++ .../resume/resume_v1_social_networks_urls.rb | 54 ++++++++++++ .../healthcare_card_v1_copays.rb | 52 ++++++++++++ .../healthcare_card_v1_document.rb | 9 +- .../product/us/us_mail/us_mail_v3_document.rb | 11 ++- .../us_mail/us_mail_v3_recipient_addresses.rb | 65 +++++++++++++++ .../input/sources/local_input_source.rbs | 1 + .../parsing/standard/position_field.rbs | 14 ++-- .../universal/universal_list_field.rbs | 9 +- .../universal/universal_object_field.rbs | 24 +++--- .../bill_of_lading_v1_carrier_items.rbs | 13 +++ .../bill_of_lading_v1_document.rbs | 2 +- .../financial_document_v1_document.rbs | 2 +- .../financial_document_v1_line_items.rbs | 13 +++ .../bank_statement_v1_document.rbs | 2 +- .../bank_statement_v1_transactions.rbs | 15 ++++ .../energy_bill/energy_bill_v1_document.rbs | 6 +- .../energy_bill_v1_energy_usages.rbs | 15 ++++ .../energy_bill_v1_subscriptions.rbs | 15 ++++ ...energy_bill_v1_taxes_and_contributions.rbs | 15 ++++ .../fr/payslip/payslip_v2_document.rbs | 2 +- .../fr/payslip/payslip_v2_salary_details.rbs | 15 ++++ .../fr/payslip/payslip_v3_document.rbs | 4 +- .../fr/payslip/payslip_v3_paid_time_offs.rbs | 15 ++++ .../fr/payslip/payslip_v3_salary_details.rbs | 15 ++++ .../product/invoice/invoice_v4_document.rbs | 2 +- .../product/invoice/invoice_v4_line_items.rbs | 13 +++ .../nutrition_facts_label_v1_document.rbs | 2 +- .../nutrition_facts_label_v1_nutrients.rbs | 13 +++ .../product/receipt/receipt_v5_document.rbs | 2 +- .../product/receipt/receipt_v5_line_items.rbs | 13 +++ .../product/resume/resume_v1_certificates.rbs | 13 +++ .../product/resume/resume_v1_document.rbs | 10 +-- .../product/resume/resume_v1_educations.rbs | 13 +++ .../product/resume/resume_v1_languages.rbs | 13 +++ .../resume_v1_professional_experiences.rbs | 13 +++ .../resume/resume_v1_social_networks_urls.rbs | 13 +++ .../healthcare_card_v1_copays.rbs | 15 ++++ .../healthcare_card_v1_document.rbs | 2 +- .../us/us_mail/us_mail_v3_document.rbs | 2 +- .../us_mail_v3_recipient_addresses.rbs | 15 ++++ spec/document/fr/bank_statement_v2_spec.rb | 32 ------- ...invoice_splitter_extraction_integration.rb | 1 - spec/extras/full_text_ocr_spec.rb | 7 +- spec/image/image_utils_spec.rb | 1 - spec/input/sources/local_input_source_spec.rb | 33 ++++++++ .../sources/url_input_source_integration.rb | 1 - spec/input/sources/url_input_source_spec.rb | 3 +- .../universal/universal_list_field_spec.rb | 37 +++++++++ .../universal/universal_object_field_spec.rb | 83 +++++++++++++++++++ spec/pdf/extracted_pdf_spec.rb | 1 - spec/pdf/pdf_extractor_spec.rb | 1 - .../barcode_reader_v1_spec.rb | 0 .../bill_of_lading_v1_spec.rb | 0 .../business_card_v1_spec.rb | 0 spec/{document => product}/cropper_v1_spec.rb | 0 .../delivery_note_v1_spec.rb | 0 .../driver_license_v1_spec.rb | 0 .../eu/license_plate_v1_spec.rb | 0 .../financial_document_v1_spec.rb | 0 .../fr/bank_account_details_v1_spec.rb | 0 .../fr/bank_account_details_v2_spec.rb | 0 .../fr/bank_statement_v1_spec.rb | 0 spec/product/fr/bank_statement_v2_spec.rb | 0 .../fr/carte_grise_v1_spec.rb | 0 .../fr/energy_bill_v1_spec.rb | 0 .../fr/health_card_v1_spec.rb | 0 .../fr/id_card_v1_spec.rb | 0 .../fr/id_card_v2_spec.rb | 0 .../fr/payslip_v2_spec.rb | 0 .../fr/payslip_v3_spec.rb | 0 .../ind/indian_passport_v1_spec.rb | 0 .../international_id_v2_spec.rb | 0 .../invoice_splitter_v1_spec.rb | 0 spec/{document => product}/invoice_v4_spec.rb | 0 .../multi_receipts_detector_v1_spec.rb | 0 .../nutrition_facts_label_v1_spec.rb | 0 .../{document => product}/passport_v1_spec.rb | 0 spec/{document => product}/receipt_v5_spec.rb | 0 spec/{document => product}/resume_v1_spec.rb | 0 spec/{document => product}/universal_spec.rb | 7 +- .../us/bank_check_v1_spec.rb | 0 .../us/healthcare_card_v1_spec.rb | 0 .../us/us_mail_v3_spec.rb | 0 spec/{document => product}/us/w9_v1_spec.rb | 0 114 files changed, 1738 insertions(+), 210 deletions(-) create mode 100644 lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_items.rb create mode 100644 lib/mindee/product/financial_document/financial_document_v1_line_items.rb create mode 100644 lib/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rb create mode 100644 lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usages.rb create mode 100644 lib/mindee/product/fr/energy_bill/energy_bill_v1_subscriptions.rb create mode 100644 lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contributions.rb create mode 100644 lib/mindee/product/fr/payslip/payslip_v2_salary_details.rb create mode 100644 lib/mindee/product/fr/payslip/payslip_v3_paid_time_offs.rb create mode 100644 lib/mindee/product/fr/payslip/payslip_v3_salary_details.rb create mode 100644 lib/mindee/product/invoice/invoice_v4_line_items.rb create mode 100644 lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rb create mode 100644 lib/mindee/product/receipt/receipt_v5_line_items.rb create mode 100644 lib/mindee/product/resume/resume_v1_certificates.rb create mode 100644 lib/mindee/product/resume/resume_v1_educations.rb create mode 100644 lib/mindee/product/resume/resume_v1_languages.rb create mode 100644 lib/mindee/product/resume/resume_v1_professional_experiences.rb create mode 100644 lib/mindee/product/resume/resume_v1_social_networks_urls.rb create mode 100644 lib/mindee/product/us/healthcare_card/healthcare_card_v1_copays.rb create mode 100644 lib/mindee/product/us/us_mail/us_mail_v3_recipient_addresses.rb create mode 100644 sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_items.rbs create mode 100644 sig/mindee/product/financial_document/financial_document_v1_line_items.rbs create mode 100644 sig/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_usages.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_subscriptions.rbs create mode 100644 sig/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contributions.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v2_salary_details.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_paid_time_offs.rbs create mode 100644 sig/mindee/product/fr/payslip/payslip_v3_salary_details.rbs create mode 100644 sig/mindee/product/invoice/invoice_v4_line_items.rbs create mode 100644 sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrients.rbs create mode 100644 sig/mindee/product/receipt/receipt_v5_line_items.rbs create mode 100644 sig/mindee/product/resume/resume_v1_certificates.rbs create mode 100644 sig/mindee/product/resume/resume_v1_educations.rbs create mode 100644 sig/mindee/product/resume/resume_v1_languages.rbs create mode 100644 sig/mindee/product/resume/resume_v1_professional_experiences.rbs create mode 100644 sig/mindee/product/resume/resume_v1_social_networks_urls.rbs create mode 100644 sig/mindee/product/us/healthcare_card/healthcare_card_v1_copays.rbs create mode 100644 sig/mindee/product/us/us_mail/us_mail_v3_recipient_addresses.rbs delete mode 100644 spec/document/fr/bank_statement_v2_spec.rb create mode 100644 spec/input/sources/local_input_source_spec.rb create mode 100644 spec/parsing/universal/universal_list_field_spec.rb create mode 100644 spec/parsing/universal/universal_object_field_spec.rb rename spec/{document => product}/barcode_reader_v1_spec.rb (100%) rename spec/{document => product}/bill_of_lading_v1_spec.rb (100%) rename spec/{document => product}/business_card_v1_spec.rb (100%) rename spec/{document => product}/cropper_v1_spec.rb (100%) rename spec/{document => product}/delivery_note_v1_spec.rb (100%) rename spec/{document => product}/driver_license_v1_spec.rb (100%) rename spec/{document => product}/eu/license_plate_v1_spec.rb (100%) rename spec/{document => product}/financial_document_v1_spec.rb (100%) rename spec/{document => product}/fr/bank_account_details_v1_spec.rb (100%) rename spec/{document => product}/fr/bank_account_details_v2_spec.rb (100%) rename spec/{document => product}/fr/bank_statement_v1_spec.rb (100%) create mode 100644 spec/product/fr/bank_statement_v2_spec.rb rename spec/{document => product}/fr/carte_grise_v1_spec.rb (100%) rename spec/{document => product}/fr/energy_bill_v1_spec.rb (100%) rename spec/{document => product}/fr/health_card_v1_spec.rb (100%) rename spec/{document => product}/fr/id_card_v1_spec.rb (100%) rename spec/{document => product}/fr/id_card_v2_spec.rb (100%) rename spec/{document => product}/fr/payslip_v2_spec.rb (100%) rename spec/{document => product}/fr/payslip_v3_spec.rb (100%) rename spec/{document => product}/ind/indian_passport_v1_spec.rb (100%) rename spec/{document => product}/international_id_v2_spec.rb (100%) rename spec/{document => product}/invoice_splitter_v1_spec.rb (100%) rename spec/{document => product}/invoice_v4_spec.rb (100%) rename spec/{document => product}/multi_receipts_detector_v1_spec.rb (100%) rename spec/{document => product}/nutrition_facts_label_v1_spec.rb (100%) rename spec/{document => product}/passport_v1_spec.rb (100%) rename spec/{document => product}/receipt_v5_spec.rb (100%) rename spec/{document => product}/resume_v1_spec.rb (100%) rename spec/{document => product}/universal_spec.rb (99%) rename spec/{document => product}/us/bank_check_v1_spec.rb (100%) rename spec/{document => product}/us/healthcare_card_v1_spec.rb (100%) rename spec/{document => product}/us/us_mail_v3_spec.rb (100%) rename spec/{document => product}/us/w9_v1_spec.rb (100%) diff --git a/Steepfile b/Steepfile index ed43b765..73b80857 100644 --- a/Steepfile +++ b/Steepfile @@ -17,6 +17,7 @@ target :lib do # Do NOT enable them. # Use the stubs located at sig/custom/.rbs instead. library 'date' + library 'fileutils' library 'logger' library 'json' library 'openssl' diff --git a/lib/mindee/input/sources/local_input_source.rb b/lib/mindee/input/sources/local_input_source.rb index 3f4e5c97..7a0d1344 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' @@ -98,10 +99,26 @@ def read_contents(close: true) @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 + # 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] diff --git a/lib/mindee/logging/logger.rb b/lib/mindee/logging/logger.rb index fe0ffe2b..ec60b5eb 100644 --- a/lib/mindee/logging/logger.rb +++ b/lib/mindee/logging/logger.rb @@ -6,6 +6,8 @@ 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 diff --git a/lib/mindee/parsing/universal/universal_object_field.rb b/lib/mindee/parsing/universal/universal_object_field.rb index 26095d47..c5bbd4c4 100644 --- a/lib/mindee/parsing/universal/universal_object_field.rb +++ b/lib/mindee/parsing/universal/universal_object_field.rb @@ -8,8 +8,15 @@ module Parsing module Universal # A JSON-like object, with miscellaneous values. class UniversalObjectField - include Mindee::Parsing::Standard - attr_accessor :page_id, :confidence, :raw_value + # 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. # Confidence with which the value was assessed. @@ -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,7 +68,7 @@ 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. @@ -83,8 +90,7 @@ def to_s def handle_position_field(name, value, item_page_id) @all_values[name.to_s] = Mindee::Parsing::Standard::PositionField.new( - { name.to_s => value }, - value_key: name.to_s, page_id: item_page_id + { name.to_s => value }, item_page_id ) end @@ -104,7 +110,7 @@ def self.universal_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/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_document.rb b/lib/mindee/product/bill_of_lading/bill_of_lading_v1_document.rb index 21c488fc..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] @@ -59,10 +59,7 @@ def initialize(prediction, page_id) prediction['carrier'], page_id ) - @carrier_items = [] # : Array[BillOfLading::BillOfLadingV1CarrierItem] - prediction['carrier_items'].each do |item| - @carrier_items.push(BillOfLading::BillOfLadingV1CarrierItem.new(item, page_id)) - end + @carrier_items = Product::BillOfLading::BillOfLadingV1CarrierItems.new(prediction['carrier_items'], page_id) @consignee = Product::BillOfLading::BillOfLadingV1Consignee.new( prediction['consignee'], page_id 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 ec8df7ed..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] @@ -151,10 +151,9 @@ def initialize(prediction, page_id) prediction['invoice_number'], page_id ) - @line_items = [] # : Array[FinancialDocument::FinancialDocumentV1LineItem] - prediction['line_items'].each do |item| - @line_items.push(FinancialDocument::FinancialDocumentV1LineItem.new(item, page_id)) - end + @line_items = Product::FinancialDocument::FinancialDocumentV1LineItems.new( + prediction['line_items'], page_id + ) @locale = Parsing::Standard::LocaleField.new( prediction['locale'], page_id 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/fr/bank_statement/bank_statement_v1_document.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb index bced6caf..51fc68d3 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../../../parsing' -require_relative 'bank_statement_v1_transaction' +require_relative 'bank_statement_v1_transactions' module Mindee module Product @@ -47,7 +47,7 @@ class BankStatementV1Document < 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::BankStatementV1Transactions] attr_reader :transactions # @param prediction [Hash] @@ -102,10 +102,9 @@ def initialize(prediction, page_id) prediction['total_debits'], page_id ) - @transactions = [] # : Array[BankStatement::BankStatementV1Transaction] - prediction['transactions'].each do |item| - @transactions.push(BankStatement::BankStatementV1Transaction.new(item, page_id)) - end + @transactions = Product::FR::BankStatement::BankStatementV1Transactions.new( + prediction['transactions'], page_id + ) end # @return [String] diff --git a/lib/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rb new file mode 100644 index 00000000..0dcbeef3 --- /dev/null +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require_relative 'bank_statement_v1_transaction' + +module Mindee + module Product + module FR + module BankStatement + # The list of values that represent the financial transactions recorded in a bank statement. + class BankStatementV1Transactions < 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::BankStatementV1Transaction.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 * 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/energy_bill/energy_bill_v1_document.rb b/lib/mindee/product/fr/energy_bill/energy_bill_v1_document.rb index bcd0b5fb..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] @@ -83,10 +83,7 @@ def initialize(prediction, page_id) prediction['energy_supplier'], page_id ) - @energy_usage = [] # : Array[EnergyBill::EnergyBillV1EnergyUsage] - prediction['energy_usage'].each do |item| - @energy_usage.push(EnergyBill::EnergyBillV1EnergyUsage.new(item, page_id)) - end + @energy_usage = Product::FR::EnergyBill::EnergyBillV1EnergyUsages.new(prediction['energy_usage'], page_id) @invoice_date = Parsing::Standard::DateField.new( prediction['invoice_date'], page_id @@ -99,14 +96,10 @@ def initialize(prediction, page_id) prediction['meter_details'], page_id ) - @subscription = [] # : Array[EnergyBill::EnergyBillV1Subscription] - prediction['subscription'].each do |item| - @subscription.push(EnergyBill::EnergyBillV1Subscription.new(item, page_id)) - end - @taxes_and_contributions = [] # : Array[EnergyBill::EnergyBillV1TaxesAndContribution] - prediction['taxes_and_contributions'].each do |item| - @taxes_and_contributions.push(EnergyBill::EnergyBillV1TaxesAndContribution.new(item, page_id)) - end + @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 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_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_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/payslip/payslip_v2_document.rb b/lib/mindee/product/fr/payslip/payslip_v2_document.rb index fe9d9f07..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,7 +39,7 @@ 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] @@ -71,10 +71,7 @@ def initialize(prediction, page_id) page_id ) @pto = Product::FR::Payslip::PayslipV2Pto.new(prediction['pto'], page_id) - @salary_details = [] # : Array[Payslip::PayslipV2SalaryDetail] - prediction['salary_details'].each do |item| - @salary_details.push(Payslip::PayslipV2SalaryDetail.new(item, page_id)) - end + @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_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_document.rb b/lib/mindee/product/fr/payslip/payslip_v3_document.rb index 55a8aa26..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,7 +39,7 @@ 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] @@ -62,10 +62,7 @@ def initialize(prediction, page_id) prediction['employment'], page_id ) - @paid_time_off = [] # : Array[Payslip::PayslipV3PaidTimeOff] - prediction['paid_time_off'].each do |item| - @paid_time_off.push(Payslip::PayslipV3PaidTimeOff.new(item, page_id)) - end + @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 @@ -74,10 +71,7 @@ def initialize(prediction, page_id) prediction['pay_period'], page_id ) - @salary_details = [] # : Array[Payslip::PayslipV3SalaryDetail] - prediction['salary_details'].each do |item| - @salary_details.push(Payslip::PayslipV3SalaryDetail.new(item, page_id)) - end + @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_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_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/invoice/invoice_v4_document.rb b/lib/mindee/product/invoice/invoice_v4_document.rb index 3ab5ec10..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] @@ -125,10 +125,7 @@ def initialize(prediction, page_id) prediction['invoice_number'], page_id ) - @line_items = [] # : Array[Invoice::InvoiceV4LineItem] - prediction['line_items'].each do |item| - @line_items.push(Invoice::InvoiceV4LineItem.new(item, page_id)) - end + @line_items = Product::Invoice::InvoiceV4LineItems.new(prediction['line_items'], page_id) @locale = Parsing::Standard::LocaleField.new( prediction['locale'], page_id 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/nutrition_facts_label/nutrition_facts_label_v1_document.rb b/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb index e644c6ac..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] @@ -84,10 +84,9 @@ def initialize(prediction, page_id) prediction['dietary_fiber'], page_id ) - @nutrients = [] # : Array[NutritionFactsLabel::NutritionFactsLabelV1Nutrient] - prediction['nutrients'].each do |item| - @nutrients.push(NutritionFactsLabel::NutritionFactsLabelV1Nutrient.new(item, page_id)) - end + @nutrients = Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrients.new( + prediction['nutrients'], page_id + ) @protein = Product::NutritionFactsLabel::NutritionFactsLabelV1Protein.new( prediction['protein'], page_id 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/receipt/receipt_v5_document.rb b/lib/mindee/product/receipt/receipt_v5_document.rb index 66aad93b..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] @@ -74,10 +74,7 @@ def initialize(prediction, page_id) prediction['document_type'], page_id ) - @line_items = [] # : Array[Receipt::ReceiptV5LineItem] - prediction['line_items'].each do |item| - @line_items.push(Receipt::ReceiptV5LineItem.new(item, page_id)) - end + @line_items = Product::Receipt::ReceiptV5LineItems.new(prediction['line_items'], page_id) @locale = Parsing::Standard::LocaleField.new( prediction['locale'], page_id 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/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 77f4817e..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] @@ -73,10 +73,7 @@ def initialize(prediction, page_id) prediction['address'], page_id ) - @certificates = [] # : Array[Resume::ResumeV1Certificate] - prediction['certificates'].each do |item| - @certificates.push(Resume::ResumeV1Certificate.new(item, page_id)) - end + @certificates = Product::Resume::ResumeV1Certificates.new(prediction['certificates'], page_id) @document_language = Parsing::Standard::StringField.new( prediction['document_language'], page_id @@ -85,10 +82,7 @@ def initialize(prediction, page_id) prediction['document_type'], page_id ) - @education = [] # : Array[Resume::ResumeV1Education] - prediction['education'].each do |item| - @education.push(Resume::ResumeV1Education.new(item, page_id)) - end + @education = Product::Resume::ResumeV1Educations.new(prediction['education'], page_id) @email_address = Parsing::Standard::StringField.new( prediction['email_address'], page_id @@ -105,10 +99,7 @@ def initialize(prediction, page_id) prediction['job_applied'], page_id ) - @languages = [] # : Array[Resume::ResumeV1Language] - prediction['languages'].each do |item| - @languages.push(Resume::ResumeV1Language.new(item, page_id)) - end + @languages = Product::Resume::ResumeV1Languages.new(prediction['languages'], page_id) @nationality = Parsing::Standard::StringField.new( prediction['nationality'], page_id @@ -121,14 +112,12 @@ def initialize(prediction, page_id) prediction['profession'], page_id ) - @professional_experiences = [] # : Array[Resume::ResumeV1ProfessionalExperience] - prediction['professional_experiences'].each do |item| - @professional_experiences.push(Resume::ResumeV1ProfessionalExperience.new(item, page_id)) - end - @social_networks_urls = [] # : Array[Resume::ResumeV1SocialNetworksUrl] - prediction['social_networks_urls'].each do |item| - @social_networks_urls.push(Resume::ResumeV1SocialNetworksUrl.new(item, page_id)) - end + @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(Parsing::Standard::StringField.new(item, page_id)) 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_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_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_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/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 71c5902d..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] @@ -55,10 +55,7 @@ def initialize(prediction, page_id) prediction['company_name'], page_id ) - @copays = [] # : Array[HealthcareCard::HealthcareCardV1Copay] - prediction['copays'].each do |item| - @copays.push(HealthcareCard::HealthcareCardV1Copay.new(item, page_id)) - end + @copays = Product::US::HealthcareCard::HealthcareCardV1Copays.new(prediction['copays'], page_id) @dependents = [] # : Array[Parsing::Standard::StringField] prediction['dependents'].each do |item| @dependents.push(Parsing::Standard::StringField.new(item, page_id)) 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 68b5c725..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] @@ -35,10 +35,9 @@ def initialize(prediction, page_id) prediction['is_return_to_sender'], page_id ) - @recipient_addresses = [] # : Array[UsMail::UsMailV3RecipientAddress] - prediction['recipient_addresses'].each do |item| - @recipient_addresses.push(UsMail::UsMailV3RecipientAddress.new(item, page_id)) - end + @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(Parsing::Standard::StringField.new(item, page_id)) 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/sig/mindee/input/sources/local_input_source.rbs b/sig/mindee/input/sources/local_input_source.rbs index d7151dde..c3426120 100644 --- a/sig/mindee/input/sources/local_input_source.rbs +++ b/sig/mindee/input/sources/local_input_source.rbs @@ -14,6 +14,7 @@ module Mindee 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 diff --git a/sig/mindee/parsing/standard/position_field.rbs b/sig/mindee/parsing/standard/position_field.rbs index a30c3e4c..090df5c9 100644 --- a/sig/mindee/parsing/standard/position_field.rbs +++ b/sig/mindee/parsing/standard/position_field.rbs @@ -3,14 +3,14 @@ module Mindee module Parsing module Standard class PositionField - def polygon: -> untyped - def value: -> untyped - def quadrangle: -> nil - def rectangle: -> nil - def bounding_box: -> nil - def initialize: (untyped, untyped) -> untyped + 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: (untyped, String) -> nil + def to_quadrilateral: (Hash[Symbol | String, Array[untyped]], String) -> Geometry::Quadrilateral? end end end diff --git a/sig/mindee/parsing/universal/universal_list_field.rbs b/sig/mindee/parsing/universal/universal_list_field.rbs index 65616258..692cb141 100644 --- a/sig/mindee/parsing/universal/universal_list_field.rbs +++ b/sig/mindee/parsing/universal/universal_list_field.rbs @@ -3,13 +3,12 @@ module Mindee module Parsing module Universal class UniversalListField - include Universal def page_id: -> Integer? - def page_id=: (Integer?) -> Integer? - def values: -> Array[untyped] - def values=: (untyped) -> Array[untyped] + 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[untyped] + def contents_list: -> Array[String] def contents_string: (?String) -> String def to_s: -> String end diff --git a/sig/mindee/parsing/universal/universal_object_field.rbs b/sig/mindee/parsing/universal/universal_object_field.rbs index 61f8a325..5e97e672 100644 --- a/sig/mindee/parsing/universal/universal_object_field.rbs +++ b/sig/mindee/parsing/universal/universal_object_field.rbs @@ -3,21 +3,21 @@ module Mindee module Parsing module Universal class UniversalObjectField - def page_id: -> untyped - def page_id=: (untyped) -> untyped - def confidence: -> untyped - def confidence=: (untyped) -> untyped - def raw_value: -> untyped - def raw_value=: (untyped) -> untyped - def initialize: (untyped, ?nil) -> untyped + 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: (untyped, *untyped) -> nil - def respond_to_missing?: (untyped, ?false) -> bool + def method_missing: (Symbol, *Array[untyped]) -> Object + def respond_to_missing?: (Symbol, ?bool) -> bool def to_s: -> String - def handle_position_field: (untyped, untyped, untyped) -> untyped - def handle_default_field: (untyped, untyped) -> nil + def handle_position_field: (String | Symbol, untyped, Integer?) -> void + def handle_default_field: (String | Symbol, untyped) -> void end - def self.universal_object?: (untyped) -> bool + def self.universal_object?: (Hash[Symbol | String, untyped]) -> bool 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_document.rbs b/sig/mindee/product/bill_of_lading/bill_of_lading_v1_document.rbs index 7bb7dd8b..68e6a05b 100644 --- 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 @@ -7,7 +7,7 @@ module Mindee def initialize: (Hash[Symbol | String, untyped], Integer?) -> void def bill_of_lading_number: -> (Parsing::Standard::StringField) def carrier: -> (Product::BillOfLading::BillOfLadingV1Carrier) - def carrier_items: -> (Array[Product::BillOfLading::BillOfLadingV1CarrierItem]) + def carrier_items: -> (Product::BillOfLading::BillOfLadingV1CarrierItems) def consignee: -> (Product::BillOfLading::BillOfLadingV1Consignee) def date_of_issue: -> (Parsing::Standard::DateField) def departure_date: -> (Parsing::Standard::DateField) diff --git a/sig/mindee/product/financial_document/financial_document_v1_document.rbs b/sig/mindee/product/financial_document/financial_document_v1_document.rbs index 3502fdd4..b38c14b8 100644 --- a/sig/mindee/product/financial_document/financial_document_v1_document.rbs +++ b/sig/mindee/product/financial_document/financial_document_v1_document.rbs @@ -16,7 +16,7 @@ module Mindee def document_type: -> (Parsing::Standard::ClassificationField) def due_date: -> (Parsing::Standard::DateField) def invoice_number: -> (Parsing::Standard::StringField) - def line_items: -> (Array[Product::FinancialDocument::FinancialDocumentV1LineItem]) + def line_items: -> (Product::FinancialDocument::FinancialDocumentV1LineItems) def locale: -> (Parsing::Standard::LocaleField) def payment_date: -> (Parsing::Standard::DateField) def po_number: -> (Parsing::Standard::StringField) 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/fr/bank_statement/bank_statement_v1_document.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v1_document.rbs index 59f359f7..fe70db07 100644 --- a/sig/mindee/product/fr/bank_statement/bank_statement_v1_document.rbs +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v1_document.rbs @@ -18,7 +18,7 @@ module Mindee def statement_start_date: -> (Parsing::Standard::DateField) def total_credits: -> (Parsing::Standard::AmountField) def total_debits: -> (Parsing::Standard::AmountField) - def transactions: -> (Array[Product::FR::BankStatement::BankStatementV1Transaction]) + def transactions: -> (Product::FR::BankStatement::BankStatementV1Transactions) def transactions_separator: (String) -> String def transactions_to_s: -> String def to_s: -> String diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rbs new file mode 100644 index 00000000..5acc6cec --- /dev/null +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rbs @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mindee + module Product + module FR + module BankStatement + class BankStatementV1Transactions < 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_document.rbs b/sig/mindee/product/fr/energy_bill/energy_bill_v1_document.rbs index db6f9b3c..526d7b7e 100644 --- a/sig/mindee/product/fr/energy_bill/energy_bill_v1_document.rbs +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_document.rbs @@ -11,12 +11,12 @@ module Mindee def due_date: -> (Parsing::Standard::DateField) def energy_consumer: -> (Product::FR::EnergyBill::EnergyBillV1EnergyConsumer) def energy_supplier: -> (Product::FR::EnergyBill::EnergyBillV1EnergySupplier) - def energy_usage: -> (Array[Product::FR::EnergyBill::EnergyBillV1EnergyUsage]) + 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: -> (Array[Product::FR::EnergyBill::EnergyBillV1Subscription]) - def taxes_and_contributions: -> (Array[Product::FR::EnergyBill::EnergyBillV1TaxesAndContribution]) + 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) 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_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_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/payslip/payslip_v2_document.rbs b/sig/mindee/product/fr/payslip/payslip_v2_document.rbs index 0228a9d4..922974b1 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_document.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_document.rbs @@ -13,7 +13,7 @@ module Mindee def pay_detail: -> (Product::FR::Payslip::PayslipV2PayDetail) def pay_period: -> (Product::FR::Payslip::PayslipV2PayPeriod) def pto: -> (Product::FR::Payslip::PayslipV2Pto) - def salary_details: -> (Array[Product::FR::Payslip::PayslipV2SalaryDetail]) + def salary_details: -> (Product::FR::Payslip::PayslipV2SalaryDetails) def salary_details_separator: (String) -> String def salary_details_to_s: -> String def to_s: -> String 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_document.rbs b/sig/mindee/product/fr/payslip/payslip_v3_document.rbs index 9cb0cb26..33a9dbd3 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_document.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_document.rbs @@ -10,10 +10,10 @@ module Mindee def employee: -> (Product::FR::Payslip::PayslipV3Employee) def employer: -> (Product::FR::Payslip::PayslipV3Employer) def employment: -> (Product::FR::Payslip::PayslipV3Employment) - def paid_time_off: -> (Array[Product::FR::Payslip::PayslipV3PaidTimeOff]) + 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: -> (Array[Product::FR::Payslip::PayslipV3SalaryDetail]) + 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 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_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/invoice/invoice_v4_document.rbs b/sig/mindee/product/invoice/invoice_v4_document.rbs index cfe3efae..bb69dd3d 100644 --- a/sig/mindee/product/invoice/invoice_v4_document.rbs +++ b/sig/mindee/product/invoice/invoice_v4_document.rbs @@ -14,7 +14,7 @@ module Mindee def document_type: -> (Parsing::Standard::ClassificationField) def due_date: -> (Parsing::Standard::DateField) def invoice_number: -> (Parsing::Standard::StringField) - def line_items: -> (Array[Product::Invoice::InvoiceV4LineItem]) + def line_items: -> (Product::Invoice::InvoiceV4LineItems) def locale: -> (Parsing::Standard::LocaleField) def payment_date: -> (Parsing::Standard::DateField) def po_number: -> (Parsing::Standard::StringField) 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/nutrition_facts_label/nutrition_facts_label_v1_document.rbs b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rbs index 043ce4f6..7f02aba9 100644 --- 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 @@ -9,7 +9,7 @@ module Mindee def calories: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Calorie) def cholesterol: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Cholesterol) def dietary_fiber: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1DietaryFiber) - def nutrients: -> (Array[Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrient]) + def nutrients: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Nutrients) def protein: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Protein) def saturated_fat: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1SaturatedFat) def serving_per_box: -> (Parsing::Standard::AmountField) 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/receipt/receipt_v5_document.rbs b/sig/mindee/product/receipt/receipt_v5_document.rbs index 17673b31..901659c1 100644 --- a/sig/mindee/product/receipt/receipt_v5_document.rbs +++ b/sig/mindee/product/receipt/receipt_v5_document.rbs @@ -8,7 +8,7 @@ module Mindee def category: -> (Parsing::Standard::ClassificationField) def date: -> (Parsing::Standard::DateField) def document_type: -> (Parsing::Standard::ClassificationField) - def line_items: -> (Array[Product::Receipt::ReceiptV5LineItem]) + def line_items: -> (Product::Receipt::ReceiptV5LineItems) def locale: -> (Parsing::Standard::LocaleField) def receipt_number: -> (Parsing::Standard::StringField) def subcategory: -> (Parsing::Standard::ClassificationField) 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/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 index 24bf0c59..586f4d08 100644 --- a/sig/mindee/product/resume/resume_v1_document.rbs +++ b/sig/mindee/product/resume/resume_v1_document.rbs @@ -6,20 +6,20 @@ module Mindee class ResumeV1Document < Parsing::Common::Prediction def initialize: (Hash[Symbol | String, untyped], Integer?) -> void def address: -> (Parsing::Standard::StringField) - def certificates: -> (Array[Product::Resume::ResumeV1Certificate]) + def certificates: -> (Product::Resume::ResumeV1Certificates) def document_language: -> (Parsing::Standard::StringField) def document_type: -> (Parsing::Standard::ClassificationField) - def education: -> (Array[Product::Resume::ResumeV1Education]) + 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: -> (Array[Product::Resume::ResumeV1Language]) + def languages: -> (Product::Resume::ResumeV1Languages) def nationality: -> (Parsing::Standard::StringField) def phone_number: -> (Parsing::Standard::StringField) def profession: -> (Parsing::Standard::StringField) - def professional_experiences: -> (Array[Product::Resume::ResumeV1ProfessionalExperience]) - def social_networks_urls: -> (Array[Product::Resume::ResumeV1SocialNetworksUrl]) + 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 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_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_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_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/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 index 1a275099..9dccc1c5 100644 --- a/sig/mindee/product/us/healthcare_card/healthcare_card_v1_document.rbs +++ b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_document.rbs @@ -7,7 +7,7 @@ module Mindee class HealthcareCardV1Document < Parsing::Common::Prediction def initialize: (Hash[Symbol | String, untyped], Integer?) -> void def company_name: -> (Parsing::Standard::StringField) - def copays: -> (Array[Product::US::HealthcareCard::HealthcareCardV1Copay]) + def copays: -> (Product::US::HealthcareCard::HealthcareCardV1Copays) def dependents: -> (Array[Parsing::Standard::StringField]) def enrollment_date: -> (Parsing::Standard::DateField) def group_number: -> (Parsing::Standard::StringField) 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 index 1dcb7cbc..e3d27171 100644 --- a/sig/mindee/product/us/us_mail/us_mail_v3_document.rbs +++ b/sig/mindee/product/us/us_mail/us_mail_v3_document.rbs @@ -7,7 +7,7 @@ module Mindee class UsMailV3Document < Parsing::Common::Prediction def initialize: (Hash[Symbol | String, untyped], Integer?) -> void def is_return_to_sender: -> (Parsing::Standard::BooleanField) - def recipient_addresses: -> (Array[Product::US::UsMail::UsMailV3RecipientAddress]) + 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) 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/spec/document/fr/bank_statement_v2_spec.rb b/spec/document/fr/bank_statement_v2_spec.rb deleted file mode 100644 index 779f949c..00000000 --- a/spec/document/fr/bank_statement_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_FR_BANK_STATEMENT_V2 = File.join(DATA_DIR, 'products', 'bank_statement_fr', 'response_v2').freeze - -describe Mindee::Product::FR::BankStatement::BankStatementV2 do - context 'A Bank Statement V2' do - it 'should load an empty document prediction' do - response = load_json(DIR_FR_BANK_STATEMENT_V2, 'empty.json') - inference = Mindee::Parsing::Common::Document.new( - Mindee::Product::FR::BankStatement::BankStatementV2, - 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_V2, 'summary_full.rst') - response = load_json(DIR_FR_BANK_STATEMENT_V2, 'complete.json') - document = Mindee::Parsing::Common::Document.new( - Mindee::Product::FR::BankStatement::BankStatementV2, - 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 9ad0df3d..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' diff --git a/spec/extras/full_text_ocr_spec.rb b/spec/extras/full_text_ocr_spec.rb index 685d93b3..27441683 100644 --- a/spec/extras/full_text_ocr_spec.rb +++ b/spec/extras/full_text_ocr_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'json' -require 'rspec' require_relative 'extras_utils' shared_context 'load pages' do @@ -128,8 +127,10 @@ 'confidence' => 0, }, 'transactions' => [ - 'value' => nil, - 'confidence' => 0, + { + 'value' => nil, + 'confidence' => 0, + }, ], }, }, diff --git a/spec/image/image_utils_spec.rb b/spec/image/image_utils_spec.rb index 7526e7c3..0fb7f27a 100644 --- a/spec/image/image_utils_spec.rb +++ b/spec/image/image_utils_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true # spec/image_utils_spec.rb -require 'rspec' require 'mini_magick' require 'stringio' require 'mindee' 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/url_input_source_integration.rb b/spec/input/sources/url_input_source_integration.rb index 0719d875..d0f79f4a 100644 --- a/spec/input/sources/url_input_source_integration.rb +++ b/spec/input/sources/url_input_source_integration.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'rspec' require 'mindee' describe Mindee::Input::Source::UrlInputSource do diff --git a/spec/input/sources/url_input_source_spec.rb b/spec/input/sources/url_input_source_spec.rb index d2a86f63..0ebd2bec 100644 --- a/spec/input/sources/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' -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' } 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 index 8bcda736..4056b339 100644 --- a/spec/pdf/extracted_pdf_spec.rb +++ b/spec/pdf/extracted_pdf_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'mindee' -require 'rspec' describe Mindee::PDF::PDFExtractor::ExtractedPDF do let(:product_data_dir) { File.join(DATA_DIR, 'products') } diff --git a/spec/pdf/pdf_extractor_spec.rb b/spec/pdf/pdf_extractor_spec.rb index 6de412f0..19c208e0 100644 --- a/spec/pdf/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') } 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_v1_spec.rb b/spec/product/fr/bank_statement_v1_spec.rb similarity index 100% rename from spec/document/fr/bank_statement_v1_spec.rb rename to spec/product/fr/bank_statement_v1_spec.rb diff --git a/spec/product/fr/bank_statement_v2_spec.rb b/spec/product/fr/bank_statement_v2_spec.rb new file mode 100644 index 00000000..e69de29b 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/universal_spec.rb b/spec/product/universal_spec.rb similarity index 99% rename from spec/document/universal_spec.rb rename to spec/product/universal_spec.rb index 8b4532d9..5430ed1a 100644 --- a/spec/document/universal_spec.rb +++ b/spec/product/universal_spec.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true require 'json' -require 'mindee/product' -require 'mindee/parsing' +require 'mindee' require_relative '../data' @@ -14,7 +13,7 @@ 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', @@ -231,7 +230,7 @@ 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', 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 From a7d2d254450978a18c347a3aff1c543b7f238686 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Fri, 21 Feb 2025 15:35:30 +0100 Subject: [PATCH 16/17] :recycle: update `UrlInputSource` to `URLInputSource` (#160) --- README.md | 44 +-- bin/mindee.rb | 4 +- docs/advanced_file_operations.md | 111 ++++++ docs/getting_started.md | 162 +++------ docs/global_products.md | 6 + .../barcode_reader_v1.md | 25 +- .../bill_of_lading_v1.md | 139 +++----- .../{ => global_products}/business_card_v1.md | 33 +- docs/{ => global_products}/cropper_v1.md | 35 +- .../delivery_notes_v1.md | 33 +- .../driver_license_v1.md | 33 +- .../expense_receipts_v5.md | 70 ++-- .../financial_document_v1.md | 89 ++--- .../international_id_v2.md | 40 ++- .../invoice_splitter_v1.md | 29 +- docs/{ => global_products}/invoices_v4.md | 89 ++--- .../multi_receipts_detector_v1.md | 35 +- .../nutrition_facts_v1.md | 293 +++++----------- docs/{ => global_products}/passport_v1.md | 25 +- docs/{ => global_products}/resume_v1.md | 184 ++++------ docs/{ => global_products}/universal.md | 29 +- docs/loading_a_document.md | 316 ++++++++++++++++++ docs/localized_products.md | 6 + .../bank_account_details_v2.md | 34 +- .../{ => localized_products}/bank_check_v1.md | 45 ++- .../bank_statement_fr_v1.md | 47 ++- .../carte_grise_v1.md | 23 +- .../energy_bill_fra_v1.md | 171 ++++------ .../french_healthcard_v1.md | 35 +- docs/{ => localized_products}/idcard_fr_v2.md | 40 ++- .../ind_passport_v1.md | 36 +- .../license_plates_v1.md | 23 +- .../payslip_fra_v3.md | 242 ++++---------- .../us_healthcare_cards_v1.md | 48 ++- docs/{ => localized_products}/us_mail_v3.md | 82 +++-- docs/{ => localized_products}/us_w9_v1.md | 99 +++--- docs/payslip_fra_v2.md | 294 ---------------- lib/mindee/client.rb | 42 +-- lib/mindee/http/endpoint.rb | 12 +- lib/mindee/http/workflow_endpoint.rb | 6 +- .../input/sources/base64_input_source.rb | 6 +- .../input/sources/bytes_input_source.rb | 6 +- lib/mindee/input/sources/file_input_source.rb | 6 +- .../input/sources/local_input_source.rb | 8 +- lib/mindee/input/sources/path_input_source.rb | 6 +- lib/mindee/input/sources/url_input_source.rb | 2 +- sig/mindee/client.rbs | 69 +--- .../input/sources/base64_input_source.rbs | 2 +- .../input/sources/bytes_input_source.rbs | 2 +- .../input/sources/file_input_source.rbs | 2 +- .../input/sources/local_input_source.rbs | 2 +- .../input/sources/path_input_source.rbs | 2 +- sig/mindee/input/sources/url_input_source.rbs | 2 +- spec/input/sources/sources_spec.rb | 6 +- .../sources/url_input_source_integration.rb | 4 +- spec/input/sources/url_input_source_spec.rb | 2 +- 56 files changed, 1629 insertions(+), 1607 deletions(-) create mode 100644 docs/advanced_file_operations.md create mode 100644 docs/global_products.md rename docs/{ => global_products}/barcode_reader_v1.md (75%) rename docs/{ => global_products}/bill_of_lading_v1.md (76%) rename docs/{ => global_products}/business_card_v1.md (77%) rename docs/{ => global_products}/cropper_v1.md (73%) rename docs/{ => global_products}/delivery_notes_v1.md (76%) rename docs/{ => global_products}/driver_license_v1.md (80%) rename docs/{ => global_products}/expense_receipts_v5.md (83%) rename docs/{ => global_products}/financial_document_v1.md (86%) rename docs/{ => global_products}/international_id_v2.md (80%) rename docs/{ => global_products}/invoice_splitter_v1.md (60%) rename docs/{ => global_products}/invoices_v4.md (85%) rename docs/{ => global_products}/multi_receipts_detector_v1.md (73%) rename docs/{ => global_products}/nutrition_facts_v1.md (66%) rename docs/{ => global_products}/passport_v1.md (84%) rename docs/{ => global_products}/resume_v1.md (75%) rename docs/{ => global_products}/universal.md (69%) create mode 100644 docs/loading_a_document.md create mode 100644 docs/localized_products.md rename docs/{ => localized_products}/bank_account_details_v2.md (82%) rename docs/{ => localized_products}/bank_check_v1.md (78%) rename docs/{ => localized_products}/bank_statement_fr_v1.md (85%) rename docs/{ => localized_products}/carte_grise_v1.md (91%) rename docs/{ => localized_products}/energy_bill_fra_v1.md (76%) rename docs/{ => localized_products}/french_healthcard_v1.md (71%) rename docs/{ => localized_products}/idcard_fr_v2.md (84%) rename docs/{ => localized_products}/ind_passport_v1.md (84%) rename docs/{ => localized_products}/license_plates_v1.md (74%) rename docs/{ => localized_products}/payslip_fra_v3.md (68%) rename docs/{ => localized_products}/us_healthcare_cards_v1.md (80%) rename docs/{ => localized_products}/us_mail_v3.md (76%) rename docs/{ => localized_products}/us_w9_v1.md (70%) delete mode 100644 docs/payslip_fra_v2.md diff --git a/README.md b/README.md index 456231c5..35d170f4 100644 --- a/README.md +++ b/README.md @@ -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 @@ -149,7 +152,9 @@ result.document.inference.prediction.fields.each do |field_name, field_data| puts field_data.to_s end ``` -## Enqueue and Parse a Webhook Response + + +## Enqueueing and Parse a Webhook Response This is an optional way of handling asynchronous APIs. @@ -163,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 @@ -220,24 +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) -* [Universal API Ruby](https://developers.mindee.com/docs/ruby-universal-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) -* [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) -* [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 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/bin/mindee.rb b/bin/mindee.rb index 8cda0c98..5476bcdc 100755 --- a/bin/mindee.rb +++ b/bin/mindee.rb @@ -151,7 +151,7 @@ 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 != 'universal' opts.banner = "#{doc_value[:description]}. \nUsage: \nmindee.rb universal [options] endpoint_name file\nor\nmindee.rb universal [options] endpoint_name file" @@ -200,7 +200,7 @@ def custom_subcommand(cli_parser, options) 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 == 'universal' diff --git a/docs/advanced_file_operations.md b/docs/advanced_file_operations.md new file mode 100644 index 00000000..517e1a10 --- /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 fix_pdf flag enabled. +input_source = mindee_client.source_from_file(file, "document.pdf", fix_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/getting_started.md b/docs/getting_started.md index c5dd5603..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 @@ -12,7 +12,7 @@ This guide will help you get the most out of the Mindee Ruby client library to e 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 Universal 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,93 +119,15 @@ 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. - -**Note**: The original filename is required when calling the method. - -```ruby -File.open(INVOICE_FILE, 'rb') do |fo| - input_source = mindee_client.source_from_file(fo, "invoice.jpg") -end - -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 -) -``` - -### Bytes -Requires raw bytes. - -**Note**: The original filename is required when calling the method. - -```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") +There are a few different ways of loading a document file, depending on your use case, you can use a: -result = mindee_client.parse( - input_source, - Mindee::Product::Invoice::InvoiceV4 -) -``` +* [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. -### URL -Requires an url as a String. - -**Note**: the url must start with `https://`. - -```ruby -input_source = mindee_client.source_from_url("https://www.example.com/invoice.pdf") - -result = mindee_client.parse( - input_source, - Mindee::Product::Invoice::InvoiceV4 -) -``` +More details about file loading on the [dedicated page](https://developers.mindee.com/docs/ruby-document-loading). ## Sending a File To send a file to the API, we need to specify how to process the document. @@ -214,13 +137,15 @@ More specifically, we need to set a `Mindee::Product` class as the first paramet 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. +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. ### Off-the-Shelf Documents Simply setting the correct class is enough: -```ruby +```rb result = mindee_client.parse( input_source, @@ -228,10 +153,27 @@ result = mindee_client.parse( ) ``` +#### 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`. + +```rb + +result = mindee_client.parse( + input_source, + Mindee::Product::Invoice::InvoiceV4, + enqueue: false +) +``` + +> 🚧 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.parse( @@ -241,10 +183,12 @@ result = mindee_client.parse( ) ``` -This is because the `Universal` 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 (using the Universal product). 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 @@ -263,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 @@ -281,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 @@ -292,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 75% rename from docs/barcode_reader_v1.md rename to docs/global_products/barcode_reader_v1.md index c512a5f0..756a79fa 100644 --- a/docs/barcode_reader_v1.md +++ b/docs/global_products/barcode_reader_v1.md @@ -1,12 +1,25 @@ --- -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 | `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 @@ -89,7 +102,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 ``` @@ -98,7 +111,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 76% rename from docs/bill_of_lading_v1.md rename to docs/global_products/bill_of_lading_v1.md index 49b4ef8a..cf982b18 100644 --- a/docs/bill_of_lading_v1.md +++ b/docs/global_products/bill_of_lading_v1.md @@ -1,12 +1,33 @@ --- -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 | `bill_of_lading` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -99,7 +120,7 @@ A typical `Field` object will have the following attributes: 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. @@ -109,116 +130,60 @@ 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. - -A `BillOfLadingV1Carrier` 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. -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. - -A `BillOfLadingV1Carrier` implements the following attributes: +### Shipper Field +The party responsible for shipping the goods. -* `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. +A `BillOfLadingV1Shipper` 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. Fields which are specific to this product; they are not used in any other product. ### Consignee Field The party to whom the goods are being shipped. A `BillOfLadingV1Consignee` implements the following attributes: - + * `address` (String): The address of the consignee. * `email` (String): The email of the shipper. * `name` (String): The name of the consignee. * `phone` (String): The phone number of the consignee. Fields which are specific to this product; they are not used in any other product. -### Consignee Field -The party to whom the goods are being shipped. - -A `BillOfLadingV1Consignee` implements the following attributes: +### Notify Party Field +The party to be notified of the arrival of the goods. -* `address` (String): The address of the consignee. +A `BillOfLadingV1NotifyParty` implements the following attributes: + +* `address` (String): The address of the notify party. * `email` (String): The email of the shipper. -* `name` (String): The name of the consignee. -* `phone` (String): The phone number of the consignee. +* `name` (String): The name of the notify party. +* `phone` (String): The phone number of the notify party. 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: +### Carrier Field +The shipping company responsible for transporting the goods. -* `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. +A `BillOfLadingV1Carrier` 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. 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. - -A `BillOfLadingV1NotifyParty` implements the following attributes: - -* `address` (String): The address of the notify party. -* `email` (String): The email of the shipper. -* `name` (String): The name of the notify party. -* `phone` (String): The phone number of the notify party. -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. - -A `BillOfLadingV1NotifyParty` implements the following attributes: - -* `address` (String): The address of the notify party. -* `email` (String): The email of the shipper. -* `name` (String): The name of the notify party. -* `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. - -A `BillOfLadingV1Shipper` 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. -Fields which are specific to this product; they are not used in any other product. - -### Shipper Field -The party responsible for shipping the goods. - -A `BillOfLadingV1Shipper` 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. # Attributes The following fields are extracted for Bill of Lading V1: @@ -241,7 +206,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 77% rename from docs/business_card_v1.md rename to docs/global_products/business_card_v1.md index b8da6bdb..5f92ee05 100644 --- a/docs/business_card_v1.md +++ b/docs/global_products/business_card_v1.md @@ -1,12 +1,33 @@ --- -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 | `business_card` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -152,7 +173,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 73% rename from docs/cropper_v1.md rename to docs/global_products/cropper_v1.md index 55f49b36..887189ac 100644 --- a/docs/cropper_v1.md +++ b/docs/global_products/cropper_v1.md @@ -1,12 +1,25 @@ --- -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 | `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 @@ -74,9 +87,11 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met ### 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 @@ -89,14 +104,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 76% rename from docs/delivery_notes_v1.md rename to docs/global_products/delivery_notes_v1.md index 874c659b..5e17db72 100644 --- a/docs/delivery_notes_v1.md +++ b/docs/global_products/delivery_notes_v1.md @@ -1,12 +1,33 @@ --- -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 | `delivery_notes` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -79,7 +100,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 80% rename from docs/driver_license_v1.md rename to docs/global_products/driver_license_v1.md index 72f1bcf6..240a758d 100644 --- a/docs/driver_license_v1.md +++ b/docs/global_products/driver_license_v1.md @@ -1,12 +1,33 @@ --- -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 | `driver_license` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -81,7 +102,7 @@ A typical `Field` object will have the following attributes: 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 83% rename from docs/expense_receipts_v5.md rename to docs/global_products/expense_receipts_v5.md index e1ee889e..a7904413 100644 --- a/docs/expense_receipts_v5.md +++ b/docs/global_products/expense_receipts_v5.md @@ -1,12 +1,33 @@ --- -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 | `expense_receipts` | +> | Recommended Version | `v5.3` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -135,26 +156,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 @@ -168,10 +193,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. @@ -180,18 +207,7 @@ Fields which are specific to this product; they are not used in any other produc List of line item details. A `ReceiptV5LineItem` implements the following attributes: - -* `description` (String): The item description. -* `quantity` (Float): The item quantity. -* `total_amount` (Float): The item total amount. -* `unit_price` (Float): The item unit price. -Fields which are specific to this product; they are not used in any other product. - -### Line Items Field -List of line item details. - -A `ReceiptV5LineItem` implements the following attributes: - + * `description` (String): The item description. * `quantity` (Float): The item quantity. * `total_amount` (Float): The item total amount. @@ -239,7 +255,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 ``` @@ -283,7 +299,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 ``` @@ -306,7 +322,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 86% rename from docs/financial_document_v1.md rename to docs/global_products/financial_document_v1.md index d38114b7..278a6cdb 100644 --- a/docs/financial_document_v1.md +++ b/docs/global_products/financial_document_v1.md @@ -1,12 +1,33 @@ --- -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 | `financial_document` | +> | Recommended Version | `v1.11` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -171,30 +192,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`. @@ -212,10 +238,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. @@ -224,22 +252,7 @@ Fields which are specific to this product; they are not used in any other produc List of line item details. A `FinancialDocumentV1LineItem` implements the following attributes: - -* `description` (String): The item description. -* `product_code` (String): The product code referring to the item. -* `quantity` (Float): The item quantity -* `tax_amount` (Float): The item tax amount. -* `tax_rate` (Float): The item tax rate in percentage. -* `total_amount` (Float): The item total amount. -* `unit_measure` (String): The item unit of measure. -* `unit_price` (Float): The item unit price. -Fields which are specific to this product; they are not used in any other product. - -### Line Items Field -List of line item details. - -A `FinancialDocumentV1LineItem` implements the following attributes: - + * `description` (String): The item description. * `product_code` (String): The product code referring to the item. * `quantity` (Float): The item quantity @@ -287,7 +300,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 ``` @@ -351,7 +364,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 ``` @@ -388,7 +401,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 ``` @@ -425,7 +438,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 ``` @@ -448,11 +461,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 ``` @@ -474,7 +487,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 80% rename from docs/international_id_v2.md rename to docs/global_products/international_id_v2.md index 9d2bf4fb..94f33978 100644 --- a/docs/international_id_v2.md +++ b/docs/global_products/international_id_v2.md @@ -1,12 +1,33 @@ --- -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 | `international_id` | +> | Recommended Version | `v2.1` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -87,12 +108,13 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met ### 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. @@ -163,7 +185,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 ``` @@ -228,7 +250,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 60% rename from docs/invoice_splitter_v1.md rename to docs/global_products/invoice_splitter_v1.md index ec0fdeb9..1cda8bf5 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 | `invoice_splitter` | +> | Recommended Version | `v1.2` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -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 85% rename from docs/invoices_v4.md rename to docs/global_products/invoices_v4.md index 15a0d645..4d97434c 100644 --- a/docs/invoices_v4.md +++ b/docs/global_products/invoices_v4.md @@ -1,12 +1,33 @@ --- -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 | `invoices` | +> | Recommended Version | `v4.9` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ✔️ Yes | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -159,30 +180,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`. @@ -200,10 +226,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. @@ -212,22 +240,7 @@ Fields which are specific to this product; they are not used in any other produc List of line item details. A `InvoiceV4LineItem` implements the following attributes: - -* `description` (String): The item description. -* `product_code` (String): The product code referring to the item. -* `quantity` (Float): The item quantity -* `tax_amount` (Float): The item tax amount. -* `tax_rate` (Float): The item tax rate in percentage. -* `total_amount` (Float): The item total amount. -* `unit_measure` (String): The item unit of measure. -* `unit_price` (Float): The item unit price. -Fields which are specific to this product; they are not used in any other product. - -### Line Items Field -List of line item details. - -A `InvoiceV4LineItem` implements the following attributes: - + * `description` (String): The item description. * `product_code` (String): The product code referring to the item. * `quantity` (Float): The item quantity @@ -258,7 +271,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 ``` @@ -313,7 +326,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 ``` @@ -343,7 +356,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 ``` @@ -366,7 +379,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 ``` @@ -389,11 +402,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 ``` @@ -415,7 +428,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 73% rename from docs/multi_receipts_detector_v1.md rename to docs/global_products/multi_receipts_detector_v1.md index be9cc19d..29e6c3c6 100644 --- a/docs/multi_receipts_detector_v1.md +++ b/docs/global_products/multi_receipts_detector_v1.md @@ -1,12 +1,25 @@ --- -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 | `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 @@ -87,9 +100,11 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met ### 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 @@ -99,11 +114,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 66% rename from docs/nutrition_facts_v1.md rename to docs/global_products/nutrition_facts_v1.md index 877366f0..c586d443 100644 --- a/docs/nutrition_facts_v1.md +++ b/docs/global_products/nutrition_facts_v1.md @@ -1,12 +1,33 @@ --- -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 | `nutrition_facts` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -135,268 +156,136 @@ 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. - -A `NutritionFactsLabelV1AddedSugar` 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. -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. - -A `NutritionFactsLabelV1AddedSugar` implements the following attributes: +### Serving Size Field +The size of a single 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. +A `NutritionFactsLabelV1ServingSize` implements the following attributes: + +* `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 The amount of calories in the product. A `NutritionFactsLabelV1Calorie` implements the following attributes: - + * `daily_value` (Float): DVs are the recommended amounts of calories to consume or not to exceed each day. * `per_100g` (Float): The amount of calories per 100g of the product. * `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. -### Calories Field -The amount of calories in the product. - -A `NutritionFactsLabelV1Calorie` implements the following attributes: +### Total Fat Field +The total amount of fat in the product. -* `daily_value` (Float): DVs are the recommended amounts of calories to consume or not to exceed each day. -* `per_100g` (Float): The amount of calories per 100g of the product. -* `per_serving` (Float): The amount of calories per serving of the product. +A `NutritionFactsLabelV1TotalFat` 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. Fields which are specific to this product; they are not used in any other product. -### Cholesterol Field -The amount of cholesterol in the product. +### Saturated Fat Field +The amount of saturated fat in the product. -A `NutritionFactsLabelV1Cholesterol` implements the following attributes: +A `NutritionFactsLabelV1SaturatedFat` implements the following attributes: + +* `daily_value` (Float): DVs are the recommended amounts of saturated fat to consume or not to exceed each day. +* `per_100g` (Float): The amount of saturated fat per 100g of the product. +* `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. -* `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. +### Trans Fat Field +The amount of trans fat in the product. + +A `NutritionFactsLabelV1TransFat` 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. 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: +### Total Carbohydrate Field +The total amount of carbohydrates in 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. +A `NutritionFactsLabelV1TotalCarbohydrate` implements the following attributes: + +* `daily_value` (Float): DVs are the recommended amounts of total carbohydrates to consume or not to exceed each day. +* `per_100g` (Float): The amount of total carbohydrates per 100g of the product. +* `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. ### 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. - -### nutrients Field -The amount of nutrients in the product. - -A `NutritionFactsLabelV1Nutrient` implements the following attributes: +### Total Sugars Field +The total amount of sugars in the product. -* `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. +A `NutritionFactsLabelV1TotalSugar` implements the following attributes: + +* `daily_value` (Float): DVs are the recommended amounts of total sugars to consume or not to exceed each day. +* `per_100g` (Float): The amount of total sugars per 100g of the product. +* `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. -### Protein Field -The amount of protein in the product. - -A `NutritionFactsLabelV1Protein` implements the following attributes: +### Added Sugars Field +The amount of added sugars in the product. -* `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. +A `NutritionFactsLabelV1AddedSugar` 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. 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. -### Saturated Fat Field -The amount of saturated fat in the product. - -A `NutritionFactsLabelV1SaturatedFat` implements the following attributes: - -* `daily_value` (Float): DVs are the recommended amounts of saturated fat to consume or not to exceed each day. -* `per_100g` (Float): The amount of saturated fat per 100g of the product. -* `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. - -### Saturated Fat Field -The amount of saturated fat in the product. - -A `NutritionFactsLabelV1SaturatedFat` implements the following attributes: - -* `daily_value` (Float): DVs are the recommended amounts of saturated fat to consume or not to exceed each day. -* `per_100g` (Float): The amount of saturated fat per 100g of the product. -* `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. - -A `NutritionFactsLabelV1ServingSize` implements the following attributes: - -* `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. - -### Serving Size Field -The size of a single serving of the product. - -A `NutritionFactsLabelV1ServingSize` implements the following attributes: - -* `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. - -### 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. - ### 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. -### Total Carbohydrate Field -The total amount of carbohydrates in the product. - -A `NutritionFactsLabelV1TotalCarbohydrate` implements the following attributes: - -* `daily_value` (Float): DVs are the recommended amounts of total carbohydrates to consume or not to exceed each day. -* `per_100g` (Float): The amount of total carbohydrates per 100g of the product. -* `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 Carbohydrate Field -The total amount of carbohydrates in the product. - -A `NutritionFactsLabelV1TotalCarbohydrate` implements the following attributes: - -* `daily_value` (Float): DVs are the recommended amounts of total carbohydrates to consume or not to exceed each day. -* `per_100g` (Float): The amount of total carbohydrates per 100g of the product. -* `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. - -A `NutritionFactsLabelV1TotalFat` 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. -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. - -A `NutritionFactsLabelV1TotalFat` 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. -Fields which are specific to this product; they are not used in any other product. - -### Total Sugars Field -The total amount of sugars in the product. - -A `NutritionFactsLabelV1TotalSugar` implements the following attributes: - -* `daily_value` (Float): DVs are the recommended amounts of total sugars to consume or not to exceed each day. -* `per_100g` (Float): The amount of total sugars per 100g of the product. -* `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. - -### Total Sugars Field -The total amount of sugars in the product. - -A `NutritionFactsLabelV1TotalSugar` implements the following attributes: - -* `daily_value` (Float): DVs are the recommended amounts of total sugars to consume or not to exceed each day. -* `per_100g` (Float): The amount of total sugars per 100g of the product. -* `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. - -A `NutritionFactsLabelV1TransFat` 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. -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. - -A `NutritionFactsLabelV1TransFat` implements the following attributes: +### nutrients Field +The amount of nutrients in the product. -* `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. +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: @@ -433,7 +322,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 84% rename from docs/passport_v1.md rename to docs/global_products/passport_v1.md index c03964db..7c493900 100644 --- a/docs/passport_v1.md +++ b/docs/global_products/passport_v1.md @@ -1,12 +1,25 @@ --- -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 | `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 @@ -96,7 +109,7 @@ A typical `Field` object will have the following attributes: 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. @@ -145,7 +158,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 75% rename from docs/resume_v1.md rename to docs/global_products/resume_v1.md index ba38141f..453b4577 100644 --- a/docs/resume_v1.md +++ b/docs/global_products/resume_v1.md @@ -1,12 +1,33 @@ --- -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 | `resume` | +> | Recommended Version | `v1.2` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🌐 Global | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -125,7 +146,8 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met ### 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`. @@ -135,78 +157,20 @@ 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. - -### 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. - -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. - -### 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. - -### Languages Field -The list of languages that the candidate is proficient in. - -A `ResumeV1Language` implements the following attributes: - -* `language` (String): The language's ISO 639 code. -* `level` (String): The candidate's level for the language. - -#### Possible values include: - - Native - - Fluent - - Proficient - - Intermediate - - Beginner +### Social Networks Field +The list of social network profiles of the candidate. +A `ResumeV1SocialNetworksUrl` implements the following attributes: + +* `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 The list of languages that the candidate is proficient in. A `ResumeV1Language` implements the following attributes: - + * `language` (String): The language's ISO 639 code. * `level` (String): The candidate's level for the language. @@ -216,37 +180,28 @@ A `ResumeV1Language` implements the following attributes: - Proficient - Intermediate - Beginner - + Fields which are specific to this product; they are not used in any other product. -### Professional Experiences Field -The list of the candidate's professional experiences. - -A `ResumeV1ProfessionalExperience` implements the following attributes: - -* `contract_type` (String): The type of contract for the professional experience. - -#### Possible values include: - - Full-Time - - Part-Time - - Internship - - Freelance +### Education Field +The list of the candidate's educational background. -* `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. -* `end_month` (String): The month when the professional experience ended. -* `end_year` (String): The year when the professional experience ended. -* `role` (String): The position or job title held by the candidate. -* `start_month` (String): The month when the professional experience began. -* `start_year` (String): The year when the professional experience began. +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 The list of the candidate's professional experiences. A `ResumeV1ProfessionalExperience` implements the following attributes: - + * `contract_type` (String): The type of contract for the professional experience. #### Possible values include: @@ -254,7 +209,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. @@ -265,22 +220,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. - -A `ResumeV1SocialNetworksUrl` implements the following attributes: - -* `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. - -### Social Networks Field -The list of social network profiles of the candidate. - -A `ResumeV1SocialNetworksUrl` implements the following attributes: +### Certificates Field +The list of certificates obtained by the candidate. -* `name` (String): The name of the social network. -* `url` (String): The URL of the social network. +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. # Attributes The following fields are extracted for Resume V1: @@ -296,7 +244,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 ``` @@ -324,7 +272,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 ``` @@ -340,7 +288,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 ``` @@ -349,7 +297,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 ``` @@ -365,7 +313,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 ``` @@ -395,7 +343,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 ``` @@ -404,7 +352,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 ``` @@ -413,7 +361,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 ``` @@ -422,7 +370,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/universal.md b/docs/global_products/universal.md similarity index 69% rename from docs/universal.md rename to docs/global_products/universal.md index adde21a3..a8d0269d 100644 --- a/docs/universal.md +++ b/docs/global_products/universal.md @@ -2,14 +2,33 @@ title: Universal API Ruby category: 622b805aaec68102ea7fcbc2 slug: ruby-universal-ocr -parentDoc: 6294d97ee723f1008d2ab28e +parentDoc: 67b49df15b843f3fa9cd622b --- -The Ruby OCR SDK supports a universal wrapper class for all products. -Universal supports all product in a catch-all generic format. +The Ruby Client Library implements a universal wrapper class for all products. + +> 📝 Product Specs +> +> | Specification | Details | +> | ------------------------------ |-----------------------------------------------------------------| +> | Endpoint | `` | +> | Recommended Version | `v` Defaults to 1 for custom products. | +> | Supports Polling/Webhooks | ❓️ Variable | +> | Support Synchronous HTTP Calls | ❓ Variable | +> | Geography | ❓ Variable | + +> 🔐 Polling Limitations (Polling only) +> +> | Setting | Parameter name | 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 @@ -84,7 +103,7 @@ Universal builds always have access to at least two attributes: **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..7c66035e --- /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 ([fix_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 82% rename from docs/bank_account_details_v2.md rename to docs/localized_products/bank_account_details_v2.md index 1c88b518..7e5c0637 100644 --- a/docs/bank_account_details_v2.md +++ b/docs/localized_products/bank_account_details_v2.md @@ -1,12 +1,25 @@ --- -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 | `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 @@ -99,18 +112,7 @@ Fields which are specific to this product; they are not used in any other produc Full extraction of BBAN, including: branch code, bank code, account and key. A `BankAccountDetailsV2Bban` implements the following attributes: - -* `bban_bank_code` (String): The BBAN bank code outputted as a string. -* `bban_branch_code` (String): The BBAN branch code outputted as a string. -* `bban_key` (String): The BBAN key outputted as a string. -* `bban_number` (String): The BBAN Account number outputted as a string. -Fields which are specific to this product; they are not used in any other product. - -### Basic Bank Account Number Field -Full extraction of BBAN, including: branch code, bank code, account and key. - -A `BankAccountDetailsV2Bban` implements the following attributes: - + * `bban_bank_code` (String): The BBAN bank code outputted as a string. * `bban_branch_code` (String): The BBAN branch code outputted as a string. * `bban_key` (String): The BBAN key outputted as a string. diff --git a/docs/bank_check_v1.md b/docs/localized_products/bank_check_v1.md similarity index 78% rename from docs/bank_check_v1.md rename to docs/localized_products/bank_check_v1.md index 6756e6ca..f61f2275 100644 --- a/docs/bank_check_v1.md +++ b/docs/localized_products/bank_check_v1.md @@ -1,12 +1,25 @@ --- -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 | `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 @@ -94,15 +107,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 @@ -139,9 +154,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 @@ -155,7 +170,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 ``` @@ -171,14 +186,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_v1.md b/docs/localized_products/bank_statement_fr_v1.md similarity index 85% rename from docs/bank_statement_fr_v1.md rename to docs/localized_products/bank_statement_fr_v1.md index 53f40a20..062ad566 100644 --- a/docs/bank_statement_fr_v1.md +++ b/docs/localized_products/bank_statement_fr_v1.md @@ -1,12 +1,33 @@ --- -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 | `bank_statement_fr` | +> | Recommended Version | `v1.1` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇫🇷 France | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -118,7 +139,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. @@ -132,17 +153,7 @@ Fields which are specific to this product; they are not used in any other produc 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. -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. @@ -238,7 +249,7 @@ puts result.document.inference.prediction.total_debits.value **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 +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 91% rename from docs/carte_grise_v1.md rename to docs/localized_products/carte_grise_v1.md index 23fec839..167baabd 100644 --- a/docs/carte_grise_v1.md +++ b/docs/localized_products/carte_grise_v1.md @@ -1,12 +1,25 @@ --- -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 | `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 @@ -156,7 +169,7 @@ A typical `Field` object will have the following attributes: 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 76% rename from docs/energy_bill_fra_v1.md rename to docs/localized_products/energy_bill_fra_v1.md index d74ed066..129551ee 100644 --- a/docs/energy_bill_fra_v1.md +++ b/docs/localized_products/energy_bill_fra_v1.md @@ -1,12 +1,33 @@ --- -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 | `energy_bill_fra` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇫🇷 France | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -114,7 +135,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. @@ -124,60 +145,42 @@ 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 Consumer Field -The entity that consumes the energy. - -A `EnergyBillV1EnergyConsumer` implements the following attributes: - -* `address` (String): The address of the energy consumer. -* `name` (String): The name of the energy consumer. -Fields which are specific to this product; they are not used in any other product. - -### Energy Consumer Field -The entity that consumes the energy. - -A `EnergyBillV1EnergyConsumer` implements the following attributes: - -* `address` (String): The address of the energy consumer. -* `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. 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 Supplier Field -The company that supplies the energy. - -A `EnergyBillV1EnergySupplier` implements the following attributes: +### Energy Consumer Field +The entity that consumes the energy. -* `address` (String): The address of the energy supplier. -* `name` (String): The name of the energy supplier. +A `EnergyBillV1EnergyConsumer` implements the following attributes: + +* `address` (String): The address of the energy consumer. +* `name` (String): The name of the energy consumer. Fields which are specific to this product; they are not used in any other product. -### Energy Usage Field -Details of energy consumption. - -A `EnergyBillV1EnergyUsage` implements the following attributes: +### Subscription Field +The subscription details fee for the energy service. -* `description` (String): Description or details of the energy usage. -* `end_date` (String): The end date of the energy usage. -* `start_date` (String): The start date of the energy usage. +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 energy consumed. -* `unit_price` (Float): The price per unit of energy consumed. +* `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 Details of energy consumption. A `EnergyBillV1EnergyUsage` implements the following attributes: - + * `description` (String): Description or details of the energy usage. * `end_date` (String): The end date of the energy usage. * `start_date` (String): The start date of the energy usage. @@ -186,28 +189,24 @@ 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. -### Meter Details Field -Information about the energy meter. - -A `EnergyBillV1MeterDetail` implements the following attributes: - -* `meter_number` (String): The unique identifier of the energy meter. -* `meter_type` (String): The type of energy meter. - -#### Possible values include: - - electricity - - gas - - water - - None +### Taxes and Contributions Field +Details of Taxes and Contributions. -* `unit` (String): The unit of measurement for energy consumption, which can be kW, m³, or L. +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. A `EnergyBillV1MeterDetail` implements the following attributes: - + * `meter_number` (String): The unique identifier of the energy meter. * `meter_type` (String): The type of energy meter. @@ -216,60 +215,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. - -### 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. -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: @@ -313,7 +260,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 ``` @@ -343,7 +290,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 ``` @@ -352,7 +299,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 71% rename from docs/french_healthcard_v1.md rename to docs/localized_products/french_healthcard_v1.md index 3a55f65a..05822db5 100644 --- a/docs/french_healthcard_v1.md +++ b/docs/localized_products/french_healthcard_v1.md @@ -1,12 +1,33 @@ --- -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 | `french_healthcard` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇫🇷 France | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -72,7 +93,7 @@ A typical `Field` object will have the following attributes: 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. @@ -86,7 +107,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 84% rename from docs/idcard_fr_v2.md rename to docs/localized_products/idcard_fr_v2.md index c4bf9bd9..3c19ed16 100644 --- a/docs/idcard_fr_v2.md +++ b/docs/localized_products/idcard_fr_v2.md @@ -1,12 +1,25 @@ --- -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 | `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 @@ -109,12 +122,13 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met ### 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. @@ -178,9 +192,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 @@ -191,9 +205,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 @@ -214,7 +228,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 84% rename from docs/ind_passport_v1.md rename to docs/localized_products/ind_passport_v1.md index 4f53c759..ff1231f2 100644 --- a/docs/ind_passport_v1.md +++ b/docs/localized_products/ind_passport_v1.md @@ -1,12 +1,33 @@ --- -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 | `ind_passport` | +> | Recommended Version | `v1.2` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇮🇳 India | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -92,12 +113,13 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met ### 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 74% rename from docs/license_plates_v1.md rename to docs/localized_products/license_plates_v1.md index b8e268c1..47a0d409 100644 --- a/docs/license_plates_v1.md +++ b/docs/localized_products/license_plates_v1.md @@ -1,12 +1,25 @@ --- -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 | `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 @@ -85,7 +98,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 68% rename from docs/payslip_fra_v3.md rename to docs/localized_products/payslip_fra_v3.md index f27dd5d8..92a967b3 100644 --- a/docs/payslip_fra_v3.md +++ b/docs/localized_products/payslip_fra_v3.md @@ -1,12 +1,33 @@ --- -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 | `payslip_fra` | +> | Recommended Version | `v3.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇫🇷 France | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -135,45 +156,23 @@ 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. - -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. - -### 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. - -### Employee Field -Information about the employee. - -A `PayslipV3Employee` implements the following attributes: +### Pay Period Field +Information about the pay period. -* `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. +A `PayslipV3PayPeriod` 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. ### Employee Field Information about the employee. A `PayslipV3Employee` 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. @@ -187,7 +186,7 @@ Fields which are specific to this product; they are not used in any other produc Information about the employer. A `PayslipV3Employer` 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. @@ -197,25 +196,21 @@ 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. -### Employer Field -Information about the employer. - -A `PayslipV3Employer` implements the following attributes: +### Bank Account Details Field +Information about the employee's bank account. -* `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. +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. A `PayslipV3Employment` implements the following attributes: - + * `category` (String): The category of the employment. * `coefficient` (String): The coefficient of the employment. * `collective_agreement` (String): The collective agreement of the employment. @@ -225,49 +220,40 @@ 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. -### Employment Field -Information about the employment. - -A `PayslipV3Employment` implements the following attributes: +### Salary Details Field +Detailed information about the earnings. -* `category` (String): The category of the employment. -* `coefficient` (String): 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. -* `seniority_date` (String): The seniority date of the employment. -* `start_date` (String): The start date of the employment. +A `PayslipV3SalaryDetail` implements the following attributes: + +* `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. -### 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. - -#### Possible values include: - - VACATION - - RTT - - COMPENSATORY +### Pay Detail Field +Detailed information about the pay. -* `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. +A `PayslipV3PayDetail` 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. ### 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. @@ -275,98 +261,16 @@ A `PayslipV3PaidTimeOff` implements the following attributes: - N - N-1 - N-2 - + * `pto_type` (String): The type of paid time off. #### 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. -Fields which are specific to this product; they are not used in any other product. - -### Pay Detail Field -Detailed information about the pay. - -A `PayslipV3PayDetail` 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 Detail Field -Detailed information about the pay. - -A `PayslipV3PayDetail` 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 `PayslipV3PayPeriod` 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. - -### Pay Period Field -Information about the pay period. - -A `PayslipV3PayPeriod` 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. - -### Salary Details Field -Detailed information about the earnings. - -A `PayslipV3SalaryDetail` implements the following attributes: - -* `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. - -### Salary Details Field -Detailed information about the earnings. - -A `PayslipV3SalaryDetail` implements the following attributes: - -* `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. # Attributes The following fields are extracted for Payslip V3: @@ -403,7 +307,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 ``` @@ -426,7 +330,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 80% rename from docs/us_healthcare_cards_v1.md rename to docs/localized_products/us_healthcare_cards_v1.md index db0d9474..23f45195 100644 --- a/docs/us_healthcare_cards_v1.md +++ b/docs/localized_products/us_healthcare_cards_v1.md @@ -1,12 +1,33 @@ --- -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 | `us_healthcare_cards` | +> | Recommended Version | `v1.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇺🇸 United States | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -94,7 +115,7 @@ A typical `Field` object will have the following attributes: 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. @@ -108,16 +129,7 @@ Fields which are specific to this product; they are not used in any other produc Is a fixed amount for a covered service. A `HealthcareCardV1Copay` implements the following attributes: - -* `service_fees` (Float): The price of service. -* `service_name` (String): The name of service of the copay. -Fields which are specific to this product; they are not used in any other product. - -### copays Field -Is a fixed amount for a covered service. - -A `HealthcareCardV1Copay` implements the following attributes: - + * `service_fees` (Float): The price of service. * `service_name` (String): The name of service of the copay. @@ -135,7 +147,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 ``` @@ -144,7 +156,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 76% rename from docs/us_mail_v3.md rename to docs/localized_products/us_mail_v3.md index b1a23fbb..97116a50 100644 --- a/docs/us_mail_v3.md +++ b/docs/localized_products/us_mail_v3.md @@ -1,12 +1,33 @@ --- -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 | `us_mail` | +> | Recommended Version | `v3.0` | +> | Supports Polling/Webhooks | ✔️ Yes | +> | Support Synchronous HTTP Calls | ❌ No | +> | Geography | 🇺🇸 United States | + +> 🔐 Polling Limitations +> +> | Setting | Parameter name | 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 @@ -88,26 +109,23 @@ 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. -### Recipient Addresses Field -The addresses of the recipients. - -A `UsMailV3RecipientAddress` implements the following attributes: +### Sender Address Field +The address of the sender. -* `city` (String): The city of the recipient's address. -* `complete` (String): The complete address of the recipient. -* `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. +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 recipient's address. -* `unit` (String): The unit number of the recipient's address. +* `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. 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` (bool): Indicates if the recipient's address is a change of address. @@ -116,36 +134,12 @@ A `UsMailV3RecipientAddress` implements the following attributes: * `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. -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: ## Return to Sender -**is_return_to_sender** ([BooleanField](#bool-field)): Whether the mailing is marked as return to sender. +**is_return_to_sender** ([BooleanField](#boolean-field)): Whether the mailing is marked as return to sender. ```rb puts result.document.inference.prediction.is_return_to_sender.value @@ -155,7 +149,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 ``` @@ -164,7 +158,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 70% rename from docs/us_w9_v1.md rename to docs/localized_products/us_w9_v1.md index fdbf501d..9249ed3e 100644 --- a/docs/us_w9_v1.md +++ b/docs/localized_products/us_w9_v1.md @@ -1,12 +1,25 @@ --- -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 | `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 @@ -84,9 +97,11 @@ Aside from the previous attributes, all basic fields have access to a `to_s` met ### 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 @@ -102,108 +117,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 9b64c6a0..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.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/lib/mindee/client.rb b/lib/mindee/client.rb index c24dc6b8..4680efe0 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -113,7 +113,7 @@ def initialize(api_key: '') # # Accepts options either as a Hash or as a ParseOptions struct. # - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @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: @@ -150,7 +150,7 @@ def parse(input_source, product_class, endpoint: nil, options: {}, enqueue: true # Call prediction API on a document and parse the results. # - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # @param product_class [Mindee::Inference] 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: @@ -185,7 +185,7 @@ def parse_sync(input_source, product_class, endpoint, options) # Enqueue a document for async parsing # - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @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: @@ -239,7 +239,7 @@ def parse_queued(job_id, product_class, endpoint: nil) # Enqueue a document for async parsing and automatically try to retrieve it # - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @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: @@ -303,7 +303,7 @@ def enqueue_and_parse(input_source, product_class, endpoint, options) # # Accepts options either as a Hash or as a WorkflowOptions struct. # - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @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. @@ -358,44 +358,44 @@ def load_prediction(product_class, local_response) # Load a document from an absolute path, as a string. # @param input_path [String] Path of file to open - # @param fix_pdf [bool] 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 [bool] 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 [bool] 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 [bool] 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. @@ -494,7 +494,7 @@ def normalize_parse_options(options) end # Processes a PDF if parameters were provided. - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @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) && diff --git a/lib/mindee/http/endpoint.rb b/lib/mindee/http/endpoint.rb index c43b240c..3700abfc 100644 --- a/lib/mindee/http/endpoint.rb +++ b/lib/mindee/http/endpoint.rb @@ -49,7 +49,7 @@ def initialize(owner, url_name, version, api_key: '') end # Call the prediction API. - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @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 @@ -75,7 +75,7 @@ def predict(input_source, all_words, full_text, close_file, cropper) end # Call the prediction API. - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @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 @@ -111,7 +111,7 @@ def parse_async(job_id) private - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource] + # @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 @@ -130,7 +130,7 @@ 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_contents(close: close_file)] @@ -145,7 +145,7 @@ 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 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 @@ -164,7 +164,7 @@ 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_contents(close: close_file)] diff --git a/lib/mindee/http/workflow_endpoint.rb b/lib/mindee/http/workflow_endpoint.rb index a45978e8..28af8530 100644 --- a/lib/mindee/http/workflow_endpoint.rb +++ b/lib/mindee/http/workflow_endpoint.rb @@ -23,7 +23,7 @@ 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 [bool] Whether to include the full OCR text response in compatible APIs. @@ -41,7 +41,7 @@ def execute_workflow(input_source, full_text, document_alias, priority, public_u 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 [bool] Whether to include the full OCR text response in compatible APIs. @@ -59,7 +59,7 @@ 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_contents] diff --git a/lib/mindee/input/sources/base64_input_source.rb b/lib/mindee/input/sources/base64_input_source.rb index 387b3c00..f3cd2a82 100644 --- a/lib/mindee/input/sources/base64_input_source.rb +++ b/lib/mindee/input/sources/base64_input_source.rb @@ -9,11 +9,11 @@ module Source class Base64InputSource < LocalInputSource # @param base64_string [String] # @param filename [String] - # @param fix_pdf [bool] - def initialize(base64_string, filename, fix_pdf: false) + # @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. diff --git a/lib/mindee/input/sources/bytes_input_source.rb b/lib/mindee/input/sources/bytes_input_source.rb index 89ce6e39..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 [bool] - 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 a58904db..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 [bool] - 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 7a0d1344..7cef27c9 100644 --- a/lib/mindee/input/sources/local_input_source.rb +++ b/lib/mindee/input/sources/local_input_source.rb @@ -32,11 +32,11 @@ class LocalInputSource # @param io_stream [StringIO, File] # @param filename [String] - # @param fix_pdf [bool] - 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 @@ -46,7 +46,7 @@ def initialize(io_stream, filename, fix_pdf: false) 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 diff --git a/lib/mindee/input/sources/path_input_source.rb b/lib/mindee/input/sources/path_input_source.rb index 4f5a25ba..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 [bool] - 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 e494bd67..e344fe5b 100644 --- a/lib/mindee/input/sources/url_input_source.rb +++ b/lib/mindee/input/sources/url_input_source.rb @@ -9,7 +9,7 @@ module Mindee module Input module Source # Load a remote document from a file url. - class UrlInputSource + class URLInputSource # @return [String] attr_reader :url diff --git a/sig/mindee/client.rbs b/sig/mindee/client.rbs index 16e5fe76..d74002a0 100644 --- a/sig/mindee/client.rbs +++ b/sig/mindee/client.rbs @@ -1,7 +1,6 @@ OTS_OWNER: String module Mindee - # Redeclare OTS_OWNER inside the module for internal use. OTS_OWNER: String class PageOptions @@ -25,7 +24,6 @@ module Mindee def initialize: (params: Hash[Symbol | String, untyped]) -> void end - # WorkflowOptions is defined via a Struct in client.rb. class WorkflowOptions attr_accessor document_alias: (String?) attr_accessor priority: (Symbol?) @@ -37,76 +35,29 @@ module Mindee end class Client - # Clients are initialized with a keyword api_key. def initialize: (api_key: String) -> void - - # The client internally uses a logger; its return type is left untyped. def logger: () -> untyped - - # Enqueue a document for parsing. - def parse: (Input::Source::LocalInputSource | Input::Source::UrlInputSource, untyped, ?endpoint: (HTTP::Endpoint?), options: ParseOptions | Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse - - # Synchronous parsing call. - # Note: options is expected to be a ParseOptions instance. - def parse_sync: (Input::Source::LocalInputSource | Input::Source::UrlInputSource, untyped, HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse - - # Asynchronous enqueuing of a document. - def enqueue: (Input::Source::LocalInputSource | Input::Source::UrlInputSource, untyped, ?endpoint: (HTTP::Endpoint?), options: ParseOptions|Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse - - # Polls for a queued document using its job_id. + 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 - - # Enqueue and then continually poll for the parsing result. - def enqueue_and_parse: (Input::Source::UrlInputSource|Input::Source::LocalInputSource, untyped, HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse - - # Sends a document to a workflow. - # The options parameter is either a Hash with symbol keys or a WorkflowOptions. - def execute_workflow: (Input::Source::UrlInputSource|Input::Source::LocalInputSource, String, options: (Hash[Symbol | String, untyped] | WorkflowOptions)) -> Parsing::Common::WorkflowResponse - - # Loads a prediction from a local response. + 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 - - # Creates an input source from a file path. - def source_from_path: (String, ?fix_pdf: bool) -> Input::Source::PathInputSource - - # Creates an input source from raw bytes. - def source_from_bytes: (String, String, ?fix_pdf: bool) -> Input::Source::BytesInputSource - - # Creates an input source from a base64 encoded string. - def source_from_b64string: (String, String, ?fix_pdf: bool) -> Input::Source::Base64InputSource - - # Creates an input source from a Ruby File. - def source_from_file: (File, String, ?fix_pdf: bool) -> Input::Source::FileInputSource - - # Creates an input source from a URL. - def source_from_url: (String) -> Input::Source::UrlInputSource - - # Creates a custom endpoint. - # The parameters are provided as keywords in client.rb but here they are declared as required. + 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 - - # Returns a ParseOptions instance given either a Hash or an existing ParseOptions. def normalize_parse_options: ((Hash[Symbol | String, untyped] | ParseOptions)) -> ParseOptions - - # Process the PDF if required. def process_pdf_if_required: (Input::Source::LocalInputSource, ParseOptions | WorkflowOptions) -> void - - # Creates an endpoint using the product class and supplied values. def initialize_endpoint: (singleton(Parsing::Common::Inference), ?endpoint_name: String, ?account_name: String, ?version: String) -> HTTP::Endpoint - - # Validates asynchronous polling parameters. def validate_async_params: (Integer | Float, Integer | Float, Integer) -> void - - # Helper to fix an endpoint name when not provided. def fix_endpoint_name: (singleton(Parsing::Common::Inference), String?) -> String? - - # Helper to fix the account name. def fix_account_name: (String) -> String - - # Helper to fix the version. - # Note: leave untyped, as RBS isn't able to recognize inherited class attributes yet. def fix_version: (singleton(Parsing::Common::Inference), String) -> String end end diff --git a/sig/mindee/input/sources/base64_input_source.rbs b/sig/mindee/input/sources/base64_input_source.rbs index 6df97dd5..0ddae587 100644 --- a/sig/mindee/input/sources/base64_input_source.rbs +++ b/sig/mindee/input/sources/base64_input_source.rbs @@ -3,7 +3,7 @@ module Mindee module Input module Source class Base64InputSource < LocalInputSource - def initialize: (String, String, ?fix_pdf: bool) -> void + def initialize: (String, String, ?repair_pdf: bool) -> void def read_contents: (?close: bool) -> [String, String, Hash[Symbol, untyped]] end end diff --git a/sig/mindee/input/sources/bytes_input_source.rbs b/sig/mindee/input/sources/bytes_input_source.rbs index 5af51d57..a3e21b66 100644 --- a/sig/mindee/input/sources/bytes_input_source.rbs +++ b/sig/mindee/input/sources/bytes_input_source.rbs @@ -3,7 +3,7 @@ module Mindee module Input module Source class BytesInputSource < LocalInputSource - def initialize: (String, String, ?fix_pdf: bool) -> void + def initialize: (String, String, ?repair_pdf: bool) -> void end end end diff --git a/sig/mindee/input/sources/file_input_source.rbs b/sig/mindee/input/sources/file_input_source.rbs index 039dc0ee..a3d4a713 100644 --- a/sig/mindee/input/sources/file_input_source.rbs +++ b/sig/mindee/input/sources/file_input_source.rbs @@ -3,7 +3,7 @@ module Mindee module Input module Source class FileInputSource < LocalInputSource - def initialize: (File, String, ?fix_pdf: bool) -> void + def initialize: (File, String, ?repair_pdf: bool) -> void end end end diff --git a/sig/mindee/input/sources/local_input_source.rbs b/sig/mindee/input/sources/local_input_source.rbs index c3426120..985fa780 100644 --- a/sig/mindee/input/sources/local_input_source.rbs +++ b/sig/mindee/input/sources/local_input_source.rbs @@ -7,7 +7,7 @@ module Mindee def filename: -> String def file_mimetype: -> String def io_stream: -> StringIO - def initialize: (StringIO | File, String, ?fix_pdf: bool) -> void + def initialize: (StringIO | File, String, ?repair_pdf: bool) -> void def logger: () -> untyped def rescue_broken_pdf: (StringIO) -> StringIO def pdf?: -> bool diff --git a/sig/mindee/input/sources/path_input_source.rbs b/sig/mindee/input/sources/path_input_source.rbs index f4cd1e6c..0e6dd7ba 100644 --- a/sig/mindee/input/sources/path_input_source.rbs +++ b/sig/mindee/input/sources/path_input_source.rbs @@ -3,7 +3,7 @@ module Mindee module Input module Source class PathInputSource < LocalInputSource - def initialize: (String, ?fix_pdf: bool) -> void + def initialize: (String, ?repair_pdf: bool) -> void end end end diff --git a/sig/mindee/input/sources/url_input_source.rbs b/sig/mindee/input/sources/url_input_source.rbs index 649d8631..93d08b5f 100644 --- a/sig/mindee/input/sources/url_input_source.rbs +++ b/sig/mindee/input/sources/url_input_source.rbs @@ -2,7 +2,7 @@ module Mindee module Input module Source - class UrlInputSource + class URLInputSource def url: -> String def logger: () -> untyped def initialize: (String) -> void diff --git a/spec/input/sources/sources_spec.rb b/spec/input/sources/sources_spec.rb index 927cabee..3ea20f04 100644 --- a/spec/input/sources/sources_spec.rb +++ b/spec/input/sources/sources_spec.rb @@ -55,7 +55,7 @@ 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) + mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_fixable.pdf", repair_pdf: true) end.not_to raise_error end end @@ -64,7 +64,7 @@ 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) + 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 @@ -75,7 +75,7 @@ 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) + 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 diff --git a/spec/input/sources/url_input_source_integration.rb b/spec/input/sources/url_input_source_integration.rb index d0f79f4a..9f8d25cd 100644 --- a/spec/input/sources/url_input_source_integration.rb +++ b/spec/input/sources/url_input_source_integration.rb @@ -2,11 +2,11 @@ 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/sources/url_input_source_spec.rb b/spec/input/sources/url_input_source_spec.rb index 0ebd2bec..3a0db99c 100644 --- a/spec/input/sources/url_input_source_spec.rb +++ b/spec/input/sources/url_input_source_spec.rb @@ -3,7 +3,7 @@ require 'mindee' require_relative '../../http/mock_http_response' -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' } From acc0f0321c2d33adb70593654230a6855abf8e27 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 25 Feb 2025 18:16:50 +0100 Subject: [PATCH 17/17] :recycle: add support for ruby 3.4 (#161) --- .github/workflows/_test-code-samples.yml | 1 + .github/workflows/_test-integrations.yml | 1 + .github/workflows/_test-units.yml | 1 + .github/workflows/cron.yml | 2 +- .github/workflows/publish-release.yml | 6 +- .github/workflows/pull-request.yml | 8 +- .github/workflows/push-main-branch.yml | 6 +- README.md | 2 +- bin/mindee.rb | 2 +- docs/advanced_file_operations.md | 4 +- docs/code_samples/bank_account_details_v1.txt | 5 + docs/code_samples/bank_account_details_v2.txt | 5 + docs/code_samples/bank_check_v1.txt | 5 + .../bank_statement_fr_v1_async.txt | 19 -- .../bank_statement_fr_v2_async.txt | 7 +- docs/code_samples/barcode_reader_v1.txt | 5 + docs/code_samples/bill_of_lading_v1.txt | 6 + docs/code_samples/bill_of_lading_v1_async.txt | 5 + docs/code_samples/business_card_v1.txt | 5 + docs/code_samples/business_card_v1_async.txt | 5 + docs/code_samples/carte_grise_v1.txt | 5 + docs/code_samples/cropper_v1.txt | 5 + docs/code_samples/default.txt | 5 + docs/code_samples/default_async.txt | 5 + docs/code_samples/delivery_notes_v1.txt | 5 + docs/code_samples/delivery_notes_v1_async.txt | 5 + docs/code_samples/driver_license_v1.txt | 5 + docs/code_samples/driver_license_v1_async.txt | 5 + docs/code_samples/energy_bill_fra_v1.txt | 5 + .../code_samples/energy_bill_fra_v1_async.txt | 5 + docs/code_samples/expense_receipts_v5.txt | 5 + .../expense_receipts_v5_async.txt | 5 + docs/code_samples/financial_document_v1.txt | 5 + .../financial_document_v1_async.txt | 5 + docs/code_samples/french_healthcard_v1.txt | 5 + .../french_healthcard_v1_async.txt | 5 + docs/code_samples/idcard_fr_v1.txt | 5 + docs/code_samples/idcard_fr_v2.txt | 5 + docs/code_samples/ind_passport_v1.txt | 5 + docs/code_samples/ind_passport_v1_async.txt | 5 + docs/code_samples/international_id_v2.txt | 5 + .../international_id_v2_async.txt | 5 + .../invoice_splitter_v1_async.txt | 5 + docs/code_samples/invoices_v4.txt | 5 + docs/code_samples/invoices_v4_async.txt | 5 + docs/code_samples/license_plates_v1.txt | 5 + .../multi_receipts_detector_v1.txt | 5 + docs/code_samples/nutrition_facts_v1.txt | 5 + .../code_samples/nutrition_facts_v1_async.txt | 5 + docs/code_samples/passport_v1.txt | 5 + docs/code_samples/payslip_fra_v2.txt | 5 + docs/code_samples/payslip_fra_v2_async.txt | 5 + docs/code_samples/payslip_fra_v3.txt | 5 + docs/code_samples/payslip_fra_v3_async.txt | 5 + docs/code_samples/resume_v1.txt | 5 + docs/code_samples/resume_v1_async.txt | 5 + docs/code_samples/us_healthcare_cards_v1.txt | 5 + .../us_healthcare_cards_v1_async.txt | 5 + docs/code_samples/us_mail_v3.txt | 5 + docs/code_samples/us_mail_v3_async.txt | 5 + docs/code_samples/us_w9_v1.txt | 5 + docs/global_products/barcode_reader_v1.md | 11 +- docs/global_products/bill_of_lading_v1.md | 31 ++- docs/global_products/business_card_v1.md | 21 +- docs/global_products/cropper_v1.md | 11 +- docs/global_products/delivery_notes_v1.md | 21 +- docs/global_products/driver_license_v1.md | 21 +- docs/global_products/expense_receipts_v5.md | 23 +- docs/global_products/financial_document_v1.md | 23 +- docs/global_products/international_id_v2.md | 21 +- docs/global_products/invoice_splitter_v1.md | 12 +- docs/global_products/invoices_v4.md | 23 +- .../multi_receipts_detector_v1.md | 11 +- docs/global_products/nutrition_facts_v1.md | 47 ++-- docs/global_products/passport_v1.md | 11 +- docs/global_products/resume_v1.md | 31 ++- docs/global_products/universal.md | 14 +- docs/loading_a_document.md | 2 +- .../bank_account_details_v2.md | 13 +- docs/localized_products/bank_check_v1.md | 11 +- .../bank_statement_fr_v1.md | 258 ------------------ .../bank_statement_fr_v2.md | 49 +++- docs/localized_products/carte_grise_v1.md | 11 +- docs/localized_products/energy_bill_fra_v1.md | 33 ++- .../french_healthcard_v1.md | 21 +- docs/localized_products/idcard_fr_v2.md | 11 +- docs/localized_products/ind_passport_v1.md | 21 +- docs/localized_products/license_plates_v1.md | 11 +- docs/localized_products/payslip_fra_v3.md | 37 +-- .../us_healthcare_cards_v1.md | 23 +- docs/localized_products/us_mail_v3.md | 25 +- docs/localized_products/us_w9_v1.md | 11 +- lib/mindee/product.rb | 1 - .../fr/bank_statement/bank_statement_v1.rb | 47 ---- .../bank_statement_v1_document.rb | 165 ----------- .../bank_statement/bank_statement_v1_page.rb | 38 --- .../bank_statement_v1_transaction.rb | 75 ----- .../fr/bank_statement/bank_statement_v2.rb | 12 +- .../bank_statement_v2_document.rb | 72 +++-- .../bank_statement/bank_statement_v2_page.rb | 14 +- .../bank_statement_v2_transaction.rb | 8 +- ...s.rb => bank_statement_v2_transactions.rb} | 12 +- mindee.gemspec | 3 +- ...statement_v1.rbs => bank_statement_v2.rbs} | 4 +- ...ent.rbs => bank_statement_v2_document.rbs} | 8 +- ...v1_page.rbs => bank_statement_v2_page.rbs} | 6 +- ....rbs => bank_statement_v2_transaction.rbs} | 2 +- ...rbs => bank_statement_v2_transactions.rbs} | 2 +- spec/extras/full_text_ocr_spec.rb | 10 +- spec/product/fr/bank_statement_v1_spec.rb | 32 --- spec/product/fr/bank_statement_v2_spec.rb | 32 +++ 111 files changed, 784 insertions(+), 933 deletions(-) delete mode 100644 docs/code_samples/bank_statement_fr_v1_async.txt delete mode 100644 docs/localized_products/bank_statement_fr_v1.md rename docs/{ => localized_products}/bank_statement_fr_v2.md (81%) delete mode 100644 lib/mindee/product/fr/bank_statement/bank_statement_v1.rb delete mode 100644 lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb delete mode 100644 lib/mindee/product/fr/bank_statement/bank_statement_v1_page.rb delete mode 100644 lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb rename lib/mindee/product/fr/bank_statement/{bank_statement_v1_transactions.rb => bank_statement_v2_transactions.rb} (82%) rename sig/mindee/product/fr/bank_statement/{bank_statement_v1.rbs => bank_statement_v2.rbs} (60%) rename sig/mindee/product/fr/bank_statement/{bank_statement_v1_document.rbs => bank_statement_v2_document.rbs} (83%) rename sig/mindee/product/fr/bank_statement/{bank_statement_v1_page.rbs => bank_statement_v2_page.rbs} (62%) rename sig/mindee/product/fr/bank_statement/{bank_statement_v1_transaction.rbs => bank_statement_v2_transaction.rbs} (88%) rename sig/mindee/product/fr/bank_statement/{bank_statement_v1_transactions.rbs => bank_statement_v2_transactions.rbs} (83%) delete mode 100644 spec/product/fr/bank_statement_v1_spec.rb diff --git a/.github/workflows/_test-code-samples.yml b/.github/workflows/_test-code-samples.yml index 87bd4b87..bbd5e8ce 100644 --- a/.github/workflows/_test-code-samples.yml +++ b/.github/workflows/_test-code-samples.yml @@ -15,6 +15,7 @@ jobs: - "3.1" - "3.2" - "3.3" + - "3.4" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/_test-integrations.yml b/.github/workflows/_test-integrations.yml index 377493fe..5f5b88b5 100644 --- a/.github/workflows/_test-integrations.yml +++ b/.github/workflows/_test-integrations.yml @@ -22,6 +22,7 @@ jobs: - "3.1" - "3.2" - "3.3" + - "3.4" steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/_test-units.yml b/.github/workflows/_test-units.yml index a13ff5ff..5f40538a 100644 --- a/.github/workflows/_test-units.yml +++ b/.github/workflows/_test-units.yml @@ -22,6 +22,7 @@ jobs: - "3.1" - "3.2" - "3.3" + - "3.4" steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index b2ec9b72..e7f14660 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -6,5 +6,5 @@ on: jobs: test_code_samples: - uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@develop/v4.0.0 + uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@main secrets: inherit diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 9af56316..a1178aeb 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -6,12 +6,12 @@ on: jobs: publish_docs: - uses: mindee/mindee-api-ruby/.github/workflows/_publish-docs.yml@develop/v4.0.0 + uses: mindee/mindee-api-ruby/.github/workflows/_publish-docs.yml@main secrets: inherit publish_guide: - uses: mindee/mindee-api-ruby/.github/workflows/_publish-guide.yml@develop/v4.0.0 + uses: mindee/mindee-api-ruby/.github/workflows/_publish-guide.yml@main needs: publish_docs secrets: inherit publish_code: - uses: mindee/mindee-api-ruby/.github/workflows/_publish-code.yml@develop/v4.0.0 + uses: mindee/mindee-api-ruby/.github/workflows/_publish-code.yml@main secrets: inherit diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 6bfe5f36..2690f22c 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,16 +5,16 @@ on: jobs: static_analysis: - uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@develop/v4.0.0 + uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@main test_units: - uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@develop/v4.0.0 + uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@main needs: static_analysis secrets: inherit test_integrations: - uses: mindee/mindee-api-ruby/.github/workflows/_test-integrations.yml@develop/v4.0.0 + uses: mindee/mindee-api-ruby/.github/workflows/_test-integrations.yml@main needs: test_units secrets: inherit test_code_samples: - uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@develop/v4.0.0 + uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@main needs: test_units secrets: inherit diff --git a/.github/workflows/push-main-branch.yml b/.github/workflows/push-main-branch.yml index a5e23267..f2cf102d 100644 --- a/.github/workflows/push-main-branch.yml +++ b/.github/workflows/push-main-branch.yml @@ -7,11 +7,11 @@ on: jobs: static_analysis: - uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@develop/v4.0.0 + uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@main test_units: - uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@develop/v4.0.0 + uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@main needs: static_analysis secrets: inherit tag: - uses: mindee/client-lib-actions/.github/workflows/tag-version.yml@develop/v4.0.0 + uses: mindee/client-lib-actions/.github/workflows/tag-version.yml@main needs: test_units diff --git a/README.md b/README.md index 35d170f4..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: 3.0, 3.1, 3.2, 3.3 +The following Ruby versions are tested and supported: 3.0, 3.1, 3.2, 3.3, 3.4 ## Quick Start diff --git a/bin/mindee.rb b/bin/mindee.rb index 5476bcdc..903093e1 100755 --- a/bin/mindee.rb +++ b/bin/mindee.rb @@ -74,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, }, diff --git a/docs/advanced_file_operations.md b/docs/advanced_file_operations.md index 517e1a10..519a4db4 100644 --- a/docs/advanced_file_operations.md +++ b/docs/advanced_file_operations.md @@ -95,8 +95,8 @@ This can sometimes help when files get rejected by the server. Example: ```rb -# Load a PDF file with the fix_pdf flag enabled. -input_source = mindee_client.source_from_file(file, "document.pdf", fix_pdf: true) +# 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. 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 76002339..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.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 index e626c77c..b9a0c6b3 100644 --- a/docs/code_samples/bill_of_lading_v1.txt +++ b/docs/code_samples/bill_of_lading_v1.txt @@ -1,3 +1,9 @@ +# +# 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_async.txt b/docs/code_samples/bill_of_lading_v1_async.txt index e626c77c..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 diff --git a/docs/code_samples/business_card_v1.txt b/docs/code_samples/business_card_v1.txt index ae200eac..d7adfea0 100644 --- a/docs/code_samples/business_card_v1.txt +++ b/docs/code_samples/business_card_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/business_card_v1_async.txt b/docs/code_samples/business_card_v1_async.txt index ae200eac..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 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/default.txt b/docs/code_samples/default.txt index 5ddcf176..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 diff --git a/docs/code_samples/default_async.txt b/docs/code_samples/default_async.txt index 230cfc95..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 diff --git a/docs/code_samples/delivery_notes_v1.txt b/docs/code_samples/delivery_notes_v1.txt index 8ba9cf72..895b3fc0 100644 --- a/docs/code_samples/delivery_notes_v1.txt +++ b/docs/code_samples/delivery_notes_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/delivery_notes_v1_async.txt b/docs/code_samples/delivery_notes_v1_async.txt index 8ba9cf72..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 diff --git a/docs/code_samples/driver_license_v1.txt b/docs/code_samples/driver_license_v1.txt index feafd685..700a4fe1 100644 --- a/docs/code_samples/driver_license_v1.txt +++ b/docs/code_samples/driver_license_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/driver_license_v1_async.txt b/docs/code_samples/driver_license_v1_async.txt index feafd685..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 diff --git a/docs/code_samples/energy_bill_fra_v1.txt b/docs/code_samples/energy_bill_fra_v1.txt index 01cda8d4..6d20bfa5 100644 --- a/docs/code_samples/energy_bill_fra_v1.txt +++ b/docs/code_samples/energy_bill_fra_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/energy_bill_fra_v1_async.txt b/docs/code_samples/energy_bill_fra_v1_async.txt index 01cda8d4..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 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 cc3d8bac..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 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 bca415af..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 diff --git a/docs/code_samples/french_healthcard_v1.txt b/docs/code_samples/french_healthcard_v1.txt index 1d557b08..8f0ebd8d 100644 --- a/docs/code_samples/french_healthcard_v1.txt +++ b/docs/code_samples/french_healthcard_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/french_healthcard_v1_async.txt b/docs/code_samples/french_healthcard_v1_async.txt index 1d557b08..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 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 index 9ee52bfb..af933cfc 100644 --- a/docs/code_samples/ind_passport_v1.txt +++ b/docs/code_samples/ind_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/ind_passport_v1_async.txt b/docs/code_samples/ind_passport_v1_async.txt index 9ee52bfb..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 diff --git a/docs/code_samples/international_id_v2.txt b/docs/code_samples/international_id_v2.txt index 05bdbc87..e463ab3c 100644 --- a/docs/code_samples/international_id_v2.txt +++ b/docs/code_samples/international_id_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/international_id_v2_async.txt b/docs/code_samples/international_id_v2_async.txt index 05bdbc87..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 diff --git a/docs/code_samples/invoice_splitter_v1_async.txt b/docs/code_samples/invoice_splitter_v1_async.txt index 24f697ec..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 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 1312a7c9..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 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 index d497e1b3..f3df6045 100644 --- a/docs/code_samples/nutrition_facts_v1.txt +++ b/docs/code_samples/nutrition_facts_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_async.txt b/docs/code_samples/nutrition_facts_v1_async.txt index d497e1b3..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 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/payslip_fra_v2.txt b/docs/code_samples/payslip_fra_v2.txt index 61444771..552ad0f5 100644 --- a/docs/code_samples/payslip_fra_v2.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 diff --git a/docs/code_samples/payslip_fra_v2_async.txt b/docs/code_samples/payslip_fra_v2_async.txt index 61444771..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 diff --git a/docs/code_samples/payslip_fra_v3.txt b/docs/code_samples/payslip_fra_v3.txt index 2c2317aa..52a074b0 100644 --- a/docs/code_samples/payslip_fra_v3.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 diff --git a/docs/code_samples/payslip_fra_v3_async.txt b/docs/code_samples/payslip_fra_v3_async.txt index 2c2317aa..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 diff --git a/docs/code_samples/resume_v1.txt b/docs/code_samples/resume_v1.txt index 7ff22b55..5439a462 100644 --- a/docs/code_samples/resume_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 diff --git a/docs/code_samples/resume_v1_async.txt b/docs/code_samples/resume_v1_async.txt index 7ff22b55..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 diff --git a/docs/code_samples/us_healthcare_cards_v1.txt b/docs/code_samples/us_healthcare_cards_v1.txt index e5b64179..4b36ae96 100644 --- a/docs/code_samples/us_healthcare_cards_v1.txt +++ b/docs/code_samples/us_healthcare_cards_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/us_healthcare_cards_v1_async.txt b/docs/code_samples/us_healthcare_cards_v1_async.txt index e5b64179..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 diff --git a/docs/code_samples/us_mail_v3.txt b/docs/code_samples/us_mail_v3.txt index 0c2a6e45..b42c6aff 100644 --- a/docs/code_samples/us_mail_v3.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 diff --git a/docs/code_samples/us_mail_v3_async.txt b/docs/code_samples/us_mail_v3_async.txt index 0c2a6e45..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 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/global_products/barcode_reader_v1.md b/docs/global_products/barcode_reader_v1.md index 756a79fa..bf7078b0 100644 --- a/docs/global_products/barcode_reader_v1.md +++ b/docs/global_products/barcode_reader_v1.md @@ -11,19 +11,24 @@ The Ruby Client Library supports the [Barcode Reader API](https://platform.minde > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `barcode_reader` | +> | 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. +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 diff --git a/docs/global_products/bill_of_lading_v1.md b/docs/global_products/bill_of_lading_v1.md index cf982b18..b8206eb7 100644 --- a/docs/global_products/bill_of_lading_v1.md +++ b/docs/global_products/bill_of_lading_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Bill of Lading API](https://platform.minde > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `bill_of_lading` | +> | Endpoint Name | `bill_of_lading` | > | Recommended Version | `v1.1` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Bill of Lading API](https://platform.minde > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 @@ -134,7 +139,7 @@ Fields which are specific to this product; they are not used in any other produc The party responsible for shipping the goods. A `BillOfLadingV1Shipper` 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. @@ -145,7 +150,7 @@ Fields which are specific to this product; they are not used in any other produc The party to whom the goods are being shipped. A `BillOfLadingV1Consignee` implements the following attributes: - + * `address` (String): The address of the consignee. * `email` (String): The email of the shipper. * `name` (String): The name of the consignee. @@ -156,7 +161,7 @@ Fields which are specific to this product; they are not used in any other produc The party to be notified of the arrival of the goods. A `BillOfLadingV1NotifyParty` implements the following attributes: - + * `address` (String): The address of the notify party. * `email` (String): The email of the shipper. * `name` (String): The name of the notify party. @@ -167,7 +172,7 @@ Fields which are specific to this product; they are not used in any other produc The shipping company responsible for transporting the goods. A `BillOfLadingV1Carrier` 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. @@ -177,7 +182,7 @@ Fields which are specific to this product; they are not used in any other produc 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. diff --git a/docs/global_products/business_card_v1.md b/docs/global_products/business_card_v1.md index 5f92ee05..d0ddcd1f 100644 --- a/docs/global_products/business_card_v1.md +++ b/docs/global_products/business_card_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Business Card API](https://platform.mindee > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `business_card` | +> | Endpoint Name | `business_card` | > | Recommended Version | `v1.0` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Business Card API](https://platform.mindee > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 diff --git a/docs/global_products/cropper_v1.md b/docs/global_products/cropper_v1.md index 887189ac..8591a34e 100644 --- a/docs/global_products/cropper_v1.md +++ b/docs/global_products/cropper_v1.md @@ -11,19 +11,24 @@ The Ruby Client Library supports the [Cropper API](https://platform.mindee.com/m > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `cropper` | +> | 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. +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 diff --git a/docs/global_products/delivery_notes_v1.md b/docs/global_products/delivery_notes_v1.md index 5e17db72..16e18d98 100644 --- a/docs/global_products/delivery_notes_v1.md +++ b/docs/global_products/delivery_notes_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Delivery note API](https://platform.mindee > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `delivery_notes` | +> | Endpoint Name | `delivery_notes` | > | Recommended Version | `v1.1` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Delivery note API](https://platform.mindee > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 diff --git a/docs/global_products/driver_license_v1.md b/docs/global_products/driver_license_v1.md index 240a758d..34346eba 100644 --- a/docs/global_products/driver_license_v1.md +++ b/docs/global_products/driver_license_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Driver License API](https://platform.minde > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `driver_license` | +> | Endpoint Name | `driver_license` | > | Recommended Version | `v1.0` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Driver License API](https://platform.minde > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 diff --git a/docs/global_products/expense_receipts_v5.md b/docs/global_products/expense_receipts_v5.md index a7904413..b5ee5f37 100644 --- a/docs/global_products/expense_receipts_v5.md +++ b/docs/global_products/expense_receipts_v5.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Receipt API](https://platform.mindee.com/m > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `expense_receipts` | +> | Endpoint Name | `expense_receipts` | > | Recommended Version | `v5.3` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ✔️ Yes | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Receipt API](https://platform.mindee.com/m > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -207,7 +212,7 @@ Fields which are specific to this product; they are not used in any other produc List of line item details. A `ReceiptV5LineItem` implements the following attributes: - + * `description` (String): The item description. * `quantity` (Float): The item quantity. * `total_amount` (Float): The item total amount. diff --git a/docs/global_products/financial_document_v1.md b/docs/global_products/financial_document_v1.md index 278a6cdb..870f16bd 100644 --- a/docs/global_products/financial_document_v1.md +++ b/docs/global_products/financial_document_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Financial Document API](https://platform.m > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `financial_document` | +> | Endpoint Name | `financial_document` | > | Recommended Version | `v1.11` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ✔️ Yes | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Financial Document API](https://platform.m > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -252,7 +257,7 @@ Fields which are specific to this product; they are not used in any other produc List of line item details. A `FinancialDocumentV1LineItem` implements the following attributes: - + * `description` (String): The item description. * `product_code` (String): The product code referring to the item. * `quantity` (Float): The item quantity diff --git a/docs/global_products/international_id_v2.md b/docs/global_products/international_id_v2.md index 94f33978..ba7d2c3f 100644 --- a/docs/global_products/international_id_v2.md +++ b/docs/global_products/international_id_v2.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [International ID API](https://platform.min > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `international_id` | +> | Endpoint Name | `international_id` | > | Recommended Version | `v2.1` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [International ID API](https://platform.min > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 diff --git a/docs/global_products/invoice_splitter_v1.md b/docs/global_products/invoice_splitter_v1.md index 1cda8bf5..9e4f2b5b 100644 --- a/docs/global_products/invoice_splitter_v1.md +++ b/docs/global_products/invoice_splitter_v1.md @@ -10,7 +10,7 @@ The Ruby Client Library supports the [Invoice Splitter API](https://platform.min > > | Specification | Details | > | ------------------------------ |--------------------| -> | Endpoint | `invoice_splitter` | +> | Endpoint Name | `invoice_splitter` | > | Recommended Version | `v1.2` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -18,11 +18,11 @@ The Ruby Client Library supports the [Invoice Splitter API](https://platform.min > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. diff --git a/docs/global_products/invoices_v4.md b/docs/global_products/invoices_v4.md index 4d97434c..3ae7acf9 100644 --- a/docs/global_products/invoices_v4.md +++ b/docs/global_products/invoices_v4.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Invoice API](https://platform.mindee.com/m > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `invoices` | +> | Endpoint Name | `invoices` | > | Recommended Version | `v4.9` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ✔️ Yes | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Invoice API](https://platform.mindee.com/m > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 +# +# Install the Ruby client library by running: +# gem install mindee +# + require 'mindee' # Init a new client @@ -240,7 +245,7 @@ Fields which are specific to this product; they are not used in any other produc List of line item details. A `InvoiceV4LineItem` implements the following attributes: - + * `description` (String): The item description. * `product_code` (String): The product code referring to the item. * `quantity` (Float): The item quantity diff --git a/docs/global_products/multi_receipts_detector_v1.md b/docs/global_products/multi_receipts_detector_v1.md index 29e6c3c6..650be0a7 100644 --- a/docs/global_products/multi_receipts_detector_v1.md +++ b/docs/global_products/multi_receipts_detector_v1.md @@ -11,19 +11,24 @@ The Ruby Client Library supports the [Multi Receipts Detector API](https://platf > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `multi_receipts_detector` | +> | 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. +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 diff --git a/docs/global_products/nutrition_facts_v1.md b/docs/global_products/nutrition_facts_v1.md index c586d443..17b40638 100644 --- a/docs/global_products/nutrition_facts_v1.md +++ b/docs/global_products/nutrition_facts_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Nutrition Facts Label API](https://platfor > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `nutrition_facts` | +> | Endpoint Name | `nutrition_facts` | > | Recommended Version | `v1.0` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Nutrition Facts Label API](https://platfor > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 @@ -160,7 +165,7 @@ Fields which are specific to this product; they are not used in any other produc The size of a single serving of the product. A `NutritionFactsLabelV1ServingSize` implements the following attributes: - + * `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. @@ -169,7 +174,7 @@ Fields which are specific to this product; they are not used in any other produc The amount of calories in the product. A `NutritionFactsLabelV1Calorie` implements the following attributes: - + * `daily_value` (Float): DVs are the recommended amounts of calories to consume or not to exceed each day. * `per_100g` (Float): The amount of calories per 100g of the product. * `per_serving` (Float): The amount of calories per serving of the product. @@ -179,7 +184,7 @@ Fields which are specific to this product; they are not used in any other produc The total amount of fat in the product. A `NutritionFactsLabelV1TotalFat` 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. @@ -189,7 +194,7 @@ Fields which are specific to this product; they are not used in any other produc The amount of saturated fat in the product. A `NutritionFactsLabelV1SaturatedFat` implements the following attributes: - + * `daily_value` (Float): DVs are the recommended amounts of saturated fat to consume or not to exceed each day. * `per_100g` (Float): The amount of saturated fat per 100g of the product. * `per_serving` (Float): The amount of saturated fat per serving of the product. @@ -199,7 +204,7 @@ Fields which are specific to this product; they are not used in any other produc The amount of trans fat in the product. A `NutritionFactsLabelV1TransFat` 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. @@ -209,7 +214,7 @@ Fields which are specific to this product; they are not used in any other produc 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. @@ -219,7 +224,7 @@ Fields which are specific to this product; they are not used in any other produc The total amount of carbohydrates in the product. A `NutritionFactsLabelV1TotalCarbohydrate` implements the following attributes: - + * `daily_value` (Float): DVs are the recommended amounts of total carbohydrates to consume or not to exceed each day. * `per_100g` (Float): The amount of total carbohydrates per 100g of the product. * `per_serving` (Float): The amount of total carbohydrates per serving of the product. @@ -229,7 +234,7 @@ Fields which are specific to this product; they are not used in any other produc 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. @@ -239,7 +244,7 @@ Fields which are specific to this product; they are not used in any other produc The total amount of sugars in the product. A `NutritionFactsLabelV1TotalSugar` implements the following attributes: - + * `daily_value` (Float): DVs are the recommended amounts of total sugars to consume or not to exceed each day. * `per_100g` (Float): The amount of total sugars per 100g of the product. * `per_serving` (Float): The amount of total sugars per serving of the product. @@ -249,7 +254,7 @@ Fields which are specific to this product; they are not used in any other produc The amount of added sugars in the product. A `NutritionFactsLabelV1AddedSugar` 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. @@ -259,7 +264,7 @@ Fields which are specific to this product; they are not used in any other produc 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. @@ -269,7 +274,7 @@ Fields which are specific to this product; they are not used in any other produc 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. @@ -280,7 +285,7 @@ Fields which are specific to this product; they are not used in any other produc 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. diff --git a/docs/global_products/passport_v1.md b/docs/global_products/passport_v1.md index 7c493900..87b75482 100644 --- a/docs/global_products/passport_v1.md +++ b/docs/global_products/passport_v1.md @@ -11,19 +11,24 @@ The Ruby Client Library supports the [Passport API](https://platform.mindee.com/ > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `passport` | +> | 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. +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 diff --git a/docs/global_products/resume_v1.md b/docs/global_products/resume_v1.md index 453b4577..1b8eb175 100644 --- a/docs/global_products/resume_v1.md +++ b/docs/global_products/resume_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Resume API](https://platform.mindee.com/mi > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `resume` | +> | Endpoint Name | `resume` | > | Recommended Version | `v1.2` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Resume API](https://platform.mindee.com/mi > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 @@ -161,7 +166,7 @@ Fields which are specific to this product; they are not used in any other produc The list of social network profiles of the candidate. A `ResumeV1SocialNetworksUrl` implements the following attributes: - + * `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. @@ -170,7 +175,7 @@ Fields which are specific to this product; they are not used in any other produc The list of languages that the candidate is proficient in. A `ResumeV1Language` implements the following attributes: - + * `language` (String): The language's ISO 639 code. * `level` (String): The candidate's level for the language. @@ -187,7 +192,7 @@ Fields which are specific to this product; they are not used in any other produc 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. @@ -201,7 +206,7 @@ Fields which are specific to this product; they are not used in any other produc The list of the candidate's professional experiences. A `ResumeV1ProfessionalExperience` implements the following attributes: - + * `contract_type` (String): The type of contract for the professional experience. #### Possible values include: @@ -224,7 +229,7 @@ Fields which are specific to this product; they are not used in any other produc 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. diff --git a/docs/global_products/universal.md b/docs/global_products/universal.md index a8d0269d..d6e2577f 100644 --- a/docs/global_products/universal.md +++ b/docs/global_products/universal.md @@ -10,19 +10,19 @@ The Ruby Client Library implements a universal wrapper class for all products. > > | Specification | Details | > | ------------------------------ |-----------------------------------------------------------------| -> | Endpoint | `` | +> | Endpoint Name | `` | > | Recommended Version | `v` Defaults to 1 for custom products. | > | Supports Polling/Webhooks | ❓️ Variable | > | Support Synchronous HTTP Calls | ❓ Variable | > | Geography | ❓ Variable | -> 🔐 Polling Limitations (Polling only) +> 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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: diff --git a/docs/loading_a_document.md b/docs/loading_a_document.md index 7c66035e..7fae7448 100644 --- a/docs/loading_a_document.md +++ b/docs/loading_a_document.md @@ -306,7 +306,7 @@ When loading using from either a path, file, raw byte sequence or base64 string, [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 ([fix_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. +* 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. diff --git a/docs/localized_products/bank_account_details_v2.md b/docs/localized_products/bank_account_details_v2.md index 7e5c0637..c3387574 100644 --- a/docs/localized_products/bank_account_details_v2.md +++ b/docs/localized_products/bank_account_details_v2.md @@ -11,19 +11,24 @@ The Ruby Client Library supports the [Bank Account Details API](https://platform > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `bank_account_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. +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 @@ -112,7 +117,7 @@ Fields which are specific to this product; they are not used in any other produc Full extraction of BBAN, including: branch code, bank code, account and key. A `BankAccountDetailsV2Bban` implements the following attributes: - + * `bban_bank_code` (String): The BBAN bank code outputted as a string. * `bban_branch_code` (String): The BBAN branch code outputted as a string. * `bban_key` (String): The BBAN key outputted as a string. diff --git a/docs/localized_products/bank_check_v1.md b/docs/localized_products/bank_check_v1.md index f61f2275..b05accb9 100644 --- a/docs/localized_products/bank_check_v1.md +++ b/docs/localized_products/bank_check_v1.md @@ -11,19 +11,24 @@ The Ruby Client Library supports the [Bank Check API](https://platform.mindee.co > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `bank_check` | +> | 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. +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 diff --git a/docs/localized_products/bank_statement_fr_v1.md b/docs/localized_products/bank_statement_fr_v1.md deleted file mode 100644 index 062ad566..00000000 --- a/docs/localized_products/bank_statement_fr_v1.md +++ /dev/null @@ -1,258 +0,0 @@ ---- -title: Ruby Client Library - FR Bank Statement -category: 622b805aaec68102ea7fcbc2 -slug: ruby-fr-bank-statement-ocr -parentDoc: 67b49e29a2cd6f08d69a40d8 ---- -The Ruby Client Library supports the [Bank Statement API](https://platform.mindee.com/mindee/bank_statement_fr). - - -> 📝 Product Specs -> -> | Specification | Details | -> | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `bank_statement_fr` | -> | Recommended Version | `v1.1` | -> | Supports Polling/Webhooks | ✔️ Yes | -> | Support Synchronous HTTP Calls | ❌ No | -> | Geography | 🇫🇷 France | - -> 🔐 Polling Limitations -> -> | Setting | Parameter name | 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 -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::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 -######## -Document -######## -:Mindee ID: b9bdb0fd-87bd-4a76-b488-1da3ce53d11d -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/bank_statement_fr v1.0 -:Rotation applied: No - -Prediction -========== -:Account Number: XXXXXXXXXXXXX -:Bank Name: lafinancepourtous -:Bank Address: 1 rue de la Banque, 100210 Cassette -:Client Name: Karine Plume -:Client Address: 1 rue des Cigales, 100210 Cassette -:Statement Date: 2002-02-28 -:Statement Start Date: 2002-02-01 -:Statement End Date: 2002-02-28 -:Opening Balance: 22.15 -:Closing Balance: -278.96 -:Transactions: - +-----------+------------+--------------------------------------+ - | Amount | Date | Description | - +===========+============+======================================+ - | 1240.00 | 2002-02-01 | Virement salaire | - +-----------+------------+--------------------------------------+ - | 520.00 | 2002-02-02 | Virement loyer | - +-----------+------------+--------------------------------------+ - | -312.00 | 2002-02-03 | Débit Carte nºxxxxx xxxxxxxxxxxx | - +-----------+------------+--------------------------------------+ - | 65.00 | 2002-02-05 | Virement APL | - +-----------+------------+--------------------------------------+ - | -3.30 | 2002-02-08 | Cotisation mensuelle carte bancaire | - +-----------+------------+--------------------------------------+ - | -120.00 | 2002-02-09 | Chèque nº xxxxxxx98 | - +-----------+------------+--------------------------------------+ - | -60.00 | 2002-02-09 | Retrait espèces DAB | - +-----------+------------+--------------------------------------+ - | -55.00 | 2002-02-15 | Chèque n ° xxxxxxXx99 | - +-----------+------------+--------------------------------------+ - | -80.00 | 2002-02-16 | Prélèvement supercrédit | - +-----------+------------+--------------------------------------+ - | -120.00 | 2002-02-17 | Chèque n ° xxxxx100 | - +-----------+------------+--------------------------------------+ - | -163.25 | 2002-02-20 | Débit Carte n ° xxxxxxxxxxxxxxxxxx | - +-----------+------------+--------------------------------------+ - | -25.50 | 2002-02-21 | Débit Carte nºxxxxxxxxxxxxxxxxx | - +-----------+------------+--------------------------------------+ - | -30.00 | 2002-02-24 | Prélèvement Opérateur téléphonique | - +-----------+------------+--------------------------------------+ - | -6.53 | 2002-02-25 | Agios | - +-----------+------------+--------------------------------------+ - | -13.00 | 2002-02-28 | Frais irrégularités et incidents ... | - +-----------+------------+--------------------------------------+ -:Total Debits: 1618.58 -:Total Credits: 1339.62 -``` - -# 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`, `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** (`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. - - -### 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 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 -result.document.inference.prediction.transactions do |transactions_elem| - 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/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/localized_products/carte_grise_v1.md b/docs/localized_products/carte_grise_v1.md index 167baabd..c2c9a1a5 100644 --- a/docs/localized_products/carte_grise_v1.md +++ b/docs/localized_products/carte_grise_v1.md @@ -11,19 +11,24 @@ The Ruby Client Library supports the [Carte Grise API](https://platform.mindee.c > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `carte_grise` | +> | 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. +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 diff --git a/docs/localized_products/energy_bill_fra_v1.md b/docs/localized_products/energy_bill_fra_v1.md index 129551ee..3cfb5603 100644 --- a/docs/localized_products/energy_bill_fra_v1.md +++ b/docs/localized_products/energy_bill_fra_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Energy Bill API](https://platform.mindee.c > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `energy_bill_fra` | +> | Endpoint Name | `energy_bill_fra` | > | Recommended Version | `v1.0` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Energy Bill API](https://platform.mindee.c > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 @@ -149,7 +154,7 @@ Fields which are specific to this product; they are not used in any other produc 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. @@ -158,7 +163,7 @@ Fields which are specific to this product; they are not used in any other produc The entity that consumes the energy. A `EnergyBillV1EnergyConsumer` implements the following attributes: - + * `address` (String): The address of the energy consumer. * `name` (String): The name of the energy consumer. Fields which are specific to this product; they are not used in any other product. @@ -167,7 +172,7 @@ Fields which are specific to this product; they are not used in any other produc 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. @@ -180,7 +185,7 @@ Fields which are specific to this product; they are not used in any other produc Details of energy consumption. A `EnergyBillV1EnergyUsage` implements the following attributes: - + * `description` (String): Description or details of the energy usage. * `end_date` (String): The end date of the energy usage. * `start_date` (String): The start date of the energy usage. @@ -193,7 +198,7 @@ Fields which are specific to this product; they are not used in any other produc 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. @@ -206,7 +211,7 @@ Fields which are specific to this product; they are not used in any other produc Information about the energy meter. A `EnergyBillV1MeterDetail` implements the following attributes: - + * `meter_number` (String): The unique identifier of the energy meter. * `meter_type` (String): The type of energy meter. diff --git a/docs/localized_products/french_healthcard_v1.md b/docs/localized_products/french_healthcard_v1.md index 05822db5..27411816 100644 --- a/docs/localized_products/french_healthcard_v1.md +++ b/docs/localized_products/french_healthcard_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Health Card API](https://platform.mindee.c > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `french_healthcard` | +> | Endpoint Name | `french_healthcard` | > | Recommended Version | `v1.0` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Health Card API](https://platform.mindee.c > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 diff --git a/docs/localized_products/idcard_fr_v2.md b/docs/localized_products/idcard_fr_v2.md index 3c19ed16..93311d6f 100644 --- a/docs/localized_products/idcard_fr_v2.md +++ b/docs/localized_products/idcard_fr_v2.md @@ -11,19 +11,24 @@ The Ruby Client Library supports the [Carte Nationale d'Identité API](https://p > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `idcard_fr` | +> | 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. +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 diff --git a/docs/localized_products/ind_passport_v1.md b/docs/localized_products/ind_passport_v1.md index ff1231f2..8a35420c 100644 --- a/docs/localized_products/ind_passport_v1.md +++ b/docs/localized_products/ind_passport_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Passport - India API](https://platform.min > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `ind_passport` | +> | Endpoint Name | `ind_passport` | > | Recommended Version | `v1.2` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Passport - India API](https://platform.min > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 diff --git a/docs/localized_products/license_plates_v1.md b/docs/localized_products/license_plates_v1.md index 47a0d409..c448e4bc 100644 --- a/docs/localized_products/license_plates_v1.md +++ b/docs/localized_products/license_plates_v1.md @@ -11,19 +11,24 @@ The Ruby Client Library supports the [License Plate API](https://platform.mindee > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `license_plates` | +> | 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. +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 diff --git a/docs/localized_products/payslip_fra_v3.md b/docs/localized_products/payslip_fra_v3.md index 92a967b3..bab3ecff 100644 --- a/docs/localized_products/payslip_fra_v3.md +++ b/docs/localized_products/payslip_fra_v3.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Payslip API](https://platform.mindee.com/m > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `payslip_fra` | +> | Endpoint Name | `payslip_fra` | > | Recommended Version | `v3.0` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Payslip API](https://platform.mindee.com/m > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 @@ -160,7 +165,7 @@ Fields which are specific to this product; they are not used in any other produc Information about the pay period. A `PayslipV3PayPeriod` 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. @@ -172,7 +177,7 @@ Fields which are specific to this product; they are not used in any other produc Information about the employee. A `PayslipV3Employee` 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. @@ -186,7 +191,7 @@ Fields which are specific to this product; they are not used in any other produc Information about the employer. A `PayslipV3Employer` 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. @@ -200,7 +205,7 @@ Fields which are specific to this product; they are not used in any other produc 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. @@ -210,7 +215,7 @@ Fields which are specific to this product; they are not used in any other produc Information about the employment. A `PayslipV3Employment` implements the following attributes: - + * `category` (String): The category of the employment. * `coefficient` (String): The coefficient of the employment. * `collective_agreement` (String): The collective agreement of the employment. @@ -224,7 +229,7 @@ Fields which are specific to this product; they are not used in any other produc Detailed information about the earnings. A `PayslipV3SalaryDetail` implements the following attributes: - + * `amount` (Float): The amount of the earning. * `base` (Float): The base rate value of the earning. * `description` (String): The description of the earnings. @@ -236,7 +241,7 @@ Fields which are specific to this product; they are not used in any other produc Detailed information about the pay. A `PayslipV3PayDetail` 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. @@ -253,7 +258,7 @@ Fields which are specific to this product; they are not used in any other produc 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. diff --git a/docs/localized_products/us_healthcare_cards_v1.md b/docs/localized_products/us_healthcare_cards_v1.md index 23f45195..24621d0a 100644 --- a/docs/localized_products/us_healthcare_cards_v1.md +++ b/docs/localized_products/us_healthcare_cards_v1.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [Healthcare Card API](https://platform.mind > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `us_healthcare_cards` | +> | Endpoint Name | `us_healthcare_cards` | > | Recommended Version | `v1.0` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [Healthcare Card API](https://platform.mind > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 @@ -129,7 +134,7 @@ Fields which are specific to this product; they are not used in any other produc Is a fixed amount for a covered service. A `HealthcareCardV1Copay` implements the following attributes: - + * `service_fees` (Float): The price of service. * `service_name` (String): The name of service of the copay. diff --git a/docs/localized_products/us_mail_v3.md b/docs/localized_products/us_mail_v3.md index 97116a50..385bb895 100644 --- a/docs/localized_products/us_mail_v3.md +++ b/docs/localized_products/us_mail_v3.md @@ -11,7 +11,7 @@ The Ruby Client Library supports the [US Mail API](https://platform.mindee.com/m > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `us_mail` | +> | Endpoint Name | `us_mail` | > | Recommended Version | `v3.0` | > | Supports Polling/Webhooks | ✔️ Yes | > | Support Synchronous HTTP Calls | ❌ No | @@ -19,19 +19,24 @@ The Ruby Client Library supports the [US Mail API](https://platform.mindee.com/m > 🔐 Polling Limitations > -> | Setting | Parameter name | 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 | +> | 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. +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 @@ -113,7 +118,7 @@ Fields which are specific to this product; they are not used in any other produc 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. @@ -125,7 +130,7 @@ Fields which are specific to this product; they are not used in any other produc The addresses of the recipients. 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` (bool): Indicates if the recipient's address is a change of address. diff --git a/docs/localized_products/us_w9_v1.md b/docs/localized_products/us_w9_v1.md index 9249ed3e..3acdbfa3 100644 --- a/docs/localized_products/us_w9_v1.md +++ b/docs/localized_products/us_w9_v1.md @@ -11,19 +11,24 @@ The Ruby Client Library supports the [W9 API](https://platform.mindee.com/mindee > > | Specification | Details | > | ------------------------------ | -------------------------------------------------- | -> | Endpoint | `us_w9` | +> | 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. +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 diff --git a/lib/mindee/product.rb b/lib/mindee/product.rb index 1148ab56..51106cc2 100644 --- a/lib/mindee/product.rb +++ b/lib/mindee/product.rb @@ -9,7 +9,6 @@ require_relative 'product/eu/license_plate/license_plate_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' 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 3264a75c..00000000 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1.rb +++ /dev/null @@ -1,47 +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 module. - module BankStatement - # Bank Statement API version 1 inference prediction. - class BankStatementV1 < Mindee::Parsing::Common::Inference - @endpoint_name = 'bank_statement_fr' - @endpoint_version = '1' - @has_async = true - @has_sync = false - - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = BankStatementV1Document.new(prediction['prediction'], nil) - @pages = [] - prediction['pages'].each do |page| - @pages.push(BankStatementV1Page.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 - # 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 -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 51fc68d3..00000000 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_document.rb +++ /dev/null @@ -1,165 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../../parsing' -require_relative 'bank_statement_v1_transactions' - -module Mindee - module Product - module FR - module BankStatement - # Bank Statement API version 1.1 document data. - 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 [Mindee::Product::FR::BankStatement::BankStatementV1Transactions] - attr_reader :transactions - - # @param prediction [Hash] - # @param page_id [Integer, nil] - def initialize(prediction, page_id) - 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_name = Parsing::Standard::StringField.new( - prediction['client_name'], - page_id - ) - @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::BankStatementV1Transactions.new( - prediction['transactions'], page_id - ) - 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 44ec229a..00000000 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_page.rb +++ /dev/null @@ -1,38 +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 API version 1.1 page data. - class BankStatementV1Page < Mindee::Parsing::Common::Page - # @param prediction [Hash] - def initialize(prediction) - super - @prediction = if prediction['prediction'].empty? - nil - else - BankStatementV1PagePrediction.new( - prediction['prediction'], - prediction['id'] - ) - end - end - end - - # Bank Statement 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 5f10583e..00000000 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rb +++ /dev/null @@ -1,75 +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 - @amount = prediction['amount'] - @date = prediction['date'] - @description = prediction['description'] - @page_id = page_id - end - - # @return [Hash] - def printable_values - printable = {} - printable[:amount] = - @amount.nil? ? '' : Parsing::Standard::BaseField.float_to_string(@amount) - printable[:date] = format_for_display(@date) - printable[:description] = format_for_display(@description) - printable - end - - # @return [Hash] - def table_printable_values - printable = {} - 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 - end - - # @return [String] - def to_table_line - printable = table_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_v1_transactions.rb b/lib/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rb similarity index 82% rename from lib/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rb rename to lib/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rb index 0dcbeef3..b62ca3ff 100644 --- a/lib/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rb +++ b/lib/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rb @@ -1,22 +1,22 @@ # frozen_string_literal: true -require_relative 'bank_statement_v1_transaction' +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 BankStatementV1Transactions < Array + class BankStatementV2Transactions < Array # Entries. - # @return [Array] + # @return [Array] attr_reader :entries # @param prediction [Array] # @param page_id [Integer, nil] def initialize(prediction, page_id) entries = prediction.map do |entry| - BankStatement::BankStatementV1Transaction.new(entry, page_id) + BankStatement::BankStatementV2Transaction.new(entry, page_id) end super(entries) end @@ -26,7 +26,7 @@ def initialize(prediction, page_id) # @return [String] def self.line_items_separator(char) out_str = String.new - out_str << "+#{char * 11}" + out_str << "+#{char * 12}" out_str << "+#{char * 12}" out_str << "+#{char * 38}" out_str @@ -41,7 +41,7 @@ def to_s end.join out_str = String.new out_str << ("\n#{self.class.line_items_separator('-')}\n ") - out_str << ' | Amount ' + out_str << ' | Amount ' out_str << ' | Date ' out_str << ' | Description ' out_str << (" |\n#{self.class.line_items_separator('=')}") diff --git a/mindee.gemspec b/mindee.gemspec index 78fbab57..4abc776c 100644 --- a/mindee.gemspec +++ b/mindee.gemspec @@ -27,9 +27,10 @@ Gem::Specification.new do |spec| 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', '~> 3.1.0' + spec.add_dependency 'origamindee', '~> 4.0.0' spec.add_dependency 'pdf-reader', '~> 2.13.0' spec.add_development_dependency 'prism', '~> 1.3' diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v1.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs similarity index 60% rename from sig/mindee/product/fr/bank_statement/bank_statement_v1.rbs rename to sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs index ea9010a4..eeabf480 100644 --- a/sig/mindee/product/fr/bank_statement/bank_statement_v1.rbs +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs @@ -1,10 +1,10 @@ -# lib/mindee/product/../bank_statement/bank_statement_v1.rb +# lib/mindee/product/../bank_statement/bank_statement_v2.rb module Mindee module Product module FR module BankStatement - class BankStatementV1 < Parsing::Common::Inference + class BankStatementV2 < Parsing::Common::Inference def initialize: (Hash[Symbol | String, untyped]) -> void end end diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v1_document.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs similarity index 83% rename from sig/mindee/product/fr/bank_statement/bank_statement_v1_document.rbs rename to sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs index fe70db07..9a536ff4 100644 --- a/sig/mindee/product/fr/bank_statement/bank_statement_v1_document.rbs +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs @@ -1,16 +1,16 @@ -# lib/mindee/product/../bank_statement/bank_statement_v1_document.rb +# lib/mindee/product/../bank_statement/bank_statement_v2_document.rb module Mindee module Product module FR module BankStatement - class BankStatementV1Document < Parsing::Common::Prediction + 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_name: -> (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) @@ -18,7 +18,7 @@ module Mindee def statement_start_date: -> (Parsing::Standard::DateField) def total_credits: -> (Parsing::Standard::AmountField) def total_debits: -> (Parsing::Standard::AmountField) - def transactions: -> (Product::FR::BankStatement::BankStatementV1Transactions) + def transactions: -> (Product::FR::BankStatement::BankStatementV2Transactions) def transactions_separator: (String) -> String def transactions_to_s: -> String def to_s: -> String diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v1_page.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs similarity index 62% rename from sig/mindee/product/fr/bank_statement/bank_statement_v1_page.rbs rename to sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs index 6566b0aa..c586ae46 100644 --- a/sig/mindee/product/fr/bank_statement/bank_statement_v1_page.rbs +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs @@ -1,13 +1,13 @@ -# lib/mindee/product/../bank_statement/bank_statement_v1_page.rb +# lib/mindee/product/../bank_statement/bank_statement_v2_page.rb module Mindee module Product module FR module BankStatement - class BankStatementV1Page < Parsing::Common::Page + class BankStatementV2Page < Parsing::Common::Page def initialize: (Hash[Symbol | String, untyped]) -> void end - class BankStatementV1PagePrediction < BankStatementV1Document + class BankStatementV2PagePrediction < BankStatementV2Document def initialize: (Hash[Symbol | String, untyped], Integer?) -> void def to_s: -> String end diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs similarity index 88% rename from sig/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rbs rename to sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs index 731d130c..41e4158d 100644 --- a/sig/mindee/product/fr/bank_statement/bank_statement_v1_transaction.rbs +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs @@ -2,7 +2,7 @@ module Mindee module Product module FR module BankStatement - class BankStatementV1Transaction < Parsing::Standard::FeatureField + class BankStatementV2Transaction < Parsing::Standard::FeatureField def initialize: (Hash[Symbol | String, untyped], Integer?) -> void def amount: -> Float def date: -> String diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rbs similarity index 83% rename from sig/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rbs rename to sig/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rbs index 5acc6cec..4e36cf22 100644 --- a/sig/mindee/product/fr/bank_statement/bank_statement_v1_transactions.rbs +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_transactions.rbs @@ -4,7 +4,7 @@ module Mindee module Product module FR module BankStatement - class BankStatementV1Transactions < Array[untyped] + class BankStatementV2Transactions < Array[untyped] def initialize: (Array[untyped], Integer?) -> void def self.line_items_separator: (String) -> String def to_s: -> String diff --git a/spec/extras/full_text_ocr_spec.rb b/spec/extras/full_text_ocr_spec.rb index 27441683..e2f62ee9 100644 --- a/spec/extras/full_text_ocr_spec.rb +++ b/spec/extras/full_text_ocr_spec.rb @@ -25,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 @@ -94,10 +94,10 @@ 'value' => nil, 'confidence' => 0, }, - 'client_name' => { + 'client_names' => [{ 'value' => nil, 'confidence' => 0, - }, + }], 'closing_balance' => { 'value' => nil, 'confidence' => 0, @@ -138,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/product/fr/bank_statement_v1_spec.rb b/spec/product/fr/bank_statement_v1_spec.rb deleted file mode 100644 index e643acb8..00000000 --- a/spec/product/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 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/product/fr/bank_statement_v2_spec.rb b/spec/product/fr/bank_statement_v2_spec.rb index e69de29b..779f949c 100644 --- a/spec/product/fr/bank_statement_v2_spec.rb +++ b/spec/product/fr/bank_statement_v2_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'json' +require 'mindee/product' +require 'mindee/parsing' + +require_relative '../../data' + +DIR_FR_BANK_STATEMENT_V2 = File.join(DATA_DIR, 'products', 'bank_statement_fr', 'response_v2').freeze + +describe Mindee::Product::FR::BankStatement::BankStatementV2 do + context 'A Bank Statement V2' do + it 'should load an empty document prediction' do + response = load_json(DIR_FR_BANK_STATEMENT_V2, 'empty.json') + inference = Mindee::Parsing::Common::Document.new( + Mindee::Product::FR::BankStatement::BankStatementV2, + 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_V2, 'summary_full.rst') + response = load_json(DIR_FR_BANK_STATEMENT_V2, 'complete.json') + document = Mindee::Parsing::Common::Document.new( + Mindee::Product::FR::BankStatement::BankStatementV2, + response['document'] + ) + expect(document.to_s).to eq(to_string) + end + end +end