From 4919945c3dee0301e1d43048fbd271ee0d5936df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Thu, 2 Jul 2026 13:42:25 +0200 Subject: [PATCH] :bug: fix for extraction method naming --- lib/mindee/v2/product/crop/crop_item.rb | 2 +- lib/mindee/v2/product/crop/crop_response.rb | 8 -------- lib/mindee/v2/product/crop/crop_result.rb | 8 ++++++++ lib/mindee/v2/product/split/split_range.rb | 2 +- lib/mindee/v2/product/split/split_response.rb | 8 -------- lib/mindee/v2/product/split/split_result.rb | 8 ++++++++ sig/mindee/v2/product/crop/crop_item.rbs | 2 +- sig/mindee/v2/product/crop/crop_response.rbs | 2 -- sig/mindee/v2/product/crop/crop_result.rbs | 1 + sig/mindee/v2/product/split/split_range.rbs | 2 +- sig/mindee/v2/product/split/split_response.rbs | 2 -- sig/mindee/v2/product/split/split_result.rbs | 3 +++ spec/v2/file_operations/crop_operation_integration.rb | 7 +++++-- spec/v2/file_operations/split_operation_integration.rb | 2 +- spec/v2/file_operations/split_operation_spec.rb | 4 ++-- 15 files changed, 32 insertions(+), 29 deletions(-) diff --git a/lib/mindee/v2/product/crop/crop_item.rb b/lib/mindee/v2/product/crop/crop_item.rb index 71c427dc..a1b8dd7e 100644 --- a/lib/mindee/v2/product/crop/crop_item.rb +++ b/lib/mindee/v2/product/crop/crop_item.rb @@ -33,7 +33,7 @@ def to_s # # @param input_source [Mindee::Input::Source::LocalInputSource] Local file to extract from # @return [ExtractedImage] - def extract_from_file(input_source) + def extract_from_input_source(input_source) Image::ImageExtractor.extract_multiple_images_from_source( input_source, @location.page, [@location.polygon] )[0] diff --git a/lib/mindee/v2/product/crop/crop_response.rb b/lib/mindee/v2/product/crop/crop_response.rb index c862fefb..90ada724 100644 --- a/lib/mindee/v2/product/crop/crop_response.rb +++ b/lib/mindee/v2/product/crop/crop_response.rb @@ -25,14 +25,6 @@ def initialize(server_response) def to_s @inference.to_s end - - # Apply the crop inference to a file and return a list of extracted images. - # - # @param input_source [Mindee::Input::Source::LocalInputSource] Local file to extract from - # @return [Image::ExtractedImages] List of extracted images - def extract_from_file(input_source) - FileOperation::Crop.extract_crops(input_source, @inference.result.crops) - end end end end diff --git a/lib/mindee/v2/product/crop/crop_result.rb b/lib/mindee/v2/product/crop/crop_result.rb index 6f572fbe..cecab0db 100644 --- a/lib/mindee/v2/product/crop/crop_result.rb +++ b/lib/mindee/v2/product/crop/crop_result.rb @@ -20,6 +20,14 @@ def initialize(server_response) end end + # Apply the crop inference to a file and return a list of extracted images. + # + # @param input_source [Mindee::Input::Source::LocalInputSource] Local file to extract from + # @return [Image::ExtractedImages] List of extracted images + def extract_from_input_source(input_source) + FileOperation::Crop.extract_crops(input_source, @inference.result.crops) + end + # String representation. # @return [String] def to_s diff --git a/lib/mindee/v2/product/split/split_range.rb b/lib/mindee/v2/product/split/split_range.rb index a2bc09e8..2752334f 100644 --- a/lib/mindee/v2/product/split/split_range.rb +++ b/lib/mindee/v2/product/split/split_range.rb @@ -34,7 +34,7 @@ def to_s # # @param input_source [Mindee::Input::Source::LocalInputSource] Local file to extract from # @return [PDF::ExtractedPDF] - def extract_from_file(input_source) + def extract_from_input_source(input_source) FileOperation::Split.extract_single_split(input_source, @page_range) end end diff --git a/lib/mindee/v2/product/split/split_response.rb b/lib/mindee/v2/product/split/split_response.rb index 15436864..9fdafae1 100644 --- a/lib/mindee/v2/product/split/split_response.rb +++ b/lib/mindee/v2/product/split/split_response.rb @@ -25,14 +25,6 @@ def initialize(server_response) def to_s @inference.to_s end - - # Splits the input PDF. - # @param input_source [Mindee::Input::Source::LocalInputSource] Path to the file or a File object. - # @return [PDF::ExtractedPDFs] - def extract_from_file(input_source) - splits = @inference.result.splits.map(&:page_range) - FileOperation::Split.extract_splits(input_source, splits) - end end end end diff --git a/lib/mindee/v2/product/split/split_result.rb b/lib/mindee/v2/product/split/split_result.rb index b11d284b..59c7541f 100644 --- a/lib/mindee/v2/product/split/split_result.rb +++ b/lib/mindee/v2/product/split/split_result.rb @@ -20,6 +20,14 @@ def initialize(server_response) end end + # Splits the input PDF. + # @param input_source [Mindee::Input::Source::LocalInputSource] Path to the file or a File object. + # @return [PDF::ExtractedPDFs] + def extract_from_input_source(input_source) + splits = @inference.result.splits.map(&:page_range) + FileOperation::Split.extract_splits(input_source, splits) + end + # String representation. # @return [String] def to_s diff --git a/sig/mindee/v2/product/crop/crop_item.rbs b/sig/mindee/v2/product/crop/crop_item.rbs index d112ea96..c549561d 100644 --- a/sig/mindee/v2/product/crop/crop_item.rbs +++ b/sig/mindee/v2/product/crop/crop_item.rbs @@ -9,7 +9,7 @@ module Mindee def initialize: (Hash[String | Symbol, untyped]) -> void - def extract_from_file: (Input::Source::LocalInputSource) -> Image::ExtractedImage + def extract_from_input_source: (Input::Source::LocalInputSource) -> Image::ExtractedImage def to_s: -> String end diff --git a/sig/mindee/v2/product/crop/crop_response.rbs b/sig/mindee/v2/product/crop/crop_response.rbs index db6d970c..773045a9 100644 --- a/sig/mindee/v2/product/crop/crop_response.rbs +++ b/sig/mindee/v2/product/crop/crop_response.rbs @@ -13,8 +13,6 @@ module Mindee def _params_type: -> singleton(Params::CropParameters) - def extract_from_file: (Input::Source::LocalInputSource) -> Image::ExtractedImages - def to_s: -> String def self._params_type: () -> singleton(Params::CropParameters) def self.slug: () -> String diff --git a/sig/mindee/v2/product/crop/crop_result.rbs b/sig/mindee/v2/product/crop/crop_result.rbs index 67cd36e9..0e75de2b 100644 --- a/sig/mindee/v2/product/crop/crop_result.rbs +++ b/sig/mindee/v2/product/crop/crop_result.rbs @@ -6,6 +6,7 @@ module Mindee attr_reader crops: Array[CropItem] def initialize: (Hash[String | Symbol, untyped]) -> void + def extract_from_input_source: (Input::Source::LocalInputSource) -> Image::ExtractedImages def to_s: -> String end end diff --git a/sig/mindee/v2/product/split/split_range.rbs b/sig/mindee/v2/product/split/split_range.rbs index efde2842..7a870bb7 100644 --- a/sig/mindee/v2/product/split/split_range.rbs +++ b/sig/mindee/v2/product/split/split_range.rbs @@ -9,7 +9,7 @@ module Mindee def initialize: (Hash[String | Symbol, untyped]) -> void - def extract_from_file: (Input::Source::LocalInputSource) -> PDF::ExtractedPDF + def extract_from_input_source: (Input::Source::LocalInputSource) -> PDF::ExtractedPDF def to_s: -> String end diff --git a/sig/mindee/v2/product/split/split_response.rbs b/sig/mindee/v2/product/split/split_response.rbs index 7b702f3e..9a023251 100644 --- a/sig/mindee/v2/product/split/split_response.rbs +++ b/sig/mindee/v2/product/split/split_response.rbs @@ -13,8 +13,6 @@ module Mindee def _params_type: -> singleton(Params::SplitParameters) - def extract_from_file: (Mindee::Input::Source::LocalInputSource) -> PDF::ExtractedPDFs - def to_s: -> String def self._params_type: () -> singleton(Params::SplitParameters) def self.slug: () -> String diff --git a/sig/mindee/v2/product/split/split_result.rbs b/sig/mindee/v2/product/split/split_result.rbs index e1be3f6a..82a36445 100644 --- a/sig/mindee/v2/product/split/split_result.rbs +++ b/sig/mindee/v2/product/split/split_result.rbs @@ -5,7 +5,10 @@ module Mindee class SplitResult attr_reader splits: Array[SplitRange] + def extract_from_input_source: (Mindee::Input::Source::LocalInputSource) -> PDF::ExtractedPDFs + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String end end diff --git a/spec/v2/file_operations/crop_operation_integration.rb b/spec/v2/file_operations/crop_operation_integration.rb index 63ed1859..4a012997 100644 --- a/spec/v2/file_operations/crop_operation_integration.rb +++ b/spec/v2/file_operations/crop_operation_integration.rb @@ -3,8 +3,9 @@ require 'mindee' require 'mindee/v2/file_operations' require 'mindee/v2/product' +require 'fileutils' -describe Mindee::V2::FileOperation::Crop, :integration, :v2, :all_deps do +describe Mindee::V2::Product::Crop::Crop, :integration, :v2, :all_deps do let(:crop_sample) do File.join(V2_PRODUCT_DATA_DIR, 'crop', 'default_sample.jpg') end @@ -47,7 +48,7 @@ def check_findoc_return(findoc_response) expect(response.inference.result.crops.size).to eq(2) - extracted_images = described_class.extract_crops(crop_input, response.inference.result.crops) + extracted_images = response.inference.result.extract_from_input_source(crop_input) expect(extracted_images.size).to eq(2) expect(extracted_images[0].filename).to eq('default_sample.jpg_page0-0.jpg') @@ -67,5 +68,7 @@ def check_findoc_return(findoc_response) expect(File.size(File.join(OUTPUT_DIR, 'default_sample.jpg_page0-0.jpg'))).to be_between(560_000, 700_000) expect(File.size(File.join(OUTPUT_DIR, 'default_sample.jpg_page0-1.jpg'))).to be_between(580_000, 700_000) + ensure + crop_input.close if crop_input.respond_to?(:close) end end diff --git a/spec/v2/file_operations/split_operation_integration.rb b/spec/v2/file_operations/split_operation_integration.rb index 2b0163ed..1a2376a3 100644 --- a/spec/v2/file_operations/split_operation_integration.rb +++ b/spec/v2/file_operations/split_operation_integration.rb @@ -52,7 +52,7 @@ def check_findoc_return(findoc_response) expect(response.inference.file.page_count).to eq(2) - extracted_pdfs = response.extract_from_file(split_input) + extracted_pdfs = response.inference.result.extract_from_input_source(split_input) expect(extracted_pdfs.size).to eq(2) expect(extracted_pdfs[0].filename).to eq('default_sample_001-001.pdf') diff --git a/spec/v2/file_operations/split_operation_spec.rb b/spec/v2/file_operations/split_operation_spec.rb index 49b230a7..d92371eb 100644 --- a/spec/v2/file_operations/split_operation_spec.rb +++ b/spec/v2/file_operations/split_operation_spec.rb @@ -26,7 +26,7 @@ response_hash = JSON.parse(File.read(splits_single_page_json_path)) doc = described_class.new(response_hash) - extracted_splits = doc.extract_from_file(input_sample) + extracted_splits = doc.extract_from_input_source(input_sample) expect(extracted_splits).to be_a(Mindee::PDF::ExtractedPDFs) expect(extracted_splits.size).to eq(1) @@ -39,7 +39,7 @@ response_hash = JSON.parse(File.read(splits_multi_page_json_path)) doc = described_class.new(response_hash) - extracted_splits = doc.extract_from_file(input_sample) + extracted_splits = doc.extract_from_input_source(input_sample) expect(extracted_splits).to be_a(Mindee::PDF::ExtractedPDFs) expect(extracted_splits.size).to eq(3)