Skip to content

Commit 9fea2ab

Browse files
⬆️ 💥 drop support for ruby < 3.2 and bump dependency
1 parent 4e46724 commit 9fea2ab

79 files changed

Lines changed: 292 additions & 232 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ AllCops:
1010
- local_test/*
1111
- Steepfile
1212

13-
TargetRubyVersion: 3.0.0
13+
TargetRubyVersion: 3.2
1414
SuggestExtensions: false
1515

1616
Gemspec/DevelopmentDependencies:

lib/mindee/geometry/polygon.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Geometry
77
class Polygon < Array
88
# @param server_response [Hash] Raw server response hash.
99
def initialize(server_response)
10-
points = []
10+
points = [] # @type var points: Array[Mindee::Geometry::Point]
1111
server_response.map do |point|
1212
points << Point.new(point[0], point[1])
1313
end
@@ -30,7 +30,7 @@ def point_in_y?(point)
3030

3131
# @return [String] Polygon as a string.
3232
def to_s
33-
"(#{map(&:to_s).join(', ')})"
33+
"(#{join(', ')})"
3434
end
3535
end
3636
end

lib/mindee/image/image_extractor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def self.extract_multiple_images_from_source(input_source, page_id, polygons)
4747
# @param [Array<Geometry::Point, Geometry::Polygon, Geometry::Quadrilateral>] polygons
4848
# @return [Array<Image::ExtractedImage>] Extracted Images.
4949
def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygons)
50-
extracted_elements = []
50+
extracted_elements = [] # @type var extracted_elements: Array[Image::ExtractedImage]
5151

5252
polygons.each_with_index do |polygon, element_id|
5353
polygon = ImageUtils.normalize_polygon(polygon)

lib/mindee/input/sources/path_input_source.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class PathInputSource < LocalInputSource
1111
# @param filepath [String]
1212
# @param repair_pdf [bool]
1313
def initialize(filepath, repair_pdf: false)
14-
io_stream = File.open(filepath, 'rb')
14+
io_stream = File.new(filepath, 'rb')
1515
super(io_stream, File.basename(filepath), repair_pdf: repair_pdf)
1616
end
1717
end

lib/mindee/page_options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class PageOptions
1111
attr_accessor :page_indexes, :operation, :on_min_pages
1212

1313
def initialize(params: {})
14-
params ||= {}
14+
params ||= {} # : Hash[Symbol, untyped]
1515
params = params.transform_keys(&:to_sym)
1616
@page_indexes = params.fetch(
1717
:page_indexes,

lib/mindee/pdf/extracted_pdf.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ class ExtractedPDF
1313
# @return [String]
1414
attr_reader :filename
1515

16-
# @param pdf_bytes [StringIO]
16+
# @param pdf_stream [StringIO, File]
1717
# @param filename [String]
18-
def initialize(pdf_bytes, filename)
19-
@pdf_bytes = pdf_bytes
18+
def initialize(pdf_stream, filename)
2019
@filename = filename
20+
21+
if pdf_stream.is_a?(File)
22+
pdf_stream.rewind
23+
@pdf_bytes = StringIO.new(pdf_stream.read)
24+
else
25+
@pdf_bytes = pdf_stream
26+
end
2127
end
2228

2329
# Retrieves the page count for a given pdf.

lib/mindee/pdf/pdf_extractor.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def cut_pages(page_indexes)
4040
# @param page_indexes [Array<Array<Integer>>] List of page number to use for merging in the original Pdf.
4141
# @return [Array<Mindee::PDF::ExtractedPDF>] The buffer containing the new Pdf.
4242
def extract_sub_documents(page_indexes)
43-
extracted_pdfs = []
43+
extracted_pdfs = [] # @type var extracted_pdfs: Array[Mindee::PDF::ExtractedPDF]
4444
extension = File.extname(@filename)
4545
basename = File.basename(@filename, extension)
4646
page_indexes.each do |page_index_list|
@@ -54,7 +54,7 @@ def extract_sub_documents(page_indexes)
5454
"Index #{page_index} is out of range."
5555
end
5656
end
57-
formatted_max_index = format('%03d', page_index_list[page_index_list.length - 1] + 1).to_s
57+
formatted_max_index = format('%03d', page_index_list[-1] + 1).to_s
5858
field_filename = "#{basename}_#{format('%03d',
5959
page_index_list[0] + 1)}-#{formatted_max_index}#{extension}"
6060
extracted_pdf = Mindee::PDF::ExtractedPDF.new(cut_pages(page_index_list),
@@ -74,15 +74,15 @@ def extract_sub_documents(page_indexes)
7474
def extract_invoices(page_indexes, strict: false)
7575
raise Error::MindeePDFError, 'No indexes provided.' if page_indexes.empty?
7676

77-
if page_indexes[0].is_a?(Array) && page_indexes[0].all? { |i| i.is_a?(Integer) }
77+
if page_indexes[0].is_a?(Array) && page_indexes[0].all?(Integer)
7878
page_indexes_as_array = page_indexes # @type var page_indexes : Array[Array[Integer]]
7979
return extract_sub_documents(page_indexes_as_array)
8080
end
8181
p_ids = page_indexes # @type var page_indexes: Product::InvoiceSplitter::InvoiceSplitterV1InvoicePageGroups
8282
return extract_sub_documents(p_ids.map(&:page_indexes)) unless strict
8383

84-
correct_page_indexes = []
85-
current_list = []
84+
correct_page_indexes = [] # @type var correct_page_indexes: Array[Array[Integer]]
85+
current_list = [] # @type var current_list: Array[Integer]
8686
previous_confidence = nil
8787
p_ids.each_with_index do |p_i, i|
8888
page_index = p_i # @type var page_index: Product::InvoiceSplitter::InvoiceSplitterV1InvoicePageGroup

lib/mindee/pdf/pdf_processor.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
require 'set'
43
require 'origami'
54
require_relative 'pdf_tools'
65

lib/mindee/v1/extraction/multi_receipts_extractor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Extraction
1111
# @param inference [Inference] Results of the inference.
1212
# @return [Array<ExtractedImage>] Individual extracted receipts as an array of ExtractedMultiReceiptsImage.
1313
def self.extract_receipts(input_source, inference)
14-
images = []
14+
images = [] # @type var images: Array[Image::ExtractedImage]
1515
unless inference.prediction.receipts
1616
raise Error::MindeeInputError,
1717
'No possible receipts candidates found for Multi-Receipts extraction.'

lib/mindee/v1/parsing/common/extras/cropper_extra.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def initialize(raw_prediction, page_id = nil)
2222

2323
# @return [String]
2424
def to_s
25-
@croppings.map(&:to_s).join("\n ")
25+
@croppings.join("\n ")
2626
end
2727
end
2828
end

0 commit comments

Comments
 (0)