Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/_publish-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
ruby-version: "3.2"
bundler-cache: true

- name: Set credentials
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.1"
ruby-version: "3.2"
bundler-cache: true

- name: Analyse the code with Rubocop
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0.0"
ruby-version: "3.2.0"
bundler-cache: true

- name: Set up Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_test-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- os: "windows-latest"
rid: "win-x64"
ruby:
- "3.0"
- "3.2"
- "4.0"
runs-on: ${{ matrix.os_config.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_test-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- "ubuntu-24.04"
- "macos-latest"
ruby:
- "3.0"
- "3.2"
- "4.0"
steps:
- uses: actions/checkout@v5
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/_test-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ jobs:
strategy:
matrix:
ruby:
- "3.0"
- "3.1"
- "3.2"
- "3.3"
- "3.4"
- "4.0"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/_test-units.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:
- "ubuntu-22.04"
- "macos-latest"
ruby:
- "3.0"
- "3.1"
- "3.2"
- "3.3"
- "3.4"
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AllCops:
- local_test/*
- Steepfile

TargetRubyVersion: 3.0.0
TargetRubyVersion: 3.2
SuggestExtensions: false

Gemspec/DevelopmentDependencies:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ https://app.mindee.com
It uses **API version 2**.

Consult the
**[V2 Documentation](https://docs.mindee.com/integrations/client-libraries-sdk)**
**<a href="https://docs.mindee.com/integrations/client-libraries-sdk">V2 Documentation</a>**


### V1
Expand All @@ -26,17 +26,17 @@ https://platform.mindee.com/
It uses **API version 1**.

Consult the
[V1 Documentation](https://docs.mindee.com/v1/libraries/ruby-sdk)
<a href="https://docs.mindee.com/v1/libraries/ruby-sdk">V1 Documentation</a>

## Additional Information

**[Source Code](https://github.com/mindee/mindee-api-ruby)**
**<a href="https://github.com/mindee/mindee-api-ruby">Source Code</a>**

**[Reference Documentation](https://mindee.github.io/mindee-api-ruby/)**
**<a href="https://mindee.github.io/mindee-api-ruby/">Reference Documentation</a>**

**[Feedback](https://feedback.mindee.com/)**
**<a href="https://feedback.mindee.com/">Feedback</a>**

### License
Copyright © Mindee

Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.
2 changes: 1 addition & 1 deletion bin/v2/products.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
'ocr' => {
description: 'OCR Utility',
response_class: Mindee::V2::Product::Ocr::Ocr,
response_class: Mindee::V2::Product::OCR::OCR,
},
'split' => {
description: 'Split Utility',
Expand Down
2 changes: 1 addition & 1 deletion docs/code_samples/v2_ocr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ input_source = Mindee::Input::Source::PathInputSource.new(input_path)

# Send for processing
response = mindee_client.enqueue_and_get_result(
Mindee::V2::Product::Ocr::Ocr,
Mindee::V2::Product::OCR::OCR,
input_source,
ocr_params
)
Expand Down
8 changes: 8 additions & 0 deletions lib/mindee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ module Standard
module Universal
end
end

# V1-specific products.
module Product
# French products.
module FR
end
end
end

# V2-specific module.
Expand All @@ -94,6 +101,7 @@ module V2
module HTTP
end

# File operations.
module FileOperation
# Crop operations.
module Crop
Expand Down
4 changes: 2 additions & 2 deletions lib/mindee/geometry/polygon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Geometry
class Polygon < Array
# @param server_response [Hash] Raw server response hash.
def initialize(server_response)
points = []
points = [] # @type var points: Array[Mindee::Geometry::Point]
server_response.map do |point|
points << Point.new(point[0], point[1])
end
Expand All @@ -30,7 +30,7 @@ def point_in_y?(point)

# @return [String] Polygon as a string.
def to_s
"(#{map(&:to_s).join(', ')})"
"(#{join(', ')})"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mindee/image/image_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def self.extract_multiple_images_from_source(input_source, page_id, polygons)
# @param [Array<Geometry::Point, Geometry::Polygon, Geometry::Quadrilateral>] polygons
# @return [Array<Image::ExtractedImage>] Extracted Images.
def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygons)
extracted_elements = []
extracted_elements = [] # @type var extracted_elements: Array[Image::ExtractedImage]

polygons.each_with_index do |polygon, element_id|
polygon = ImageUtils.normalize_polygon(polygon)
Expand Down
3 changes: 3 additions & 0 deletions lib/mindee/input/base_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def slug
self.class.slug
end

# Load from a hash
# @param [Hash] params Parameters to provide as a hash.
# @return [BaseParameters]
def self.from_hash(params: {})
load_from_hash(params: params)
new(
Expand Down
2 changes: 1 addition & 1 deletion lib/mindee/input/sources/path_input_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PathInputSource < LocalInputSource
# @param filepath [String]
# @param repair_pdf [bool]
def initialize(filepath, repair_pdf: false)
io_stream = File.open(filepath, 'rb')
io_stream = File.new(filepath, 'rb')
super(io_stream, File.basename(filepath), repair_pdf: repair_pdf)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mindee/page_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PageOptions
attr_accessor :page_indexes, :operation, :on_min_pages

def initialize(params: {})
params ||= {}
params ||= {} # : Hash[Symbol, untyped]
params = params.transform_keys(&:to_sym)
@page_indexes = params.fetch(
:page_indexes,
Expand Down
12 changes: 9 additions & 3 deletions lib/mindee/pdf/extracted_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ class ExtractedPDF
# @return [String]
attr_reader :filename

# @param pdf_bytes [StringIO]
# @param pdf_stream [StringIO, File]
# @param filename [String]
def initialize(pdf_bytes, filename)
@pdf_bytes = pdf_bytes
def initialize(pdf_stream, filename)
@filename = filename

if pdf_stream.is_a?(File)
pdf_stream.rewind
@pdf_bytes = StringIO.new(pdf_stream.read)
else
@pdf_bytes = pdf_stream
end
end

# Retrieves the page count for a given pdf.
Expand Down
10 changes: 5 additions & 5 deletions lib/mindee/pdf/pdf_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def cut_pages(page_indexes)
# @param page_indexes [Array<Array<Integer>>] List of page number to use for merging in the original Pdf.
# @return [Array<Mindee::PDF::ExtractedPDF>] The buffer containing the new Pdf.
def extract_sub_documents(page_indexes)
extracted_pdfs = []
extracted_pdfs = [] # @type var extracted_pdfs: Array[Mindee::PDF::ExtractedPDF]
extension = File.extname(@filename)
basename = File.basename(@filename, extension)
page_indexes.each do |page_index_list|
Expand All @@ -54,7 +54,7 @@ def extract_sub_documents(page_indexes)
"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
formatted_max_index = format('%03d', page_index_list[-1] + 1).to_s
field_filename = "#{basename}_#{format('%03d',
page_index_list[0] + 1)}-#{formatted_max_index}#{extension}"
extracted_pdf = Mindee::PDF::ExtractedPDF.new(cut_pages(page_index_list),
Expand All @@ -74,15 +74,15 @@ def extract_sub_documents(page_indexes)
def extract_invoices(page_indexes, strict: false)
raise Error::MindeePDFError, 'No indexes provided.' if page_indexes.empty?

if page_indexes[0].is_a?(Array) && page_indexes[0].all? { |i| i.is_a?(Integer) }
if page_indexes[0].is_a?(Array) && page_indexes[0].all?(Integer)
page_indexes_as_array = page_indexes # @type var page_indexes : Array[Array[Integer]]
return extract_sub_documents(page_indexes_as_array)
end
p_ids = page_indexes # @type var page_indexes: Product::InvoiceSplitter::InvoiceSplitterV1InvoicePageGroups
return extract_sub_documents(p_ids.map(&:page_indexes)) unless strict

correct_page_indexes = []
current_list = []
correct_page_indexes = [] # @type var correct_page_indexes: Array[Array[Integer]]
current_list = [] # @type var current_list: Array[Integer]
previous_confidence = nil
p_ids.each_with_index do |p_i, i|
page_index = p_i # @type var page_index: Product::InvoiceSplitter::InvoiceSplitterV1InvoicePageGroup
Expand Down
1 change: 0 additions & 1 deletion lib/mindee/pdf/pdf_processor.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'set'
require 'origami'
require_relative 'pdf_tools'

Expand Down
2 changes: 1 addition & 1 deletion lib/mindee/v1/extraction/multi_receipts_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Extraction
# @param inference [Inference] Results of the inference.
# @return [Array<ExtractedImage>] Individual extracted receipts as an array of ExtractedMultiReceiptsImage.
def self.extract_receipts(input_source, inference)
images = []
images = [] # @type var images: Array[Image::ExtractedImage]
unless inference.prediction.receipts
raise Error::MindeeInputError,
'No possible receipts candidates found for Multi-Receipts extraction.'
Expand Down
2 changes: 1 addition & 1 deletion lib/mindee/v1/parsing/common/extras/cropper_extra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(raw_prediction, page_id = nil)

# @return [String]
def to_s
@croppings.map(&:to_s).join("\n ")
@croppings.join("\n ")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mindee/v1/parsing/common/inference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def to_s
out_str << "\n#{"#{@prediction}\n" if @prediction.to_s.size.positive?}"
if @pages.any? { |page| !page.prediction.nil? }
out_str << "\nPage Predictions\n================\n\n"
out_str << @pages.map(&:to_s).join("\n\n")
out_str << @pages.join("\n\n")
end
out_str.rstrip!
out_str
Expand Down
2 changes: 1 addition & 1 deletion lib/mindee/v1/parsing/common/ocr/ocr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Mindee
module V1
module Parsing
module Common
# Ocr-specific parsing fields and options
# OCR-specific parsing fields and options
module OCR
# A single word.
class OCRWord
Expand Down
10 changes: 5 additions & 5 deletions lib/mindee/v1/parsing/standard/company_registration_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ def initialize(prediction, page_id, reconstructed: false)
# @return [String] The formatted table line, as a string.
def to_table_line
printable = printable_values
format('| %<type>-15s | %<value>-20s ', type: printable['type'], value: printable['value'])
format('| %<type>-15s | %<value>-20s ', type: printable[:type], value: printable[:value])
end

# @return [String]
def to_s
printable = printable_values
format('Type: %<type>s, Value: %<value>s', type: printable['type'], value: printable['value'])
format('Type: %<type>s, Value: %<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
printable['value'] = value
printable = {} # @type var printable: Hash[Symbol, String]
printable[:type] = type
printable[:value] = value.to_s
printable
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mindee/v1/parsing/standard/tax_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def to_s

# @return [Hash]
def printable_values
out_h = {}
out_h = {} # @type var out_h: Hash[Symbol, String]
out_h[:code] = @code.nil? ? '' : @code
out_h[:base] = @base.nil? ? '' : print_float(@base)
out_h[:rate] = @rate.nil? ? '' : print_float(@rate).to_s
Expand Down
2 changes: 1 addition & 1 deletion lib/mindee/v1/parsing/universal/universal_list_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def contents_list

# Return a string representation of all values.
def contents_string(separator = ' ')
@values.map(&:to_s).join(separator)
@values.join(separator)
end

# String representation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module BarcodeReader
# Barcode Reader API version 1.0 document data.
class BarcodeReaderV1Document < Mindee::V1::Parsing::Common::Prediction
include Mindee::V1::Parsing::Standard

# List of decoded 1D barcodes.
# @return [Array<Mindee::V1::Parsing::Standard::StringField>]
attr_reader :codes_1d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module FinancialDocument
# Financial Document API version 1.14 document data.
class FinancialDocumentV1Document < Mindee::V1::Parsing::Common::Prediction
include Mindee::V1::Parsing::Standard

# The customer's address used for billing.
# @return [Mindee::V1::Parsing::Standard::AddressField]
attr_reader :billing_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module FinancialDocument
# List of line item present on the document.
class FinancialDocumentV1LineItem < Mindee::V1::Parsing::Standard::FeatureField
include Mindee::V1::Parsing::Standard

# The item description.
# @return [String]
attr_reader :description
Expand Down Expand Up @@ -51,7 +52,7 @@ def initialize(prediction, page_id)

# @return [Hash]
def printable_values
printable = {}
printable = {} # @type var printable: Hash[Symbol, String]
printable[:description] = format_for_display(@description)
printable[:product_code] = format_for_display(@product_code)
printable[:quantity] =
Expand All @@ -70,7 +71,7 @@ def printable_values

# @return [Hash]
def table_printable_values
printable = {}
printable = {} # @type var printable: Hash[Symbol, String]
printable[:description] = format_for_display(@description, 36)
printable[:product_code] = format_for_display(@product_code, nil)
printable[:quantity] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module BankAccountDetails
# Bank Account Details API version 1.0 document data.
class BankAccountDetailsV1Document < Mindee::V1::Parsing::Common::Prediction
include Mindee::V1::Parsing::Standard

# The name of the account holder as seen on the document.
# @return [Mindee::V1::Parsing::Standard::StringField]
attr_reader :account_holder_name
Expand Down
Loading
Loading