From 339cdd0036cfc752564283b3787663725456ca93 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 30 Jul 2025 16:22:04 +0200 Subject: [PATCH 01/19] add preliminary deserialization classes --- lib/mindee/parsing/v2.rb | 0 lib/mindee/parsing/v2/common_response.rb | 18 ++++ lib/mindee/parsing/v2/error_response.rb | 27 +++++ lib/mindee/parsing/v2/field.rb | 0 lib/mindee/parsing/v2/field/base_field.rb | 52 +++++++++ lib/mindee/parsing/v2/field/dynamic_field.rb | 28 +++++ .../parsing/v2/field/field_confidence.rb | 92 ++++++++++++++++ lib/mindee/parsing/v2/field/field_location.rb | 36 +++++++ .../parsing/v2/field/inference_fields.rb | 88 +++++++++++++++ lib/mindee/parsing/v2/field/list_field.rb | 90 ++++++++++++++++ lib/mindee/parsing/v2/field/object_field.rb | 102 ++++++++++++++++++ lib/mindee/parsing/v2/field/simple_field.rb | 59 ++++++++++ lib/mindee/parsing/v2/inference.rb | 54 ++++++++++ lib/mindee/parsing/v2/inference_file.rb | 38 +++++++ lib/mindee/parsing/v2/inference_model.rb | 18 ++++ lib/mindee/parsing/v2/inference_response.rb | 31 ++++++ lib/mindee/parsing/v2/inference_result.rb | 50 +++++++++ .../parsing/v2/inference_result_options.rb | 21 ++++ lib/mindee/parsing/v2/job.rb | 82 ++++++++++++++ lib/mindee/parsing/v2/job_response.rb | 31 ++++++ lib/mindee/parsing/v2/job_webhook.rb | 60 +++++++++++ lib/mindee/parsing/v2/raw_text.rb | 21 ++++ sig/mindee/http/workflow_endpoint.rbs | 2 +- sig/mindee/parsing/common/api_request.rbs | 12 +-- sig/mindee/parsing/common/api_response.rbs | 2 +- .../parsing/common/workflow_response.rbs | 12 ++- spec/data | 2 +- 27 files changed, 1015 insertions(+), 13 deletions(-) create mode 100644 lib/mindee/parsing/v2.rb create mode 100644 lib/mindee/parsing/v2/common_response.rb create mode 100644 lib/mindee/parsing/v2/error_response.rb create mode 100644 lib/mindee/parsing/v2/field.rb create mode 100644 lib/mindee/parsing/v2/field/base_field.rb create mode 100644 lib/mindee/parsing/v2/field/dynamic_field.rb create mode 100644 lib/mindee/parsing/v2/field/field_confidence.rb create mode 100644 lib/mindee/parsing/v2/field/field_location.rb create mode 100644 lib/mindee/parsing/v2/field/inference_fields.rb create mode 100644 lib/mindee/parsing/v2/field/list_field.rb create mode 100644 lib/mindee/parsing/v2/field/object_field.rb create mode 100644 lib/mindee/parsing/v2/field/simple_field.rb create mode 100644 lib/mindee/parsing/v2/inference.rb create mode 100644 lib/mindee/parsing/v2/inference_file.rb create mode 100644 lib/mindee/parsing/v2/inference_model.rb create mode 100644 lib/mindee/parsing/v2/inference_response.rb create mode 100644 lib/mindee/parsing/v2/inference_result.rb create mode 100644 lib/mindee/parsing/v2/inference_result_options.rb create mode 100644 lib/mindee/parsing/v2/job.rb create mode 100644 lib/mindee/parsing/v2/job_response.rb create mode 100644 lib/mindee/parsing/v2/job_webhook.rb create mode 100644 lib/mindee/parsing/v2/raw_text.rb diff --git a/lib/mindee/parsing/v2.rb b/lib/mindee/parsing/v2.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/mindee/parsing/v2/common_response.rb b/lib/mindee/parsing/v2/common_response.rb new file mode 100644 index 000000000..70053d1ae --- /dev/null +++ b/lib/mindee/parsing/v2/common_response.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module V2 + # Base class for inference and job responses on the V2 API. + class CommonResponse + # @return [String] + attr_reader :raw_http + + # @param http_response [Hash] + def initialize(http_response) + @raw_http = http_response + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/error_response.rb b/lib/mindee/parsing/v2/error_response.rb new file mode 100644 index 000000000..dd12faf46 --- /dev/null +++ b/lib/mindee/parsing/v2/error_response.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module V2 + # Encapsulates information returned by the API when an error occurs. + class ErrorResponse + # @return [Integer] HTTP status code. + attr_reader :status + # @return [String] Error detail. + attr_reader :detail + + # @param server_response [Hash] Raw JSON parsed into a Hash. + def initialize(server_response) + @status = server_response['status'] + @detail = server_response['detail'] + end + + # String representation, useful when embedding in larger objects. + # @return [String] + def to_s + "Error\n=====\n:Status: #{@status}\n:Detail: #{@detail}" + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/field.rb b/lib/mindee/parsing/v2/field.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/mindee/parsing/v2/field/base_field.rb b/lib/mindee/parsing/v2/field/base_field.rb new file mode 100644 index 000000000..d0bd97c56 --- /dev/null +++ b/lib/mindee/parsing/v2/field/base_field.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module V2 + module Field + # Base class for V2 fields. + class BaseField + # @return [Integer] Level of indentation for rst display. + attr_reader :indent_level + + # @return [FieldConfidence, nil] Confidence score for the field. + attr_accessor :confidence + + # @param raw_prediction [Hash] Raw prediction hash. + # @param indent_level [Integer] Level of indentation for rst display. + def initialize(raw_prediction, indent_level = 0) + @indent_level = indent_level + @confidence = nil + + # Process confidence if present + @confidence = raw_prediction['confidence'] if raw_prediction.key?('confidence') + end + + # Factory method to create appropriate field types. + # @param raw_prediction [Hash] Raw prediction hash. + # @param indent_level [Integer] Level of indentation for rst display. + # @return [BaseField] Appropriate field instance. + # @raise [MindeeError] If the field type isn't recognized. + def self.create_field(raw_prediction, indent_level = 0) + if raw_prediction.key?('items') + require_relative 'list_field' + return ListField.new(raw_prediction, indent_level) + end + + if raw_prediction.key?('fields') + require_relative 'object_field' + return ObjectField.new(raw_prediction, indent_level) + end + + if raw_prediction.key?('value') + require_relative 'simple_field' + return SimpleField.new(raw_prediction, indent_level) + end + + raise MindeeError, "Unrecognized field format in #{raw_prediction.to_json}" + end + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/field/dynamic_field.rb b/lib/mindee/parsing/v2/field/dynamic_field.rb new file mode 100644 index 000000000..155457e64 --- /dev/null +++ b/lib/mindee/parsing/v2/field/dynamic_field.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module V2 + module Field + # Extension of the base field class for V2 fields, with location data. + class DynamicField < BaseField + # @return [Array, nil] List of possible locations for a field. + attr_accessor :locations + + # @param raw_prediction [Hash] Raw prediction hash. + # @param indent_level [Integer] Level of indentation for rst display. + def initialize(raw_prediction, indent_level = 0) + super + + # Process locations if present + return unless raw_prediction['locations'] + + @locations = raw_prediction['locations'].map do |location| + location ? FieldLocation.new(location) : nil + end.compact + end + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/field/field_confidence.rb b/lib/mindee/parsing/v2/field/field_confidence.rb new file mode 100644 index 000000000..d93d7b0dd --- /dev/null +++ b/lib/mindee/parsing/v2/field/field_confidence.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module V2 + module Field + # Confidence level of a field as returned by the V2 API. + class FieldConfidence + # @return [String] The confidence level value. + attr_reader :value + + CERTAIN = 'Certain' + HIGH = 'High' + MEDIUM = 'Medium' + LOW = 'Low' + + VALID_VALUES = [CERTAIN, HIGH, MEDIUM, LOW].freeze + + # @param value [String] The confidence level value. + # @raise [ArgumentError] If the value is not a valid confidence level. + def initialize(value) + unless VALID_VALUES.include?(value) + raise ArgumentError, + "Invalid confidence level: #{value}. Must be one of: #{VALID_VALUES.join(', ')}" + end + + @value = value + end + + # Create a FieldConfidence from a string value. + # @param value [String] The confidence level string. + # @return [FieldConfidence] The confidence instance. + def self.from_string(value) + new(value) + end + + # Check if this is a certain confidence level. + # @return [Boolean] True if confidence is certain. + def certain? + @value == CERTAIN + end + + # Check if this is a high confidence level. + # @return [Boolean] True if confidence is high. + def high? + @value == HIGH + end + + # Check if this is a medium confidence level. + # @return [Boolean] True if confidence is medium. + def medium? + @value == MEDIUM + end + + # Check if this is a low confidence level. + # @return [Boolean] True if confidence is low. + def low? + @value == LOW + end + + # String representation of the confidence level. + # @return [String] The confidence level value. + def to_s + @value + end + + # Compare two FieldConfidence instances. + # @param other [FieldConfidence] The other confidence to compare. + # @return [Boolean] True if they have the same value. + def ==(other) + other.is_a?(FieldConfidence) && @value == other.value + end + + # Hash code for the confidence level. + # @return [Integer] Hash code based on the value. + def hash + @value.hash + end + + # Make instances comparable and hashable + alias eql? == + + # Inspect method for debugging. + # @return [String] Debug representation. + def inspect + "#<#{self.class.name}:#{@value}>" + end + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/field/field_location.rb b/lib/mindee/parsing/v2/field/field_location.rb new file mode 100644 index 000000000..b45f5a084 --- /dev/null +++ b/lib/mindee/parsing/v2/field/field_location.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require_relative '../../../geometry/polygon' + +module Mindee + module Parsing + module V2 + module Field + # Location of a field. + class FieldLocation + # @return [Mindee::Geometry::Polygon, nil] Polygon corresponding to the field location. + attr_reader :polygon + + # @return [Integer, nil] Page on which the field is located. + attr_reader :page + + # @param server_response [Hash] Raw server response hash. + def initialize(server_response) + polygon_data = server_response['polygon'] || server_response[:polygon] + @polygon = polygon_data ? Mindee::Geometry::Polygon.new(polygon_data) : nil + + page_id = server_response['page'] || server_response[:page] + @page = page_id.is_a?(Numeric) ? page_id.to_i : nil + end + + # String representation of the polygon (empty string when none). + # + # @return [String] + def to_s + @polygon ? @polygon.to_s : '' + end + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/field/inference_fields.rb b/lib/mindee/parsing/v2/field/inference_fields.rb new file mode 100644 index 000000000..9d2169286 --- /dev/null +++ b/lib/mindee/parsing/v2/field/inference_fields.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +require_relative 'base_field' + +module Mindee + module Parsing + module V2 + module Field + # Collection of inference fields that extends Hash functionality. + class InferenceFields < Hash + # @return [Integer] Level of indentation for rst display. + attr_reader :indent_level + + # @param server_response [Hash] Raw server response hash. + # @param indent_level [Integer] Level of indentation for rst display. + def initialize(server_response, indent_level = 0) + super() + @indent_level = indent_level + + server_response.each do |key, value| + self[key] = BaseField.create_field(value, 1) + end + end + + # Get a field by key with nil fallback. + # @param key [String] Field key to retrieve. + # @return [BaseField, nil] The field or nil if not found. + def get(key) + self[key] + end + + # Allow dot notation access to fields. + # @param method_name [Symbol] The method name (field key). + # @return [BaseField, nil] The field or nil if not found. + def method_missing(method_name, *args, &block) + key = method_name.to_s + if key?(key) + self[key] + else + super + end + end + + # Check if method_missing should handle the method. + # @param method_name [Symbol] The method name. + # @return [Boolean] True if the method should be handled. + def respond_to_missing?(method_name, include_private = false) + key?(method_name.to_s) || super + end + + # Convert the fields to a string representation. + # @param indent [Integer, nil] Optional indentation level. + # @return [String] String representation of all fields. + def to_s(indent = nil) + return '' if empty? + + indent ||= @indent_level + padding = ' ' * indent + lines = [] + + each do |field_key, field_value| + line = "#{padding}:#{field_key}:" + + case field_value.class.name.split('::').last + when 'ListField' + # Check if ListField has items and they're not empty + if defined?(field_value.items) && field_value.items && !field_value.items.empty? + line += field_value.to_s + end + when 'ObjectField' + line += field_value.to_s + when 'SimpleField' + # Check if SimpleField has a non-empty value + if defined?(field_value.value) && field_value.value && !field_value.value.to_s.empty? + line += " #{field_value.value}" + end + end + + lines << line + end + + lines.join("\n").rstrip + end + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/field/list_field.rb b/lib/mindee/parsing/v2/field/list_field.rb new file mode 100644 index 000000000..34dea3e3d --- /dev/null +++ b/lib/mindee/parsing/v2/field/list_field.rb @@ -0,0 +1,90 @@ +# frozen_string_literal: true + +require_relative 'base_field' + +module Mindee + module Parsing + module V2 + module Field + # A field containing a list of other fields. + class ListField < BaseField + # @return [Array] Items contained in the list. + attr_reader :items + + # @param server_response [Hash] Raw server response hash. + # @param indent_level [Integer] Level of indentation for rst display. + # @raise [MindeeError] If the 'items' key is missing or not an array. + def initialize(server_response, indent_level = 0) + super + + unless server_response.key?('items') && server_response['items'].is_a?(Array) + raise MindeeError, + "Expected \"items\" to be an array in #{server_response.to_json}." + end + + @items = [] + server_response['items'].each do |item| + @items << BaseField.create_field(item, indent_level + 1) + end + end + + # String representation of the list field. + # @return [String] Formatted string with bullet points for each item. + def to_s + return "\n" if @items.empty? + + parts = [''] + @items.each do |item| + next unless item + + parts << if item.is_a?(ObjectField) + item.to_s_from_list + else + item.to_s + end + end + + parts.join("\n * ") + end + + # Check if the list is empty. + # @return [Boolean] True if the list has no items. + def empty? + @items.empty? + end + + # Get the number of items in the list. + # @return [Integer] Number of items. + def size + @items.size + end + + # Get the number of items in the list (alias for size). + # @return [Integer] Number of items. + def length + @items.length + end + + # Iterate over the items in the list. + # @yield [BaseField] Each item in the list. + # @return [Enumerator] If no block is given. + def each(&block) + return @items.to_enum unless block_given? + + @items.each(&block) + end + + # Get an item by index. + # @param index [Integer] The index of the item to retrieve. + # @return [BaseField, nil] The item at the given index. + def [](index) + @items[index] + end + + # Array-like access methods + include Enumerable + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/field/object_field.rb b/lib/mindee/parsing/v2/field/object_field.rb new file mode 100644 index 000000000..7f290e4df --- /dev/null +++ b/lib/mindee/parsing/v2/field/object_field.rb @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +require_relative 'base_field' +require_relative 'inference_fields' + +module Mindee + module Parsing + module V2 + module Field + # A field containing a nested set of inference fields. + class ObjectField < DynamicField + # @return [InferenceFields] Fields contained in the object. + attr_reader :fields + + # @param server_response [Hash] Raw server response hash. + # @param indent_level [Integer] Level of indentation for rst display. + def initialize(server_response, indent_level = 0) + super + + inner_fields = server_response.fetch('fields', server_response) + @fields = InferenceFields.new(inner_fields, @indent_level + 1) + end + + # String representation of the object field. + # @return [String] String representation with newline prefix. + def to_s + return "\n" unless @fields && !@fields.empty? + + "\n#{@fields.to_s(1)}" + end + + # String representation suitable for list display. + # @return [String] String representation without leading spaces. + def to_s_from_list + return '' unless @fields && !@fields.empty? + + field_str = @fields.to_s(2) + # Remove the first 4 characters + field_str.length > 4 ? field_str[4..] : '' + end + + # String representation of a single object field + # @return [String] Multi-line string with proper indentation. + def single_str + return '' unless @fields && !@fields.empty? + + out_str = '' + indent = ' ' * @indent_level + + @fields.each do |field_key, field_value| + value_str = field_value && !field_value.to_s.empty? ? field_value.to_s : '' + out_str += "\n#{indent} :#{field_key}: #{value_str}" + end + + out_str + end + + # String representation for multi-object display + # @return [String] Formatted string for list context. + def multi_str + return '' unless @fields && !@fields.empty? + + out_str = '' + indent = ' ' * @indent_level + first = true + + @fields.each do |field_key, field_value| + value_str = field_value ? field_value.to_s : '' + + if first + out_str += "#{indent}:#{field_key}: #{value_str}" + first = false + else + out_str += "\n#{indent} :#{field_key}: #{value_str}" + end + end + + out_str + end + + # Allow dot notation access to nested fields. + # @param method_name [Symbol] The method name (field key). + # @return [BaseField, nil] The field or nil if not found. + def method_missing(method_name, ...) + if @fields.respond_to?(method_name) + @fields.send(method_name, ...) + else + super + end + end + + # Check if method_missing should handle the method. + # @param method_name [Symbol] The method name. + # @return [Boolean] True if the method should be handled. + def respond_to_missing?(method_name, include_private = false) + @fields.respond_to?(method_name) || super + end + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/field/simple_field.rb b/lib/mindee/parsing/v2/field/simple_field.rb new file mode 100644 index 000000000..42429482b --- /dev/null +++ b/lib/mindee/parsing/v2/field/simple_field.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require_relative 'base_field' + +module Mindee + module Parsing + module V2 + module Field + # A simple field with a scalar value. + class SimpleField < DynamicField + # @return [String, Integer, Float, Boolean, nil] Value contained in the field. + attr_accessor :value + + # @param server_response [Hash] Raw server response hash. + # @param indent_level [Integer] Level of indentation for rst display. + def initialize(server_response, indent_level = 0) + super + @value = server_response.key?('value') ? server_response['value'] : nil + end + + # String representation of the field value. + # @return [String] String representation of the value. + def to_s + return '' if @value.nil? + + case @value + when TrueClass + 'True' + when FalseClass + 'False' + when Numeric + format_numeric_value(@value) + else + @value.to_s + end + end + + private + + # Format numeric values according to the PHP implementation logic. + # @param value [Numeric] The numeric value to format. + # @return [String] Formatted numeric string. + def format_numeric_value(value) + float_value = value.to_f + + # If it's effectively an integer, show with .0 + if float_value == float_value.to_i + format('%.1f', float_value) + else + # Format with up to 5 decimal places, removing trailing zeros + formatted = format('%.5f', float_value) + formatted.sub(%r{\.?0+$}, '') + end + end + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/inference.rb b/lib/mindee/parsing/v2/inference.rb new file mode 100644 index 000000000..f7666d846 --- /dev/null +++ b/lib/mindee/parsing/v2/inference.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require_relative 'inference_model' +require_relative 'inference_file' +require_relative 'inference_result' + +module Mindee + module Parsing + module V2 + # Complete data returned by an inference request: + # • model information + # • file information + # • inference result (fields, options, …) + class Inference + # @return [InferenceModel] Information about the model used. + attr_reader :model + # @return [InferenceFile] Information about the processed file. + attr_reader :file + # @return [InferenceResult] Result contents. + attr_reader :result + # @return [String, nil] Identifier of the inference (when provided by API). + attr_reader :id + + # @param server_response [Hash] Hash representation of the JSON returned by the service. + def initialize(server_response) + raise ArgumentError, 'server_response must be a Hash' unless server_response.is_a?(Hash) + + @model = InferenceModel.new(server_response['model']) + @file = InferenceFile.new(server_response['file']) + @result = InferenceResult.new(server_response['result']) + + @id = server_response['id'] if server_response.key?('id') + end + + # RST-style string representation (keeps parity with TS implementation). + # + # @return [String] + def to_s + [ + 'Inference', + '#########', + 'Model', + '=====', + ":ID: #{@model.id}", + '', + @file.to_s, + @result.to_s, + '', + ].join("\n") + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/inference_file.rb b/lib/mindee/parsing/v2/inference_file.rb new file mode 100644 index 000000000..d7f27aefd --- /dev/null +++ b/lib/mindee/parsing/v2/inference_file.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module V2 + # Information about a file returned in an inference. + class InferenceFile + # @return [String] File name. + attr_reader :name + # @return [String, nil] Optional alias for the file. + attr_reader :file_alias + # @return [Integer] Page count. + attr_reader :page_count + # @return [String] MIME type. + attr_reader :mime_type + + # @param server_response [Hash] Raw JSON parsed into a Hash. + def initialize(server_response) + @name = server_response['name'] + @file_alias = server_response['alias'] + @page_count = server_response['page_count'] + @mime_type = server_response['mime_type'] + end + + # RST-style string representation. + # @return [String] + def to_s + "File\n" \ + "====\n" \ + ":Name: #{@name}\n" \ + ":Alias:#{" #{@file_alias}" if @file_alias}\n" \ + ":Page Count: #{@page_count}\n" \ + ":MIME Type: #{@mime_type}" + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/inference_model.rb b/lib/mindee/parsing/v2/inference_model.rb new file mode 100644 index 000000000..1ee1af2be --- /dev/null +++ b/lib/mindee/parsing/v2/inference_model.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module V2 + # ID of the model that produced the inference. + class InferenceModel + # @return [String] Identifier of the model. + attr_reader :id + + # @param server_response [Hash] Raw JSON parsed into a Hash. + def initialize(server_response) + @id = server_response['id'] + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/inference_response.rb b/lib/mindee/parsing/v2/inference_response.rb new file mode 100644 index 000000000..70ee98554 --- /dev/null +++ b/lib/mindee/parsing/v2/inference_response.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require_relative 'common_response' +require_relative 'inference' + +module Mindee + module Parsing + module V2 + # HTTP response wrapper that embeds a V2 Inference. + class InferenceResponse < CommonResponse + # @return [Inference] Parsed inference payload. + attr_reader :inference + + # @param server_response [Hash] Hash parsed from the API JSON response. + def initialize(server_response) + # CommonResponse takes care of the generic metadata (status, etc.) + super + + @inference = Inference.new(server_response['inference']) + end + + # Delegates to CommonResponse's string representation and appends the inference details. + # + # @return [String] + def to_s + @inference.to_s + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/inference_result.rb b/lib/mindee/parsing/v2/inference_result.rb new file mode 100644 index 000000000..500f97c95 --- /dev/null +++ b/lib/mindee/parsing/v2/inference_result.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require_relative 'field/inference_fields' +require_relative 'inference_result_options' + +module Mindee + module Parsing + module V2 + # Wrapper for the result of a V2 inference request. + class InferenceResult + # @return [Mindee::Parsing::V2::Field::InferenceFields] Fields produced by the model. + attr_reader :fields + # @return [Mindee::Parsing::V2::InferenceResultOptions, nil] Optional extra data. + attr_reader :options + + # @param server_response [Hash] Hash version of the JSON returned by the API. + def initialize(server_response) + raise ArgumentError, 'server_response must be a Hash' unless server_response.is_a?(Hash) + + @fields = Field::InferenceFields.new(server_response['fields']) + + return unless server_response.key?('options') && server_response['options'] + + @options = InferenceResultOptions.new(server_response['options']) + end + + # RST-style string representation. + # + # @return [String] + def to_s + parts = [ + 'Fields', + '======', + @fields.to_s, + ] + + if @options + parts += [ + 'Options', + '=======', + @options.to_s, + ] + end + + parts.join("\n") + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/inference_result_options.rb b/lib/mindee/parsing/v2/inference_result_options.rb new file mode 100644 index 000000000..ba903e7c8 --- /dev/null +++ b/lib/mindee/parsing/v2/inference_result_options.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require_relative 'raw_text' + +module Mindee + module Parsing + module V2 + # Optional data returned alongside an inference. + class InferenceResultOptions + # @return [Array] Collection of raw texts per page. + attr_reader :raw_texts + + # @param server_response [Hash] Raw JSON parsed into a Hash. + def initialize(server_response) + raw = server_response['raw_texts'] + @raw_texts = raw.is_a?(Array) ? raw.map { |rt| RawText.new(rt) } : [] + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/job.rb b/lib/mindee/parsing/v2/job.rb new file mode 100644 index 000000000..c0c74de80 --- /dev/null +++ b/lib/mindee/parsing/v2/job.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +require 'date' +require_relative 'error_response' +require_relative 'job_webhook' + +module Mindee + module Parsing + module V2 + # Metadata returned when polling a job (asynchronous request). + class Job + # @return [String] Unique job identifier. + attr_reader :id + # @return [DateTime, nil] Timestamp of creation. + attr_reader :created_at + # @return [String] Identifier of the model used. + attr_reader :model_id + # @return [String] Name of the processed file. + attr_reader :filename + # @return [String] Optional alias for the file. + attr_reader :alias + # @return [String, nil] Current status (submitted, processing, done, …). + attr_reader :status + # @return [String] URL to query for updated status. + attr_reader :polling_url + # @return [String, nil] URL that redirects to the final result once ready. + attr_reader :result_url + # @return [Array] Webhooks triggered by the job. + attr_reader :webhooks + # @return [ErrorResponse, nil] Error details when the job failed. + attr_reader :error + + # @param server_response [Hash] Parsed JSON payload from the API. + def initialize(server_response) + raise ArgumentError, 'server_response must be a Hash' unless server_response.is_a?(Hash) + + @id = server_response['id'] + @status = server_response['status'] if server_response.key?('status') + @error = build_error(server_response['error']) + @created_at = Time.iso8601(server_response['created_at']) + @model_id = server_response['model_id'] + @polling_url = server_response['polling_url'] + @filename = server_response['filename'] + @result_url = server_response['result_url'] + @alias = server_response['alias'] + @webhooks = JobWebhook.new(server_response['webhooks']) + end + + # RST-style string representation, useful for debugging or logs. + # + # @return [String] + def to_s + lines = [ + 'Job', + '###', + ":ID: #{@id}", + ":CreatedAt: #{@created_at}", + ":ModelID: #{@model_id}", + ":Filename: #{@filename}", + ":Alias: #{@alias}", + ":Status: #{@status}", + ":PollingURL: #{@polling_url}", + ":ResultURL: #{@result_url}", + ] + + lines << @error.to_s if @error + + unless @webhooks.empty? + lines += [ + '', + 'Webhooks', + '=========', + @webhooks.map(&:to_s).join("\n\n"), + ] + end + + lines.join("\n") + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/job_response.rb b/lib/mindee/parsing/v2/job_response.rb new file mode 100644 index 000000000..16ed070ee --- /dev/null +++ b/lib/mindee/parsing/v2/job_response.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require_relative 'common_response' +require_relative 'job' + +module Mindee + module Parsing + module V2 + # HTTP response wrapper that embeds a V2 job. + class JobResponse < CommonResponse + # @return [Job] Parsed job payload. + attr_reader :job + + # @param server_response [Hash] Hash parsed from the API JSON response. + def initialize(server_response) + # CommonResponse takes care of the generic metadata (status, etc.) + super + + @job = Job.new(server_response['job']) + end + + # Delegates to CommonResponse's string representation and appends the job details. + # + # @return [String] + def to_s + @job.to_s + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/job_webhook.rb b/lib/mindee/parsing/v2/job_webhook.rb new file mode 100644 index 000000000..c9e1e0007 --- /dev/null +++ b/lib/mindee/parsing/v2/job_webhook.rb @@ -0,0 +1,60 @@ +# lib/mindee/parsing/v2/job_response_webhook.rb +# frozen_string_literal: true + +require 'date' +require_relative 'error_response' + +module Mindee + module Parsing + module V2 + # Information about a webhook created for a job response. + class JobWebhook + # @return [String] Identifier of the webhook. + attr_reader :id + # @return [DateTime, nil] Creation timestamp (or +nil+ when absent). + attr_reader :created_at + # @return [String] Webhook status. + attr_reader :status + # @return [ErrorResponse, nil] Error information when something failed. + attr_reader :error + + # @param server_response [Hash] Raw JSON parsed into a Hash. + def initialize(server_response) + @id = server_response['id'] + @created_at = parse_date(server_response['created_at']) + @status = server_response['status'] + @error = ErrorResponse.new(server_response['error']) if server_response.key?('error') + end + + # RST display. + # + # @return [String] + def to_s + parts = [ + 'JobResponseWebhook', + '##################', + ":ID: #{@id}", + ":CreatedAt: #{@created_at}", + ":Status: #{@status}", + ] + + parts << @error.to_s if @error + parts.join("\n") + end + + private + + # Safely parse an ISO-8601 date/time string to DateTime. + # @param str [String, nil] The date string. + # @return [DateTime, nil] + def parse_date(str) + return nil if str.to_s.empty? + + DateTime.iso8601(str) + rescue ArgumentError + nil + end + end + end + end +end diff --git a/lib/mindee/parsing/v2/raw_text.rb b/lib/mindee/parsing/v2/raw_text.rb new file mode 100644 index 000000000..0aac358f5 --- /dev/null +++ b/lib/mindee/parsing/v2/raw_text.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Mindee + module Parsing + module V2 + # Raw text extracted from a given page. + class RawText + # @return [Integer] Page number where the text was found. + attr_reader :page + # @return [String] Text content. + attr_reader :content + + # @param server_response [Hash] Raw JSON parsed into a Hash. + def initialize(server_response) + @page = server_response['page'] + @content = server_response['content'] + end + end + end + end +end diff --git a/sig/mindee/http/workflow_endpoint.rbs b/sig/mindee/http/workflow_endpoint.rbs index 89a609d89..6795f44f2 100644 --- a/sig/mindee/http/workflow_endpoint.rbs +++ b/sig/mindee/http/workflow_endpoint.rbs @@ -10,7 +10,7 @@ module Mindee def initialize: (untyped, ?api_key: String) -> String - def execute_workflow: (Input::Source::LocalInputSource | Input::Source::URLInputSource, WorkflowOptions) -> [untyped, untyped] + def execute_workflow: (Input::Source::LocalInputSource | Input::Source::URLInputSource, WorkflowOptions) -> [Hash[String, untyped], String] def workflow_execution_req_post: (Input::Source::LocalInputSource | Input::Source::URLInputSource, WorkflowOptions) -> Net::HTTPResponse? diff --git a/sig/mindee/parsing/common/api_request.rbs b/sig/mindee/parsing/common/api_request.rbs index 94bfebd0b..4f5e652be 100644 --- a/sig/mindee/parsing/common/api_request.rbs +++ b/sig/mindee/parsing/common/api_request.rbs @@ -3,12 +3,12 @@ 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 + def error: -> Hash[String, untyped] + def ressources: -> Array[String] + def status: -> [RequestStatus, Symbol] + def status_code: -> Integer + def url: -> String + def initialize: (Hash[String, untyped]) -> void end end end diff --git a/sig/mindee/parsing/common/api_response.rbs b/sig/mindee/parsing/common/api_response.rbs index 8cd595fbf..6c3decc57 100644 --- a/sig/mindee/parsing/common/api_response.rbs +++ b/sig/mindee/parsing/common/api_response.rbs @@ -15,7 +15,7 @@ module Mindee class ApiResponse - def logger: () -> untyped + def logger: () -> Logger def document: -> Parsing::Common::Document? def job: -> Parsing::Common::Job? def api_request: -> Parsing::Common::ApiRequest? diff --git a/sig/mindee/parsing/common/workflow_response.rbs b/sig/mindee/parsing/common/workflow_response.rbs index de4fd8175..5719f62d8 100644 --- a/sig/mindee/parsing/common/workflow_response.rbs +++ b/sig/mindee/parsing/common/workflow_response.rbs @@ -3,10 +3,14 @@ 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 + @api_request: ApiRequest + @execution: Execution + @raw_http: String + + def execution: -> Execution + def api_request: -> ApiRequest + def raw_http: -> String + def initialize: (singleton(Parsing::Common::Inference), Hash[Symbol | String, untyped] | Net::HTTPResponse, String) -> void end end end diff --git a/spec/data b/spec/data index e48b26e52..632af76d6 160000 --- a/spec/data +++ b/spec/data @@ -1 +1 @@ -Subproject commit e48b26e5250cbbab9d3ee6c66c0eb85b667a4bb8 +Subproject commit 632af76d6eefe551cdeb2b7fa2f325cecec1b66f From a8a4071ca52cdccc1226ad3cacb0b5f6f98cdd52 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Thu, 31 Jul 2025 18:00:00 +0200 Subject: [PATCH 02/19] added most of the basic HTTP logic (non-functional) --- lib/mindee/client.rb | 4 +- lib/mindee/errors/mindee_http_error_v2.rb | 23 +++ lib/mindee/http/api_settings_v2.rb | 59 +++++++ lib/mindee/http/endpoint.rb | 4 +- lib/mindee/http/http_error_handler.rb | 13 ++ lib/mindee/http/mindee_api_v2.rb | 147 ++++++++++++++++++ lib/mindee/http/response_validation.rb | 15 ++ lib/mindee/http/workflow_endpoint.rb | 2 +- lib/mindee/input/inference_parameters.rb | 49 ++++++ lib/mindee/input/polling_options.rb | 29 ++++ .../input/sources/local_input_source.rb | 4 +- lib/mindee/parsing/common/api_request.rb | 4 +- sig/custom/net_http.rbs | 1 - sig/mindee/client.rbs | 11 +- sig/mindee/http/endpoint.rbs | 13 +- sig/mindee/http/http_error_handler.rbs | 7 +- sig/mindee/http/response_validation.rbs | 1 + .../input/sources/local_input_source.rbs | 4 +- 18 files changed, 370 insertions(+), 20 deletions(-) create mode 100644 lib/mindee/errors/mindee_http_error_v2.rb create mode 100644 lib/mindee/http/api_settings_v2.rb create mode 100644 lib/mindee/http/mindee_api_v2.rb create mode 100644 lib/mindee/input/inference_parameters.rb create mode 100644 lib/mindee/input/polling_options.rb diff --git a/lib/mindee/client.rb b/lib/mindee/client.rb index 07f62a9e4..2436088f1 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -89,8 +89,9 @@ def initialize(params: {}) # * `: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 close_file [bool, nil] Whether to close the file after sending it. Defaults to true. class WorkflowOptions - attr_accessor :document_alias, :priority, :full_text, :public_url, :page_options, :rag + attr_accessor :document_alias, :priority, :full_text, :public_url, :page_options, :rag, :close_file def initialize(params: {}) params = params.transform_keys(&:to_sym) @@ -102,6 +103,7 @@ def initialize(params: {}) raw_page_options = params.fetch(:page_options, nil) raw_page_options = PageOptions.new(params: raw_page_options) unless raw_page_options.is_a?(PageOptions) @page_options = raw_page_options + @close_file = params.fetch(:close_file, true) end end diff --git a/lib/mindee/errors/mindee_http_error_v2.rb b/lib/mindee/errors/mindee_http_error_v2.rb new file mode 100644 index 000000000..e4914298b --- /dev/null +++ b/lib/mindee/errors/mindee_http_error_v2.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require_relative 'mindee_error' + +module Mindee + module Errors + # API V2 HttpError + class MindeeHTTPErrorV2 < MindeeError + # @return [Integer] + attr_reader :status + # @return [String] + attr_reader :detail + + # @param http_error [Hash] + # @param code [Integer] + def initialize(http_error) + @status = http_error['status'] + @detail = http_error['detail'] + super("HTTP error: #{@status} - #{@detail}") + end + end + end +end diff --git a/lib/mindee/http/api_settings_v2.rb b/lib/mindee/http/api_settings_v2.rb new file mode 100644 index 000000000..e7a387287 --- /dev/null +++ b/lib/mindee/http/api_settings_v2.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Mindee + module HTTP + # API client for version 2. + class ApiSettingsV2 + # V2 API key's default environment key name. + MINDEE_V2_API_KEY_ENV_NAME = 'MINDEE_V2_API_KEY' + # V2 API key's default value. + MINDEE_V2_API_KEY_DEFAULT = nil + + # V2 base URL default environment key name. + MINDEE_V2_BASE_URL_ENV_NAME = 'MINDEE_V2_BASE_URL' + # V2 base URL default value. + MINDEE_V2_BASE_URL_DEFAULT = 'https://api-v2.mindee.net/v2' + + # HTTP request timeout default environment key name. + MINDEE_V2_REQUEST_TIMEOUT_ENV_NAME = 'MINDEE_V2_REQUEST_TIMEOUT' + # HTTP request timeout default value. + MINDEE_V2_TIMEOUT_DEFAULT = 120 + + # Default value for the user agent (same as V1). + USER_AGENT = "mindee-api-ruby@v#{Mindee::VERSION} ruby-v#{RUBY_VERSION} #{Mindee::PLATFORM}".freeze + + # @return [String] + attr_reader :api_key + # @return [Integer] + attr_reader :request_timeout + # @return [String] + attr_reader :base_url + # @return [String] + attr_reader :user_agent + + def initialize(api_key: '') + @request_timeout = ENV.fetch(MINDEE_V2_REQUEST_TIMEOUT_ENV_NAME, MINDEE_V2_TIMEOUT_DEFAULT).to_i + if api_key.nil? && !ENV.fetch(MINDEE_V2_API_KEY_ENV_NAME, MINDEE_V2_API_KEY_DEFAULT).to_s.empty? + logger.debug('API key set from environment') + end + @api_key = if api_key.nil? || api_key.empty? + ENV.fetch(MINDEE_V2_API_KEY_ENV_NAME, + MINDEE_V2_API_KEY_DEFAULT) + else + api_key + end + @base_url = ENV.fetch(MINDEE_V2_BASE_URL_ENV_NAME, MINDEE_V2_BASE_URL_DEFAULT).chomp('/') + @user_agent = USER_AGENT + end + + # Checks API key + def check_api_key + return unless @api_key.nil? || @api_key.empty? + + raise Errors::MindeeAPIError, + "Missing API key. check your Client Configuration.\nYou can set this using the " \ + "'#{MINDEE_V2_API_KEY_ENV_NAME}' environment variable." + end + end + end +end diff --git a/lib/mindee/http/endpoint.rb b/lib/mindee/http/endpoint.rb index 806524663..a6199939b 100644 --- a/lib/mindee/http/endpoint.rb +++ b/lib/mindee/http/endpoint.rb @@ -123,7 +123,7 @@ def predict_req_post(input_source, opts) form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource) [['document', input_source.url]] # : Array[untyped] else - [input_source.read_contents(close: opts.close_file)] # : Array[untyped] + ['document', *input_source.read_contents(close: opts.close_file)] # : Array[untyped] end form_data.push ['include_mvision', 'true'] if opts.all_words @@ -160,7 +160,7 @@ def document_queue_req_post(input_source, opts) form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource) [['document', input_source.url]] # : Array[untyped] else - [input_source.read_contents(close: opts.close_file)] # : Array[untyped] + ['document', *input_source.read_contents(close: opts.close_file)] # : Array[untyped] end form_data.push ['include_mvision', 'true'] if opts.all_words diff --git a/lib/mindee/http/http_error_handler.rb b/lib/mindee/http/http_error_handler.rb index b4ade5ace..7aad09cc3 100644 --- a/lib/mindee/http/http_error_handler.rb +++ b/lib/mindee/http/http_error_handler.rb @@ -88,6 +88,19 @@ def handle_error(url, response) Errors::MindeeHTTPError.new(error_obj, url, code) end end + + # Creates an appropriate HTTP error exception for a V2 API response, based on retrieved http error code. + # @param hashed_response [Hash] dictionary response retrieved by the server + def generate_v2_error(hashed_response) + code = hashed_response.code.to_i + if hashed_response.key?('status') + Errors::MindeeHTTPErrorV2.new(hashed_response) + elsif code < 200 || code > 399 + Errors::MindeeHTTPErrorV2.new({ 'status' => code, 'detail' => 'No details available.' }) + else + Errors::MindeeHTTPErrorV2.new({ 'status' => -1, 'detail' => 'Unknown Error.' }) + end + end end end end diff --git a/lib/mindee/http/mindee_api_v2.rb b/lib/mindee/http/mindee_api_v2.rb new file mode 100644 index 000000000..600d79779 --- /dev/null +++ b/lib/mindee/http/mindee_api_v2.rb @@ -0,0 +1,147 @@ +# frozen_string_literal: true + +require_relative 'api_settings_v2' +require_relative '../input' +require_relative '../errors' +require_relative '../parsing/v2' + +module Mindee + module HTTP + # API client for version 2. + class MindeeApiV2 + # @return [ApiSettingsV2] + attr_reader :settings + + # @param api_key [String, nil] + def initialize(api_key = nil) + @settings = ApiSettingsV2.new(api_key: api_key) + end + + # Sends a file to the inference queue. + # + # @param input_source [Input::Source::BaseSource] + # @param params [Input::InferenceParameters] + # @return [Mindee::Parsing::V2::JobResponse] + # @raise [Mindee::Errors::MindeeHttpErrorV2] + def req_post_inference_enqueue(input_source, params) + @settings.check_api_key + response = enqueue( + input_source, + params + ) + Parsing::V2::JobResponse.new(process_response(response)) + end + + # Retrieves a queued inference. + # + # @param inference_id [String] + # @return [Mindee::Parsing::V2::InferenceResponse] + def req_get_inference(inference_id) + @settings.check_api_key + response = inference_result_req_get( + inference_id + ) + Parsing::V2::InferenceResponse.new(process_response(response)) + end + + # Retrieves a queued job. + # + # @param job_id [String] + # @return [Mindee::Parsing::V2::JobResponse] + def req_get_job(job_id) + @settings.check_api_key + response = inference_result_req_get( + job_id + ) + Parsing::V2::JobResponse.new(process_response(response)) + end + + private + + # Converts an HTTP response to a parsed response object. + # + # @param response [Net::HTTP::Response, nil] + # @return [Hash] + # @raise Throws if the server returned an error. + def process_response(response) + if !response.nil? && response.respond_to?(:body) && ResponseValidation.valid_v2_response?(response) + return JSON.parse(response.body, object_class: Hash) + end + + response_body = if response.nil? || !response.respond_to?(:body) + { 'status' => -1, + 'detail' => 'Empty server response.' } + else + response.body + end + raise ErrorHandler.generate_v2_error(response_body) + end + + # Polls a queue for either a result or a job. + # @param url [String] URL, passed as a string. + # @return [Net::HTTP::Response] + def poll(url) + uri = URI(url) + headers = { + 'Authorization' => @settings.api_key, + 'User-Agent' => @settings.user_agent, + } + req = Net::HTTP::Get.new(uri, headers) + req['Transfer-Encoding'] = 'chunked' + + Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @settings.request_timeout) do |http| + return http.request(req) + end + raise Mindee::Errors::MindeeError, 'Could not resolve server response.' + end + + # Polls the API for the status of a job. + # + # @param job_id [String] ID of the job. + # @return [Net::HTTP::Response] + def inference_job_req_get(job_id) + poll("#{@url_root}/jobs/#{job_id}") + end + + # Polls the API for the result of an inference. + # + # @param queue_id [String] ID of the queue. + # @return [Net::HTTP::Response] + def inference_result_req_get(queue_id) + poll("#{@url_root}/inferences/#{queue_id}") + end + + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # @param params [Input::InferenceParameters] Parse options. + # @return [Net::HTTPResponse, nil] + def enqueue(input_source, params) + uri = URI("#{@settings.url_root}/inferences/enqueue") + + req_params = { model_id: params[:model_id] } + req_params[:rag] = 'true' if params.rag + req_params[:file_alias] = params.full_text if params.full_text + req_params[:webhook_ids] = params.webhook_ids.join(',') if params.webhook_ids + uri.query = URI.encode_www_form(req_params) + + headers = { + 'Authorization' => @settings.api_key, + 'User-Agent' => @settings.user_agent, + } + req = Net::HTTP::Post.new(uri, headers) + form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource) + [['url', input_source.url]] # : Array[untyped] + else + ['file', input_source.read_contents(close: params.close_file)] # : Array[untyped] + end + + req.set_form(form_data, 'multipart/form-data') + req['Transfer-Encoding'] = 'chunked' + + Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @settings.request_timeout) do |http| + return http.request(req) + end + raise Mindee::Errors::MindeeError, 'Could not resolve server response.' + end + end + end +end diff --git a/lib/mindee/http/response_validation.rb b/lib/mindee/http/response_validation.rb index 1601e2b5d..9ed086607 100644 --- a/lib/mindee/http/response_validation.rb +++ b/lib/mindee/http/response_validation.rb @@ -21,6 +21,21 @@ def self.valid_sync_response?(response) true end + # Checks if a V2 response is valid. + # @param [Net::HTTPResponse] response + # @return [bool] + def self.valid_v2_response?(response) + return false unless valid_sync_response?(response) + + hashed_response = JSON.parse(response.body, object_class: Hash) + + return false if hashed_response.dig('job', 'status').to_s == 'Failed' + + return false if hashed_response.dig('job', 'error') && !hashed_response.dig('job', 'error').empty? + + true + end + # 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 diff --git a/lib/mindee/http/workflow_endpoint.rb b/lib/mindee/http/workflow_endpoint.rb index 1c239ce20..4e7bab078 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, opts) if input_source.is_a?(Mindee::Input::Source::URLInputSource) form_data.push ['document', input_source.url] else - form_data.push input_source.read_contents + form_data.push ['document', *input_source.read_contents(close: opts.close_file)] end form_data.push ['alias', opts.document_alias] if opts.document_alias form_data.push ['public_url', opts.public_url] if opts.public_url diff --git a/lib/mindee/input/inference_parameters.rb b/lib/mindee/input/inference_parameters.rb new file mode 100644 index 000000000..0897ee58d --- /dev/null +++ b/lib/mindee/input/inference_parameters.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +module Mindee + module Input + # Parameters to set when sending a file for inference. + # + # Rough equivalent of the Python dataclass: + # mindee.input.inference_parameters.InferenceParameters + class InferenceParameters + # @return [String] ID of the model (required). + attr_reader :model_id + + # @return [Boolean, nil] Enable Retrieval-Augmented Generation. + attr_accessor :rag + + # @return [String, nil] Optional alias for the file. + attr_accessor :file_alias + + # @return [Array, nil] Optional list of webhooks IDs to propagate the API response to. + attr_accessor :webhook_ids + + # @return [PollingOptions, nil] Options for polling. Set only if having timeout issues. + attr_accessor :polling_options + + # @return [Boolean, nil] Whether to close the file after parsing. + attr_accessor :close_file + + # @param model_id [String] ID of the model (required). + # @param rag [Boolean] Enable RAG (default: false). + # @param file_alias [String, nil] Optional alias (default: nil). + # @param webhook_ids [Array, nil] Webhook IDs (default: nil). + # @param polling_options [PollingOptions, nil] Polling options (default: nil). + # @param close_file [Boolean] Close the file after parsing (default: true). + def initialize(model_id:, + rag: false, + file_alias: nil, + webhook_ids: nil, + polling_options: nil, + close_file: true) + @model_id = model_id + @rag = rag + @file_alias = file_alias + @webhook_ids = webhook_ids.nil? ? [] : webhook_ids + @polling_options = polling_options.nil? ? PollingOptions.new : polling_options + @close_file = close_file.nil? || close_file + end + end + end +end diff --git a/lib/mindee/input/polling_options.rb b/lib/mindee/input/polling_options.rb new file mode 100644 index 000000000..0e9e89611 --- /dev/null +++ b/lib/mindee/input/polling_options.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Mindee + module Input + # Options for asynchronous polling. + # + # Rough equivalent of: + # mindee.input.polling_options.PollingOptions (Python) + class PollingOptions + # Initial delay before the first polling attempt (in seconds). + attr_accessor :initial_delay_sec + + # Delay between each polling attempt (in seconds). + attr_accessor :delay_sec + + # Total number of polling attempts. + attr_accessor :max_retries + + # @param initial_delay_sec [Float] Initial delay before the first attempt (default: 2.0) + # @param delay_sec [Float] Delay between attempts (default: 1.5) + # @param max_retries [Integer] Maximum number of retries (default: 80) + def initialize(initial_delay_sec: 2.0, delay_sec: 1.5, max_retries: 80) + @initial_delay_sec = initial_delay_sec + @delay_sec = delay_sec + @max_retries = max_retries + end + end + end +end diff --git a/lib/mindee/input/sources/local_input_source.rb b/lib/mindee/input/sources/local_input_source.rb index 7cef27c90..e82fc5f46 100644 --- a/lib/mindee/input/sources/local_input_source.rb +++ b/lib/mindee/input/sources/local_input_source.rb @@ -93,7 +93,7 @@ def process_pdf(options) # Reads a document. # @param close [bool] - # @return [Array] + # @return [Array<>] def read_contents(close: true) logger.debug("Reading data from: #{@filename}") @io_stream.seek(0) @@ -101,7 +101,7 @@ def read_contents(close: true) data = @io_stream.read @io_stream.rewind @io_stream.close if close - ['document', data, { filename: Mindee::Input::Source.convert_to_unicode_escape(@filename) }] + [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. diff --git a/lib/mindee/parsing/common/api_request.rb b/lib/mindee/parsing/common/api_request.rb index c9e8876e3..131d8cf4e 100644 --- a/lib/mindee/parsing/common/api_request.rb +++ b/lib/mindee/parsing/common/api_request.rb @@ -8,7 +8,7 @@ class ApiRequest # @return [Hash] attr_reader :error # @return [Array] - attr_reader :ressources + attr_reader :resources # @return [RequestStatus, Symbol] attr_reader :status # @return [Integer] @@ -18,7 +18,7 @@ class ApiRequest def initialize(server_response) @error = server_response['error'] - @ressources = server_response['ressources'] + @resources = server_response['resources'] @status = if server_response['status'] == 'failure' RequestStatus::FAILURE diff --git a/sig/custom/net_http.rbs b/sig/custom/net_http.rbs index 5bfa33318..8d6d08a43 100644 --- a/sig/custom/net_http.rbs +++ b/sig/custom/net_http.rbs @@ -29,7 +29,6 @@ module Net class HTTPResponse def self.body: -> untyped - def body: -> untyped def []: (untyped) -> untyped def key?: (untyped) -> bool def code: -> String diff --git a/sig/mindee/client.rbs b/sig/mindee/client.rbs index 4d5fb2711..eab25836d 100644 --- a/sig/mindee/client.rbs +++ b/sig/mindee/client.rbs @@ -33,18 +33,21 @@ module Mindee attr_accessor rag: bool? attr_accessor public_url: (String?) attr_accessor page_options: (PageOptions) + attr_accessor close_file: bool def initialize: (params: Hash[Symbol | String, untyped]) -> void end class Client + @api_key: string |nil + def initialize: (?api_key: String) -> void def logger: () -> untyped - def parse: (Input::Source::LocalInputSource | Input::Source::URLInputSource, untyped, ?endpoint: (HTTP::Endpoint?), options: ParseOptions | Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse - def parse_sync: (Input::Source::LocalInputSource | Input::Source::URLInputSource, untyped, HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse - def enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, untyped, ?endpoint: (HTTP::Endpoint?), options: ParseOptions|Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse + def parse: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), ?endpoint: (HTTP::Endpoint?), options: ParseOptions | Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse + def parse_sync: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse + def enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), ?endpoint: (HTTP::Endpoint?), options: ParseOptions|Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse def parse_queued: (String, singleton(Parsing::Common::Inference), ?endpoint: HTTP::Endpoint?) -> Parsing::Common::ApiResponse - def enqueue_and_parse: (Input::Source::URLInputSource|Input::Source::LocalInputSource, untyped, HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse + def enqueue_and_parse: (Input::Source::URLInputSource|Input::Source::LocalInputSource, singleton(Parsing::Common::Inference), HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse def execute_workflow: (Input::Source::URLInputSource|Input::Source::LocalInputSource, String, options: (Hash[Symbol | String, untyped] | WorkflowOptions)) -> Parsing::Common::WorkflowResponse def load_prediction: (singleton(Parsing::Common::Inference), Input::LocalResponse) -> Parsing::Common::ApiResponse def source_from_path: (String, ?repair_pdf: bool) -> Input::Source::PathInputSource diff --git a/sig/mindee/http/endpoint.rbs b/sig/mindee/http/endpoint.rbs index a6946d8ce..563d79210 100644 --- a/sig/mindee/http/endpoint.rbs +++ b/sig/mindee/http/endpoint.rbs @@ -2,14 +2,21 @@ module Mindee module HTTP API_KEY_ENV_NAME: String - API_KEY_DEFAULT: nil + API_KEY_DEFAULT: String | 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 + attr_reader api_key: String | nil + + attr_reader base_url: String + attr_reader request_timeout: Integer + + attr_reader url_root: String + + def logger: () -> Logger def api_key: -> String? def request_timeout: -> Integer def url_root: -> String @@ -20,7 +27,7 @@ module Mindee def parse_async: (String) -> [Net::HTTPResponse, Hash[Symbol, untyped]] def predict_req_post: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> Net::HTTPResponse def document_queue_req_post: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> Net::HTTPResponse - def document_queue_req_get: (untyped) -> Net::HTTPResponse + def document_queue_req_get: (String) -> Net::HTTPResponse def check_api_key: -> void end end diff --git a/sig/mindee/http/http_error_handler.rbs b/sig/mindee/http/http_error_handler.rbs index 3a1388305..c46c742ef 100644 --- a/sig/mindee/http/http_error_handler.rbs +++ b/sig/mindee/http/http_error_handler.rbs @@ -2,9 +2,10 @@ 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 + def extract_error: (Hash[String | Symbol, untyped]) -> void + def create_error_obj: (Hash[String | Symbol, untyped]) -> (Hash[String, String] | Hash[String | Symbol, untyped])? + def handle_error: (String, Hash[String | Symbol, untyped]) -> void + def handle_v2_error: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/http/response_validation.rbs b/sig/mindee/http/response_validation.rbs index 447a6aa91..142a7eb92 100644 --- a/sig/mindee/http/response_validation.rbs +++ b/sig/mindee/http/response_validation.rbs @@ -3,6 +3,7 @@ module Mindee module HTTP module ResponseValidation def self.valid_sync_response?: (Net::HTTPResponse) -> bool + def self.valid_v2_response?: (Net::HTTPResponse) -> bool def self.valid_async_response?: (Net::HTTPResponse) -> bool def self.clean_request!: (Net::HTTPResponse) -> void end diff --git a/sig/mindee/input/sources/local_input_source.rbs b/sig/mindee/input/sources/local_input_source.rbs index 985fa7807..f4f14dfab 100644 --- a/sig/mindee/input/sources/local_input_source.rbs +++ b/sig/mindee/input/sources/local_input_source.rbs @@ -9,10 +9,12 @@ module Mindee def io_stream: -> StringIO def initialize: (StringIO | File, String, ?repair_pdf: bool) -> void def logger: () -> untyped + + def rescue_broken_pdf: (StringIO) -> StringIO def pdf?: -> bool def process_pdf: (PageOptions) -> StringIO? - def read_contents: (?close: bool) -> [String, String?, Hash[:filename, String]] + def read_contents: (?close: bool) -> [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 From 92d3d4865192a430a64321d44784024b4293bf24 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 5 Aug 2025 10:46:35 +0200 Subject: [PATCH 03/19] fix broken v1 tests --- lib/mindee.rb | 1 + lib/mindee/client.rb | 27 +- lib/mindee/client_v2.rb | 509 ++++++++++++++++++ lib/mindee/http/endpoint.rb | 4 +- .../input/sources/base64_input_source.rb | 4 +- .../input/sources/local_input_source.rb | 12 +- lib/mindee/page_options.rb | 25 + sig/mindee/client.rbs | 10 +- .../input/sources/base64_input_source.rbs | 2 +- .../input/sources/local_input_source.rbs | 7 +- sig/mindee/page_options.rbs | 9 + spec/input/sources/files_handling_spec.rb | 36 +- spec/input/sources/sources_spec.rb | 2 +- 13 files changed, 587 insertions(+), 61 deletions(-) create mode 100644 lib/mindee/client_v2.rb create mode 100644 lib/mindee/page_options.rb create mode 100644 sig/mindee/page_options.rbs diff --git a/lib/mindee.rb b/lib/mindee.rb index 26f2be437..6c5bdb8d3 100644 --- a/lib/mindee.rb +++ b/lib/mindee.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'mindee/client' +require 'mindee/page_options' require 'mindee/logging' module Mindee diff --git a/lib/mindee/client.rb b/lib/mindee/client.rb index 2436088f1..67122b2d9 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -2,38 +2,17 @@ require_relative 'input' require_relative 'http' -require_relative 'product' +require_relative 'logging' +require_relative 'page_options' require_relative 'parsing/common/api_response' require_relative 'parsing/common/job' require_relative 'parsing/common/workflow_response' -require_relative 'logging' +require_relative 'product' # Default owner for products. OTS_OWNER = 'mindee' module Mindee - # Class for page options in parse calls. - # - # @!attribute page_indexes [Array[Integer]] Zero-based list of page indexes. - # @!attribute operation [:KEEP_ONLY, :REMOVE] Operation to apply on the document, given the specified page indexes: - # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # * `:REMOVE` - remove the specified pages, and keep all others. - # @!attribute on_min_pages [Integer, nil] Apply the operation only if the document has at least this many pages. - class PageOptions - attr_accessor :page_indexes, :operation, :on_min_pages - - def initialize(params: {}) - params ||= {} - params = params.transform_keys(&:to_sym) - @page_indexes = params.fetch( - :page_indexes, - [] # : Array[Integer] - ) - @operation = params.fetch(:operation, :KEEP_ONLY) - @on_min_pages = params.fetch(:on_min_pages, nil) - end - end - # Class for configuration options in parse calls. # # @!attribute all_words [bool] Whether to include the full text for each page. diff --git a/lib/mindee/client_v2.rb b/lib/mindee/client_v2.rb new file mode 100644 index 000000000..2436088f1 --- /dev/null +++ b/lib/mindee/client_v2.rb @@ -0,0 +1,509 @@ +# frozen_string_literal: true + +require_relative 'input' +require_relative 'http' +require_relative 'product' +require_relative 'parsing/common/api_response' +require_relative 'parsing/common/job' +require_relative 'parsing/common/workflow_response' +require_relative 'logging' + +# Default owner for products. +OTS_OWNER = 'mindee' + +module Mindee + # Class for page options in parse calls. + # + # @!attribute page_indexes [Array[Integer]] Zero-based list of page indexes. + # @!attribute operation [:KEEP_ONLY, :REMOVE] Operation to apply on the document, given the specified page indexes: + # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # * `:REMOVE` - remove the specified pages, and keep all others. + # @!attribute on_min_pages [Integer, nil] Apply the operation only if the document has at least this many pages. + class PageOptions + attr_accessor :page_indexes, :operation, :on_min_pages + + def initialize(params: {}) + params ||= {} + params = params.transform_keys(&:to_sym) + @page_indexes = params.fetch( + :page_indexes, + [] # : Array[Integer] + ) + @operation = params.fetch(:operation, :KEEP_ONLY) + @on_min_pages = params.fetch(:on_min_pages, nil) + end + end + + # Class for configuration options in parse calls. + # + # @!attribute all_words [bool] Whether to include the full text for each page. + # This performs a full OCR operation on the server and will increase response time. + # @!attribute full_text [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # @!attribute close_file [bool] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # @!attribute page_options [PageOptions, Hash, nil] Page cutting/merge options: + # * `:page_indexes` Zero-based list of page indexes. + # * `:operation` Operation to apply on the document, given the specified page indexes: + # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # * `:REMOVE` - remove the specified pages, and keep all others. + # * `:on_min_pages` Apply the operation only if the document has at least this many pages. + # @!attribute cropper [bool] Whether to include cropper results for each page. + # This performs a cropping operation on the server and will increase response time. + # @!attribute initial_delay_sec [Numeric] Initial delay before polling. Defaults to 2. + # @!attribute delay_sec [Numeric] Delay between polling attempts. Defaults to 1.5. + # @!attribute max_retries [Integer] Maximum number of retries. Defaults to 80. + class ParseOptions + attr_accessor :all_words, :full_text, :close_file, :page_options, :cropper, :rag, + :workflow_id, :initial_delay_sec, :delay_sec, :max_retries + + def initialize(params: {}) + params = params.transform_keys(&:to_sym) + @all_words = params.fetch(:all_words, false) + @full_text = params.fetch(:full_text, false) + @close_file = params.fetch(:close_file, true) + raw_page_options = params.fetch(:page_options, nil) + raw_page_options = PageOptions.new(params: raw_page_options) unless raw_page_options.is_a?(PageOptions) + @page_options = raw_page_options + @cropper = params.fetch(:cropper, false) + @rag = params.fetch(:rag, false) + @workflow_id = params.fetch(:workflow_id, nil) + @initial_delay_sec = params.fetch(:initial_delay_sec, 2) + @delay_sec = params.fetch(:delay_sec, 1.5) + @max_retries = params.fetch(:max_retries, 80) + end + end + + # Class for configuration options in workflow executions. + # + # @!attribute document_alias [String, nil] Alias to give to the document. + # @!attribute priority [Symbol, nil] Priority to give to the document. + # @!attribute full_text [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # @!attribute public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without + # requiring authentication. + # @!attribute rag [bool, nil] Whether to enable Retrieval-Augmented Generation. + # @!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 close_file [bool, nil] Whether to close the file after sending it. Defaults to true. + class WorkflowOptions + attr_accessor :document_alias, :priority, :full_text, :public_url, :page_options, :rag, :close_file + + 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) + @rag = params.fetch(:rag, nil) + raw_page_options = params.fetch(:page_options, nil) + raw_page_options = PageOptions.new(params: raw_page_options) unless raw_page_options.is_a?(PageOptions) + @page_options = raw_page_options + @close_file = params.fetch(:close_file, true) + end + end + + # Mindee API Client. + # See: https://developers.mindee.com/docs + class Client + # @param api_key [String] + def initialize(api_key: '') + @api_key = api_key + end + + # Enqueue a document for parsing and automatically try to retrieve it if needed. + # + # Accepts options either as a Hash or as a ParseOptions struct. + # + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # @param product_class [Mindee::Inference] The class of the product. + # @param endpoint [Mindee::HTTP::Endpoint, nil] Endpoint of the API. + # @param options [Hash] A hash of options to configure the parsing behavior. Possible keys: + # * `:all_words` [bool] Whether to extract all the words on each page. + # This performs a full OCR operation on the server and will increase response time. + # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # * `:close_file` [bool] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # * `:page_options` [Hash, nil] Page cutting/merge options: + # - `:page_indexes` [Array] Zero-based list of page indexes. + # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: + # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # - `:REMOVE` - remove the specified pages, and keep all others. + # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. + # * `:cropper` [bool, nil] Whether to include cropper results for each page. + # This performs a cropping operation on the server and will increase response time. + # * `:initial_delay_sec` [Numeric] Initial delay before polling. Defaults to 2. + # * `:delay_sec` [Numeric] Delay between polling attempts. Defaults to 1.5. + # * `:max_retries` [Integer] Maximum number of retries. Defaults to 80. + # @param enqueue [bool] Whether to enqueue the file. + # @return [Mindee::Parsing::Common::ApiResponse] + def parse(input_source, product_class, endpoint: nil, options: {}, enqueue: true) + opts = normalize_parse_options(options) + process_pdf_if_required(input_source, opts) if input_source.is_a?(Input::Source::LocalInputSource) + endpoint ||= initialize_endpoint(product_class) + + if enqueue && product_class.has_async + enqueue_and_parse(input_source, product_class, endpoint, opts) + else + parse_sync(input_source, product_class, endpoint, opts) + end + 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` [bool] Whether to extract all the words on each page. + # This performs a full OCR operation on the server and will increase response time. + # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # * `:close_file` [bool] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # * `:page_options` [Hash, nil] Page cutting/merge options: + # - `:page_indexes` [Array] Zero-based list of page indexes. + # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: + # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # - `:REMOVE` - remove the specified pages, and keep all others. + # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. + # * `:cropper` [bool, nil] Whether to include cropper results for each page. + # This performs a cropping operation on the server and will increase response time. + # @return [Mindee::Parsing::Common::ApiResponse] + def parse_sync(input_source, product_class, endpoint, options) + logger.debug("Parsing document as '#{endpoint.url_root}'") + + prediction, raw_http = endpoint.predict( + input_source, + options + ) + + Mindee::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http.to_s) + end + + # Enqueue a document for async parsing + # + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # The source of the input document (local file or URL). + # @param product_class [Mindee::Inference] The class of the product. + # @param options [Hash] A hash of options to configure the enqueue behavior. Possible keys: + # * `:endpoint` [HTTP::Endpoint, nil] Endpoint of the API. + # Doesn't need to be set in the case of OTS APIs. + # * `:all_words` [bool] Whether to extract all the words on each page. + # This performs a full OCR operation on the server and will increase response time. + # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # * `:close_file` [bool] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # * `:page_options` [Hash, nil] Page cutting/merge options: + # - `:page_indexes` [Array] Zero-based list of page indexes. + # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: + # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # - `:REMOVE` - remove the specified pages, and keep all others. + # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. + # * `:cropper` [bool] Whether to include cropper results for each page. + # This performs a cropping operation on the server and will increase response time. + # * `:rag` [bool] Whether to enable Retrieval-Augmented Generation. Only works if a Workflow ID is provided. + # * `:workflow_id` [String, nil] ID of the workflow to use. + # @param endpoint [Mindee::HTTP::Endpoint] Endpoint of the API. + # @return [Mindee::Parsing::Common::ApiResponse] + def enqueue(input_source, product_class, endpoint: nil, options: {}) + opts = normalize_parse_options(options) + endpoint ||= initialize_endpoint(product_class) + logger.debug("Enqueueing document as '#{endpoint.url_root}'") + + prediction, raw_http = endpoint.predict_async( + input_source, + opts + ) + Mindee::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http.to_json) + end + + # Parses a queued document + # + # @param job_id [String] ID of the job (queue) to poll from + # @param product_class [Mindee::Inference] class of the product + # @param endpoint [HTTP::Endpoint, nil] Endpoint of the API + # Doesn't need to be set in the case of OTS APIs. + # + # @return [Mindee::Parsing::Common::ApiResponse] + def parse_queued(job_id, product_class, endpoint: nil) + 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.to_json) + end + + # Enqueue a document for async parsing and automatically try to retrieve it + # + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # The source of the input document (local file or URL). + # @param product_class [Mindee::Inference] The class of the product. + # @param options [Hash] A hash of options to configure the parsing behavior. Possible keys: + # * `:endpoint` [HTTP::Endpoint, nil] Endpoint of the API. + # Doesn't need to be set in the case of OTS APIs. + # * `:all_words` [bool] Whether to extract all the words on each page. + # This performs a full OCR operation on the server and will increase response time. + # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. + # This performs a full OCR operation on the server and may increase response time. + # * `:close_file` [bool] Whether to `close()` the file after parsing it. + # Set to false if you need to access the file after this operation. + # * `:page_options` [Hash, nil] Page cutting/merge options: + # - `:page_indexes` [Array] Zero-based list of page indexes. + # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: + # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # - `:REMOVE` - remove the specified pages, and keep all others. + # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. + # * `:cropper` [bool, nil] Whether to include cropper results for each page. + # This performs a cropping operation on the server and will increase response time. + # * `:rag` [bool] Whether to enable Retrieval-Augmented Generation. Only works if a Workflow ID is provided. + # * `:workflow_id` [String, nil] ID of the workflow to use. + # * `:initial_delay_sec` [Numeric] Initial delay before polling. Defaults to 2. + # * `:delay_sec` [Numeric] Delay between polling attempts. Defaults to 1.5. + # * `:max_retries` [Integer] Maximum number of retries. Defaults to 80. + # @param endpoint [Mindee::HTTP::Endpoint] Endpoint of the API. + # @return [Mindee::Parsing::Common::ApiResponse] + def enqueue_and_parse(input_source, product_class, endpoint, options) + validate_async_params(options.initial_delay_sec, options.delay_sec, options.max_retries) + enqueue_res = enqueue(input_source, product_class, endpoint: endpoint, options: options) + job = enqueue_res.job or raise Errors::MindeeAPIError, 'Expected job to be present' + job_id = job.id + + sleep(options.initial_delay_sec) + polling_attempts = 1 + logger.debug("Successfully enqueued document with job id: '#{job_id}'") + 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' + valid_statuses = [ + Mindee::Parsing::Common::JobStatus::WAITING, + Mindee::Parsing::Common::JobStatus::PROCESSING, + ] + # @type var valid_statuses: Array[(:waiting | :processing | :completed | :failed)] + while valid_statuses.include?(queue_res_job.status) && polling_attempts < options.max_retries + logger.debug("Polling server for parsing result with job id: '#{job_id}'. Attempt #{polling_attempts}") + sleep(options.delay_sec) + queue_res = parse_queued(job_id, product_class, endpoint: endpoint) + queue_res_job = queue_res.job or raise Errors::MindeeAPIError, 'Expected job to be present' + polling_attempts += 1 + end + + if queue_res_job.status != Mindee::Parsing::Common::JobStatus::COMPLETED + elapsed = options.initial_delay_sec + (polling_attempts * options.delay_sec.to_f) + raise Errors::MindeeAPIError, + "Asynchronous parsing request timed out after #{elapsed} seconds (#{polling_attempts} tries)" + end + + queue_res + end + + # 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 workflow_id [String] + # @param options [Hash, WorkflowOptions] Options to configure workflow behavior. Possible keys: + # * `document_alias` [String, nil] Alias to give to the document. + # * `priority` [Symbol, nil] Priority to give to the document. + # * `full_text` [bool] Whether to include the full OCR text response in compatible APIs. + # * `rag` [bool, nil] Whether to enable Retrieval-Augmented Generation. + # + # * `public_url` [String, nil] A unique, encrypted URL for accessing the document validation interface without + # requiring authentication. + # * `page_options` [Hash, nil] Page cutting/merge options: + # * `:page_indexes` Zero-based list of page indexes. + # * `:operation` Operation to apply on the document, given the `page_indexes specified: + # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # * `:REMOVE` - remove the specified pages, and keep all others. + # * `:on_min_pages` Apply the operation only if document has at least this many pages. + # @return [Mindee::Parsing::Common::WorkflowResponse] + def execute_workflow(input_source, workflow_id, options: {}) + opts = options.is_a?(WorkflowOptions) ? options : WorkflowOptions.new(params: options) + if opts.respond_to?(:page_options) && input_source.is_a?(Input::Source::LocalInputSource) + process_pdf_if_required(input_source, opts) + end + + workflow_endpoint = Mindee::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key) + logger.debug("Sending document to workflow '#{workflow_id}'") + + prediction, raw_http = workflow_endpoint.execute_workflow( + input_source, + opts + ) + + Mindee::Parsing::Common::WorkflowResponse.new(Product::Universal::Universal, prediction, raw_http) + end + + # Load a prediction. + # + # @param product_class [Mindee::Inference] class of the product + # @param local_response [Mindee::Input::LocalResponse] + # @return [Mindee::Parsing::Common::ApiResponse] + def load_prediction(product_class, local_response) + raise Errors::MindeeAPIError, 'Expected LocalResponse to not be nil.' if local_response.nil? + + response_hash = local_response.as_hash || {} + raise Errors::MindeeAPIError, 'Expected LocalResponse#as_hash to return a hash.' if response_hash.nil? + + Mindee::Parsing::Common::ApiResponse.new(product_class, response_hash, response_hash.to_json) + rescue KeyError, Errors::MindeeAPIError + raise Errors::MindeeInputError, 'No prediction found in local response.' + end + + # Load a document from an absolute path, as a string. + # @param input_path [String] Path of file to open + # @param repair_pdf [bool] Attempts to fix broken pdf if true + # @return [Mindee::Input::Source::PathInputSource] + 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 repair_pdf [bool] Attempts to fix broken pdf if true + # @return [Mindee::Input::Source::BytesInputSource] + 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 repair_pdf [bool] Attempts to fix broken pdf if true + # @return [Mindee::Input::Source::Base64InputSource] + 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 repair_pdf [bool] Attempts to fix broken pdf if true + # @return [Mindee::Input::Source::FileInputSource] + 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] + def source_from_url(url) + Input::Source::URLInputSource.new(url) + end + + # Creates a custom endpoint with the given values. + # Do not set for standard (off the shelf) endpoints. + # + # @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. + # + # @param account_name [String] For custom endpoints, your account or organization username on the API Builder. + # This is normally not required unless you have a custom endpoint which has the same name as a + # standard (off the shelf) endpoint. + # @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::Universal::Universal, + endpoint_name: endpoint_name, + account_name: account_name, + version: version + ) + end + + # Validates the parameters for async auto-polling + # @param initial_delay_sec [Numeric] initial delay before polling + # @param delay_sec [Numeric] delay between polling attempts + # @param max_retries [Integer, nil] maximum amount of retries. + def validate_async_params(initial_delay_sec, delay_sec, max_retries) + min_delay_sec = 1 + min_initial_delay_sec = 1 + min_retries = 2 + + 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 ArgumentError, + "Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)" + end + raise ArgumentError, "Cannot set auto-poll retries to less than #{min_retries}" if max_retries < min_retries + end + + # Creates an endpoint with the given values. Raises an error if the endpoint is invalid. + # @param product_class [Mindee::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. + # + # @param account_name [String] For custom endpoints, your account or organization username on the API Builder. + # This is normally not required unless you have a custom endpoint which has the same name as a + # standard (off the shelf) endpoint. + # @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::Universal::Universal + raise Mindee::Errors::MindeeConfigurationError, 'Missing argument endpoint_name when using custom class' + end + + endpoint_name = fix_endpoint_name(product_class, endpoint_name) + account_name = fix_account_name(account_name) + version = fix_version(product_class, version) + + HTTP::Endpoint.new(account_name, endpoint_name, version, api_key: @api_key) + end + + def fix_endpoint_name(product_class, endpoint_name) + endpoint_name.nil? || endpoint_name.empty? ? product_class.endpoint_name : endpoint_name + end + + def fix_account_name(account_name) + if account_name.nil? || account_name.empty? + logger.info("No account name provided, #{OTS_OWNER} will be used by default.") + return OTS_OWNER + end + + account_name + end + + def fix_version(product_class, version) + return version unless version.nil? || version.empty? + + if product_class.endpoint_version.nil? || product_class.endpoint_version.empty? + logger.debug('No version provided for a custom build, will attempt to poll version 1 by default.') + return '1' + end + product_class.endpoint_version + end + + # If needed, converts the parsing options provided as a hash into a proper ParseOptions object. + # @param options [Hash, ParseOptions] Options. + # @return [ParseOptions] + def normalize_parse_options(options) + return options if options.is_a?(ParseOptions) + + ParseOptions.new(params: options) + end + + # Processes a PDF if parameters were provided. + # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] + # @param opts [ParseOptions] + def process_pdf_if_required(input_source, opts) + return unless input_source.is_a?(Mindee::Input::Source::LocalInputSource) && + opts.page_options.on_min_pages && + 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/http/endpoint.rb b/lib/mindee/http/endpoint.rb index a6199939b..4345f0db1 100644 --- a/lib/mindee/http/endpoint.rb +++ b/lib/mindee/http/endpoint.rb @@ -123,7 +123,7 @@ def predict_req_post(input_source, opts) form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource) [['document', input_source.url]] # : Array[untyped] else - ['document', *input_source.read_contents(close: opts.close_file)] # : Array[untyped] + [['document', *input_source.read_contents(close: opts.close_file)]] # : Array[untyped] end form_data.push ['include_mvision', 'true'] if opts.all_words @@ -160,7 +160,7 @@ def document_queue_req_post(input_source, opts) form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource) [['document', input_source.url]] # : Array[untyped] else - ['document', *input_source.read_contents(close: opts.close_file)] # : Array[untyped] + [['document', *input_source.read_contents(close: opts.close_file)]] # : Array[untyped] end form_data.push ['include_mvision', 'true'] if opts.all_words diff --git a/lib/mindee/input/sources/base64_input_source.rb b/lib/mindee/input/sources/base64_input_source.rb index f3cd2a821..af2972d94 100644 --- a/lib/mindee/input/sources/base64_input_source.rb +++ b/lib/mindee/input/sources/base64_input_source.rb @@ -18,12 +18,12 @@ def initialize(base64_string, filename, repair_pdf: false) # Overload of the same function to prevent a base64 from being re-encoded. # @param close [bool] - # @return [Array] + # @return [Array<[String, aBinaryString ], [Hash, nil] >] def read_contents(close: true) @io_stream.seek(0) data = @io_stream.read @io_stream.close if close - ['document', [data].pack('m'), { filename: Source.convert_to_unicode_escape(@filename) }] + [[data].pack('m'), { filename: Source.convert_to_unicode_escape(@filename) }] end end end diff --git a/lib/mindee/input/sources/local_input_source.rb b/lib/mindee/input/sources/local_input_source.rb index e82fc5f46..3aaced4ce 100644 --- a/lib/mindee/input/sources/local_input_source.rb +++ b/lib/mindee/input/sources/local_input_source.rb @@ -60,7 +60,7 @@ def initialize(io_stream, filename, repair_pdf: false) # Attempts to fix pdf files if mimetype is rejected. # "Broken PDFs" are often a result of third-party injecting invalid headers. # This attempts to remove them and send the file - # @param stream [StringIO] + # @param stream [StringIO, File] def rescue_broken_pdf(stream) stream.gets('%PDF-') raise Errors::MindeePDFError if stream.eof? || stream.pos > 500 @@ -78,7 +78,7 @@ def pdf? @file_mimetype.to_s == 'application/pdf' end - # Parses a PDF file according to provided options. + # Cuts a PDF file according to provided options. # @param options [PageOptions, nil] Page cutting/merge options: # # * `:page_indexes` Zero-based list of page indexes. @@ -86,11 +86,17 @@ def pdf? # * `: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. - def process_pdf(options) + def apply_page_options(options) @io_stream.seek(0) @io_stream = PDF::PDFProcessor.parse(@io_stream, options) end + # @deprecated Use {#apply_page_options} instead. + # @see #apply_page_options + def process_pdf(options) + apply_page_options(options) + end + # Reads a document. # @param close [bool] # @return [Array<>] diff --git a/lib/mindee/page_options.rb b/lib/mindee/page_options.rb new file mode 100644 index 000000000..eed3f1c2f --- /dev/null +++ b/lib/mindee/page_options.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Mindee + # Class for page options in parse calls. + # + # @!attribute page_indexes [Array[Integer]] Zero-based list of page indexes. + # @!attribute operation [:KEEP_ONLY, :REMOVE] Operation to apply on the document, given the specified page indexes: + # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. + # * `:REMOVE` - remove the specified pages, and keep all others. + # @!attribute on_min_pages [Integer, nil] Apply the operation only if the document has at least this many pages. + class PageOptions + attr_accessor :page_indexes, :operation, :on_min_pages + + def initialize(params: {}) + params ||= {} + params = params.transform_keys(&:to_sym) + @page_indexes = params.fetch( + :page_indexes, + [] # : Array[Integer] + ) + @operation = params.fetch(:operation, :KEEP_ONLY) + @on_min_pages = params.fetch(:on_min_pages, nil) + end + end +end diff --git a/sig/mindee/client.rbs b/sig/mindee/client.rbs index eab25836d..328618d80 100644 --- a/sig/mindee/client.rbs +++ b/sig/mindee/client.rbs @@ -1,16 +1,8 @@ -OTS_OWNER: String +# lib/mindee/client.rb module Mindee OTS_OWNER: String - class PageOptions - attr_accessor page_indexes: Array[Integer] - attr_accessor operation: :KEEP_ONLY | :REMOVE - attr_accessor on_min_pages: Integer? - - def initialize: (params: Hash[Symbol | String, untyped]) -> void - end - class ParseOptions attr_accessor all_words: bool attr_accessor full_text: bool diff --git a/sig/mindee/input/sources/base64_input_source.rbs b/sig/mindee/input/sources/base64_input_source.rbs index 0ddae5872..babd5a6f9 100644 --- a/sig/mindee/input/sources/base64_input_source.rbs +++ b/sig/mindee/input/sources/base64_input_source.rbs @@ -4,7 +4,7 @@ module Mindee module Source class Base64InputSource < LocalInputSource def initialize: (String, String, ?repair_pdf: bool) -> void - def read_contents: (?close: bool) -> [String, String, Hash[Symbol, untyped]] + def read_contents: (?close: bool) -> [String, Hash[Symbol, untyped]] end end end diff --git a/sig/mindee/input/sources/local_input_source.rbs b/sig/mindee/input/sources/local_input_source.rbs index f4f14dfab..1fdcf98cd 100644 --- a/sig/mindee/input/sources/local_input_source.rbs +++ b/sig/mindee/input/sources/local_input_source.rbs @@ -4,6 +4,10 @@ module Mindee module Source ALLOWED_MIME_TYPES: Array[String] class LocalInputSource + attr_reader file_mimetype: String + attr_reader filename: String + attr_reader io_stream: StringIO|File + def filename: -> String def file_mimetype: -> String def io_stream: -> StringIO @@ -11,8 +15,9 @@ module Mindee def logger: () -> untyped - def rescue_broken_pdf: (StringIO) -> StringIO + def rescue_broken_pdf: (StringIO|File) -> StringIO def pdf?: -> bool + def apply_page_options: (PageOptions) -> StringIO? def process_pdf: (PageOptions) -> StringIO? def read_contents: (?close: bool) -> [String?, Hash[:filename, String]] def count_pages: -> Integer diff --git a/sig/mindee/page_options.rbs b/sig/mindee/page_options.rbs new file mode 100644 index 000000000..759efe8fa --- /dev/null +++ b/sig/mindee/page_options.rbs @@ -0,0 +1,9 @@ +# lib/mindee/page_options.rb + +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 \ No newline at end of file diff --git a/spec/input/sources/files_handling_spec.rb b/spec/input/sources/files_handling_spec.rb index 46786d59f..22b536469 100644 --- a/spec/input/sources/files_handling_spec.rb +++ b/spec/input/sources/files_handling_spec.rb @@ -10,8 +10,8 @@ file = File.join(DATA_DIR, 'file_types/receipt.jpg') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents - expect(read_f.length).to eq(3) - expect(read_f[1]).to eq(File.read(file, mode: 'rb')) + expect(read_f.length).to eq(2) + expect(read_f[0]).to eq(File.read(file, mode: 'rb')) end end @@ -20,8 +20,8 @@ file = File.join(DATA_DIR, 'file_types/receipt.jpga') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents - expect(read_f.length).to eq(3) - expect(read_f[1]).to eq(File.read(file, mode: 'rb')) + expect(read_f.length).to eq(2) + expect(read_f[0]).to eq(File.read(file, mode: 'rb')) end end @@ -30,8 +30,8 @@ file = File.join(DATA_DIR, 'file_types/receipt.heic') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents - expect(read_f.length).to eq(3) - expect(read_f[1]).to eq(File.read(file, mode: 'rb')) + expect(read_f.length).to eq(2) + expect(read_f[0]).to eq(File.read(file, mode: 'rb')) end end @@ -40,8 +40,8 @@ file = File.join(DATA_DIR, 'file_types/receipt.tif') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents - expect(read_f.length).to eq(3) - expect(read_f[1]).to eq(File.read(file, mode: 'rb')) + expect(read_f.length).to eq(2) + expect(read_f[0]).to eq(File.read(file, mode: 'rb')) end end @@ -50,8 +50,8 @@ file = File.join(DATA_DIR, 'file_types/receipt.tiff') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents - expect(read_f.length).to eq(3) - expect(read_f[1]).to eq(File.read(file, mode: 'rb')) + expect(read_f.length).to eq(2) + expect(read_f[0]).to eq(File.read(file, mode: 'rb')) end end @@ -60,8 +60,8 @@ file = File.join(DATA_DIR, 'file_types/receipt.txt') input = Mindee::Input::Source::Base64InputSource.new(File.read(file), 'receipt.txt') 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", '')) + expect(read_f.length).to eq(2) + expect(read_f[0].gsub("\n", '')).to eq(File.read(file).gsub("\n", '')) end end @@ -71,9 +71,9 @@ input = Mindee::Input::Source::PathInputSource.new(file) 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) - expect(Base64.decode64(read_f[1])).to eq(Base64.decode64(file_contents)) + expect(read_f[0]).to_not eq(Base64.encode64(file_contents)) + expect(read_f.length).to eq(2) + expect(Base64.decode64(read_f[0])).to eq(Base64.decode64(file_contents)) end end @@ -83,9 +83,9 @@ input = Mindee::Input::Source::PathInputSource.new(file) 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) - expect(Base64.decode64(read_f[1])).to eq(Base64.decode64(file_contents)) + expect(read_f[0]).to_not eq(Base64.encode64(file_contents)) + expect(read_f.length).to eq(2) + expect(Base64.decode64(read_f[0])).to eq(Base64.decode64(file_contents)) end end end diff --git a/spec/input/sources/sources_spec.rb b/spec/input/sources/sources_spec.rb index 3ea20f047..3baf8f042 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", repair_pdf: true) - expect(source_doc_fixed.read_contents[1].to_s).to eq(source_doc_original.read_contents[1].to_s) + expect(source_doc_fixed.read_contents[0].to_s).to eq(source_doc_original.read_contents[0].to_s) end.not_to raise_error end end From f2045588ddc58db8dd79c8775d29708a81867ec5 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 5 Aug 2025 15:59:21 +0200 Subject: [PATCH 04/19] add signatures & missing logic (untested) --- lib/mindee/client_v2.rb | 517 +++--------------- lib/mindee/errors/mindee_http_error_v2.rb | 4 +- lib/mindee/http.rb | 2 + lib/mindee/http/api_settings_v2.rb | 4 +- lib/mindee/http/mindee_api_v2.rb | 10 +- lib/mindee/input.rb | 2 + lib/mindee/input/inference_parameters.rb | 58 +- lib/mindee/input/local_response.rb | 11 +- lib/mindee/input/polling_options.rb | 25 +- lib/mindee/parsing/v2.rb | 15 + lib/mindee/parsing/v2/common_response.rb | 2 +- lib/mindee/parsing/v2/error_response.rb | 9 + lib/mindee/parsing/v2/field.rb | 10 + lib/mindee/parsing/v2/field/base_field.rb | 7 +- lib/mindee/parsing/v2/field/dynamic_field.rb | 2 +- .../parsing/v2/field/field_confidence.rb | 6 - .../parsing/v2/field/inference_fields.rb | 11 +- lib/mindee/parsing/v2/field/list_field.rb | 6 +- lib/mindee/parsing/v2/field/object_field.rb | 8 +- lib/mindee/parsing/v2/field/simple_field.rb | 2 +- lib/mindee/parsing/v2/inference.rb | 4 +- sig/custom/mini_magick.rbs | 4 +- sig/mindee/client_v2.rbs | 16 + sig/mindee/errors/mindee_http_error_v2.rbs | 12 + sig/mindee/http/api_settings_v2.rbs | 22 + sig/mindee/http/mindee_api_v2.rbs | 18 + sig/mindee/input/inference_parameters.rbs | 15 + sig/mindee/input/local_response.rbs | 11 +- sig/mindee/input/polling_options.rbs | 12 + sig/mindee/parsing/standard/amount_field.rbs | 10 +- sig/mindee/parsing/standard/date_field.rbs | 12 +- .../standard/payment_details_field.rbs | 13 +- sig/mindee/parsing/v2/common_response.rbs | 11 + sig/mindee/parsing/v2/error_response.rbs | 16 + sig/mindee/parsing/v2/field/base_field.rbs | 16 + sig/mindee/parsing/v2/field/dynamic_field.rbs | 14 + .../parsing/v2/field/field_confidence.rbs | 27 + .../parsing/v2/field/field_location.rbs | 16 + .../parsing/v2/field/inference_fields.rbs | 18 + sig/mindee/parsing/v2/field/list_field.rbs | 20 + sig/mindee/parsing/v2/field/object_field.rbs | 21 + sig/mindee/parsing/v2/field/simple_field.rbs | 16 + sig/mindee/parsing/v2/inference.rbs | 16 + sig/mindee/parsing/v2/inference_file.rbs | 15 + sig/mindee/parsing/v2/inference_model.rbs | 11 + sig/mindee/parsing/v2/inference_response.rbs | 12 + sig/mindee/parsing/v2/inference_result.rbs | 13 + .../parsing/v2/inference_result_options.rbs | 11 + sig/mindee/parsing/v2/job.rbs | 22 + sig/mindee/parsing/v2/job_response.rbs | 12 + sig/mindee/parsing/v2/job_webhook.rbs | 17 + sig/mindee/parsing/v2/raw_text.rbs | 12 + 52 files changed, 632 insertions(+), 544 deletions(-) create mode 100644 sig/mindee/client_v2.rbs create mode 100644 sig/mindee/errors/mindee_http_error_v2.rbs create mode 100644 sig/mindee/http/api_settings_v2.rbs create mode 100644 sig/mindee/http/mindee_api_v2.rbs create mode 100644 sig/mindee/input/inference_parameters.rbs create mode 100644 sig/mindee/input/polling_options.rbs create mode 100644 sig/mindee/parsing/v2/common_response.rbs create mode 100644 sig/mindee/parsing/v2/error_response.rbs create mode 100644 sig/mindee/parsing/v2/field/base_field.rbs create mode 100644 sig/mindee/parsing/v2/field/dynamic_field.rbs create mode 100644 sig/mindee/parsing/v2/field/field_confidence.rbs create mode 100644 sig/mindee/parsing/v2/field/field_location.rbs create mode 100644 sig/mindee/parsing/v2/field/inference_fields.rbs create mode 100644 sig/mindee/parsing/v2/field/list_field.rbs create mode 100644 sig/mindee/parsing/v2/field/object_field.rbs create mode 100644 sig/mindee/parsing/v2/field/simple_field.rbs create mode 100644 sig/mindee/parsing/v2/inference.rbs create mode 100644 sig/mindee/parsing/v2/inference_file.rbs create mode 100644 sig/mindee/parsing/v2/inference_model.rbs create mode 100644 sig/mindee/parsing/v2/inference_response.rbs create mode 100644 sig/mindee/parsing/v2/inference_result.rbs create mode 100644 sig/mindee/parsing/v2/inference_result_options.rbs create mode 100644 sig/mindee/parsing/v2/job.rbs create mode 100644 sig/mindee/parsing/v2/job_response.rbs create mode 100644 sig/mindee/parsing/v2/job_webhook.rbs create mode 100644 sig/mindee/parsing/v2/raw_text.rbs diff --git a/lib/mindee/client_v2.rb b/lib/mindee/client_v2.rb index 2436088f1..a52331053 100644 --- a/lib/mindee/client_v2.rb +++ b/lib/mindee/client_v2.rb @@ -12,415 +12,102 @@ OTS_OWNER = 'mindee' module Mindee - # Class for page options in parse calls. - # - # @!attribute page_indexes [Array[Integer]] Zero-based list of page indexes. - # @!attribute operation [:KEEP_ONLY, :REMOVE] Operation to apply on the document, given the specified page indexes: - # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # * `:REMOVE` - remove the specified pages, and keep all others. - # @!attribute on_min_pages [Integer, nil] Apply the operation only if the document has at least this many pages. - class PageOptions - attr_accessor :page_indexes, :operation, :on_min_pages - - def initialize(params: {}) - params ||= {} - params = params.transform_keys(&:to_sym) - @page_indexes = params.fetch( - :page_indexes, - [] # : Array[Integer] - ) - @operation = params.fetch(:operation, :KEEP_ONLY) - @on_min_pages = params.fetch(:on_min_pages, nil) - end - end - - # Class for configuration options in parse calls. - # - # @!attribute all_words [bool] Whether to include the full text for each page. - # This performs a full OCR operation on the server and will increase response time. - # @!attribute full_text [bool] Whether to include the full OCR text response in compatible APIs. - # This performs a full OCR operation on the server and may increase response time. - # @!attribute close_file [bool] Whether to `close()` the file after parsing it. - # Set to false if you need to access the file after this operation. - # @!attribute page_options [PageOptions, Hash, nil] Page cutting/merge options: - # * `:page_indexes` Zero-based list of page indexes. - # * `:operation` Operation to apply on the document, given the specified page indexes: - # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # * `:REMOVE` - remove the specified pages, and keep all others. - # * `:on_min_pages` Apply the operation only if the document has at least this many pages. - # @!attribute cropper [bool] Whether to include cropper results for each page. - # This performs a cropping operation on the server and will increase response time. - # @!attribute initial_delay_sec [Numeric] Initial delay before polling. Defaults to 2. - # @!attribute delay_sec [Numeric] Delay between polling attempts. Defaults to 1.5. - # @!attribute max_retries [Integer] Maximum number of retries. Defaults to 80. - class ParseOptions - attr_accessor :all_words, :full_text, :close_file, :page_options, :cropper, :rag, - :workflow_id, :initial_delay_sec, :delay_sec, :max_retries - - def initialize(params: {}) - params = params.transform_keys(&:to_sym) - @all_words = params.fetch(:all_words, false) - @full_text = params.fetch(:full_text, false) - @close_file = params.fetch(:close_file, true) - raw_page_options = params.fetch(:page_options, nil) - raw_page_options = PageOptions.new(params: raw_page_options) unless raw_page_options.is_a?(PageOptions) - @page_options = raw_page_options - @cropper = params.fetch(:cropper, false) - @rag = params.fetch(:rag, false) - @workflow_id = params.fetch(:workflow_id, nil) - @initial_delay_sec = params.fetch(:initial_delay_sec, 2) - @delay_sec = params.fetch(:delay_sec, 1.5) - @max_retries = params.fetch(:max_retries, 80) - end - end - - # Class for configuration options in workflow executions. - # - # @!attribute document_alias [String, nil] Alias to give to the document. - # @!attribute priority [Symbol, nil] Priority to give to the document. - # @!attribute full_text [bool] Whether to include the full OCR text response in compatible APIs. - # This performs a full OCR operation on the server and may increase response time. - # @!attribute public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without - # requiring authentication. - # @!attribute rag [bool, nil] Whether to enable Retrieval-Augmented Generation. - # @!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 close_file [bool, nil] Whether to close the file after sending it. Defaults to true. - class WorkflowOptions - attr_accessor :document_alias, :priority, :full_text, :public_url, :page_options, :rag, :close_file - - 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) - @rag = params.fetch(:rag, nil) - raw_page_options = params.fetch(:page_options, nil) - raw_page_options = PageOptions.new(params: raw_page_options) unless raw_page_options.is_a?(PageOptions) - @page_options = raw_page_options - @close_file = params.fetch(:close_file, true) - end - end - # Mindee API Client. # See: https://developers.mindee.com/docs - class Client + class ClientV2 + # @return [HTTP::MindeeApiV2] + private attr_reader :mindee_api + # @param api_key [String] def initialize(api_key: '') - @api_key = api_key + @mindee_api = Mindee::HTTP::MindeeApiV2.new(api_key) end - # Enqueue a document for parsing and automatically try to retrieve it if needed. - # - # Accepts options either as a Hash or as a ParseOptions struct. - # - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] - # @param product_class [Mindee::Inference] The class of the product. - # @param endpoint [Mindee::HTTP::Endpoint, nil] Endpoint of the API. - # @param options [Hash] A hash of options to configure the parsing behavior. Possible keys: - # * `:all_words` [bool] Whether to extract all the words on each page. - # This performs a full OCR operation on the server and will increase response time. - # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. - # This performs a full OCR operation on the server and may increase response time. - # * `:close_file` [bool] Whether to `close()` the file after parsing it. - # Set to false if you need to access the file after this operation. - # * `:page_options` [Hash, nil] Page cutting/merge options: - # - `:page_indexes` [Array] Zero-based list of page indexes. - # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: - # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # - `:REMOVE` - remove the specified pages, and keep all others. - # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. - # * `:cropper` [bool, nil] Whether to include cropper results for each page. - # This performs a cropping operation on the server and will increase response time. - # * `:initial_delay_sec` [Numeric] Initial delay before polling. Defaults to 2. - # * `:delay_sec` [Numeric] Delay between polling attempts. Defaults to 1.5. - # * `:max_retries` [Integer] Maximum number of retries. Defaults to 80. - # @param enqueue [bool] Whether to enqueue the file. - # @return [Mindee::Parsing::Common::ApiResponse] - def parse(input_source, product_class, endpoint: nil, options: {}, enqueue: true) - opts = normalize_parse_options(options) - process_pdf_if_required(input_source, opts) if input_source.is_a?(Input::Source::LocalInputSource) - endpoint ||= initialize_endpoint(product_class) - - if enqueue && product_class.has_async - enqueue_and_parse(input_source, product_class, endpoint, opts) - else - parse_sync(input_source, product_class, endpoint, opts) - end + # Retrieves an inference. + # @param inference_id [String] + # @return [Mindee::Parsing::V2::InferenceResponse] + def get_inference(inference_id) + @mindee_api.req_get_inference(inference_id) 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` [bool] Whether to extract all the words on each page. - # This performs a full OCR operation on the server and will increase response time. - # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. - # This performs a full OCR operation on the server and may increase response time. - # * `:close_file` [bool] Whether to `close()` the file after parsing it. - # Set to false if you need to access the file after this operation. - # * `:page_options` [Hash, nil] Page cutting/merge options: - # - `:page_indexes` [Array] Zero-based list of page indexes. - # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: - # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # - `:REMOVE` - remove the specified pages, and keep all others. - # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. - # * `:cropper` [bool, nil] Whether to include cropper results for each page. - # This performs a cropping operation on the server and will increase response time. - # @return [Mindee::Parsing::Common::ApiResponse] - def parse_sync(input_source, product_class, endpoint, options) - logger.debug("Parsing document as '#{endpoint.url_root}'") - - prediction, raw_http = endpoint.predict( - input_source, - options - ) - - Mindee::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http.to_s) + # Retrieves an inference. + # @param job_id [String] + # @return [Mindee::Parsing::V2::JobResponse] + def get_job(job_id) + @mindee_api.req_get_job(job_id) end # Enqueue a document for async parsing # # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # The source of the input document (local file or URL). - # @param product_class [Mindee::Inference] The class of the product. - # @param options [Hash] A hash of options to configure the enqueue behavior. Possible keys: - # * `:endpoint` [HTTP::Endpoint, nil] Endpoint of the API. - # Doesn't need to be set in the case of OTS APIs. - # * `:all_words` [bool] Whether to extract all the words on each page. - # This performs a full OCR operation on the server and will increase response time. - # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. - # This performs a full OCR operation on the server and may increase response time. - # * `:close_file` [bool] Whether to `close()` the file after parsing it. - # Set to false if you need to access the file after this operation. - # * `:page_options` [Hash, nil] Page cutting/merge options: - # - `:page_indexes` [Array] Zero-based list of page indexes. - # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: - # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # - `:REMOVE` - remove the specified pages, and keep all others. - # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. - # * `:cropper` [bool] Whether to include cropper results for each page. - # This performs a cropping operation on the server and will increase response time. - # * `:rag` [bool] Whether to enable Retrieval-Augmented Generation. Only works if a Workflow ID is provided. - # * `:workflow_id` [String, nil] ID of the workflow to use. - # @param endpoint [Mindee::HTTP::Endpoint] Endpoint of the API. - # @return [Mindee::Parsing::Common::ApiResponse] - def enqueue(input_source, product_class, endpoint: nil, options: {}) - opts = normalize_parse_options(options) - endpoint ||= initialize_endpoint(product_class) - logger.debug("Enqueueing document as '#{endpoint.url_root}'") - - prediction, raw_http = endpoint.predict_async( - input_source, - opts - ) - Mindee::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http.to_json) - end + # @param params [Hash, InferenceParameters] + # @return [Mindee::Parsing::V2::JobResponse] + def enqueue_inference(input_source, params) + normalized_params = normalize_inference_parameters(params) + logger.debug("Enqueueing document to model '#{normalized_params.model_id}'.") - # Parses a queued document - # - # @param job_id [String] ID of the job (queue) to poll from - # @param product_class [Mindee::Inference] class of the product - # @param endpoint [HTTP::Endpoint, nil] Endpoint of the API - # Doesn't need to be set in the case of OTS APIs. - # - # @return [Mindee::Parsing::Common::ApiResponse] - def parse_queued(job_id, product_class, endpoint: nil) - 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.to_json) + @mindee_api.req_post_inference_enqueue(input_source, normalized_params) end # Enqueue a document for async parsing and automatically try to retrieve it # # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # The source of the input document (local file or URL). - # @param product_class [Mindee::Inference] The class of the product. - # @param options [Hash] A hash of options to configure the parsing behavior. Possible keys: - # * `:endpoint` [HTTP::Endpoint, nil] Endpoint of the API. - # Doesn't need to be set in the case of OTS APIs. - # * `:all_words` [bool] Whether to extract all the words on each page. - # This performs a full OCR operation on the server and will increase response time. - # * `:full_text` [bool] Whether to include the full OCR text response in compatible APIs. - # This performs a full OCR operation on the server and may increase response time. - # * `:close_file` [bool] Whether to `close()` the file after parsing it. - # Set to false if you need to access the file after this operation. - # * `:page_options` [Hash, nil] Page cutting/merge options: - # - `:page_indexes` [Array] Zero-based list of page indexes. - # - `:operation` [Symbol] Operation to apply on the document, given the `page_indexes` specified: - # - `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # - `:REMOVE` - remove the specified pages, and keep all others. - # - `:on_min_pages` [Integer] Apply the operation only if the document has at least this many pages. - # * `:cropper` [bool, nil] Whether to include cropper results for each page. - # This performs a cropping operation on the server and will increase response time. - # * `:rag` [bool] Whether to enable Retrieval-Augmented Generation. Only works if a Workflow ID is provided. - # * `:workflow_id` [String, nil] ID of the workflow to use. - # * `:initial_delay_sec` [Numeric] Initial delay before polling. Defaults to 2. - # * `:delay_sec` [Numeric] Delay between polling attempts. Defaults to 1.5. - # * `:max_retries` [Integer] Maximum number of retries. Defaults to 80. - # @param endpoint [Mindee::HTTP::Endpoint] Endpoint of the API. - # @return [Mindee::Parsing::Common::ApiResponse] - def enqueue_and_parse(input_source, product_class, endpoint, options) - validate_async_params(options.initial_delay_sec, options.delay_sec, options.max_retries) - enqueue_res = enqueue(input_source, product_class, endpoint: endpoint, options: options) - job = enqueue_res.job or raise Errors::MindeeAPIError, 'Expected job to be present' - job_id = job.id - - sleep(options.initial_delay_sec) - polling_attempts = 1 - logger.debug("Successfully enqueued document with job id: '#{job_id}'") - 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' - 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 + # @param params [Hash, InferenceParameters] Parameters for the inference. + # @return [Mindee::Parsing::V2::InferenceResponse] + def enqueue_and_get_inference(input_source, params) + normalized_params = normalize_inference_parameters(params) + validate_async_params(normalized_params.initial_delay_sec, normalized_params.delay_sec, + normalized_params.max_retries) + enqueue_response = enqueue_inference(input_source, normalized_params) + + if enqueue_response.job.id.nil? || enqueue_response.job.id.empty? + logger.error("Failed enqueueing:\n#{enqueue_response.raw_http}") + raise Mindee::Errors::MindeeError, 'Enqueueing of the document failed.' end - 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)" + queue_id = enqueue_response.job.id + logger.debug("Successfully enqueued document with job id: #{queue_id}.") + + sleep(normalized_params.polling_options.initial_delay_sec) + retry_counter = 1 + poll_results = get_job(queue_id) + + while retry_counter < normalized_params.polling_options.max_retries + if poll_results.job.status == 'Failed' + break + elsif poll_results.job.status == 'Processed' + return get_inference(poll_results.job.id) + end + + logger.debug( + "Polling server for parsing result with queueId: #{queue_id}.\n" \ + "Attempt n°#{retry_counter}/#{normalized_params.polling_options.max_retries}.\n" \ + "Job status: #{poll_results.job.status}." + ) + + sleep(normalized_params.polling_options.delay_sec) + poll_results = get_job(queue_id) + retry_counter += 1 end - queue_res - end - - # 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 workflow_id [String] - # @param options [Hash, WorkflowOptions] Options to configure workflow behavior. Possible keys: - # * `document_alias` [String, nil] Alias to give to the document. - # * `priority` [Symbol, nil] Priority to give to the document. - # * `full_text` [bool] Whether to include the full OCR text response in compatible APIs. - # * `rag` [bool, nil] Whether to enable Retrieval-Augmented Generation. - # - # * `public_url` [String, nil] A unique, encrypted URL for accessing the document validation interface without - # requiring authentication. - # * `page_options` [Hash, nil] Page cutting/merge options: - # * `:page_indexes` Zero-based list of page indexes. - # * `:operation` Operation to apply on the document, given the `page_indexes specified: - # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. - # * `:REMOVE` - remove the specified pages, and keep all others. - # * `:on_min_pages` Apply the operation only if document has at least this many pages. - # @return [Mindee::Parsing::Common::WorkflowResponse] - def execute_workflow(input_source, workflow_id, options: {}) - opts = options.is_a?(WorkflowOptions) ? options : WorkflowOptions.new(params: options) - if opts.respond_to?(:page_options) && input_source.is_a?(Input::Source::LocalInputSource) - process_pdf_if_required(input_source, opts) + error = poll_results.job.error + unless error.nil? + err_to_raise = Mindee::Errors::MindeeHTTPErrorV2.new(error) + # NOTE: purposefully decoupled from the line above, otherwise rubocop thinks `error` is a `message` param. + raise err_to_raise 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, - opts - ) - - Mindee::Parsing::Common::WorkflowResponse.new(Product::Universal::Universal, prediction, raw_http) - end - - # Load a prediction. - # - # @param product_class [Mindee::Inference] class of the product - # @param local_response [Mindee::Input::LocalResponse] - # @return [Mindee::Parsing::Common::ApiResponse] - def load_prediction(product_class, local_response) - raise Errors::MindeeAPIError, 'Expected LocalResponse to not be nil.' if local_response.nil? - - response_hash = local_response.as_hash || {} - raise Errors::MindeeAPIError, 'Expected LocalResponse#as_hash to return a hash.' if response_hash.nil? - - Mindee::Parsing::Common::ApiResponse.new(product_class, response_hash, response_hash.to_json) - rescue KeyError, Errors::MindeeAPIError - raise Errors::MindeeInputError, 'No prediction found in local response.' - end - - # Load a document from an absolute path, as a string. - # @param input_path [String] Path of file to open - # @param repair_pdf [bool] Attempts to fix broken pdf if true - # @return [Mindee::Input::Source::PathInputSource] - 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 repair_pdf [bool] Attempts to fix broken pdf if true - # @return [Mindee::Input::Source::BytesInputSource] - 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 repair_pdf [bool] Attempts to fix broken pdf if true - # @return [Mindee::Input::Source::Base64InputSource] - 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 repair_pdf [bool] Attempts to fix broken pdf if true - # @return [Mindee::Input::Source::FileInputSource] - 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] - def source_from_url(url) - Input::Source::URLInputSource.new(url) - end - - # Creates a custom endpoint with the given values. - # Do not set for standard (off the shelf) endpoints. - # - # @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. - # - # @param account_name [String] For custom endpoints, your account or organization username on the API Builder. - # This is normally not required unless you have a custom endpoint which has the same name as a - # standard (off the shelf) endpoint. - # @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::Universal::Universal, - endpoint_name: endpoint_name, - account_name: account_name, - version: version - ) + sec_count = normalized_params.polling_options.delay_sec * retry_counter + raise Mindee::Errors::MindeeError, + "Asynchronous parsing request timed out after #{sec_count} seconds" end # Validates the parameters for async auto-polling - # @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. + # @param initial_delay_sec [Integer, Float] initial delay before polling + # @param delay_sec [Integer, Float] delay between polling attempts + # @param max_retries [Integer] maximum amount of retries. def validate_async_params(initial_delay_sec, delay_sec, max_retries) min_delay_sec = 1 min_initial_delay_sec = 1 @@ -437,73 +124,13 @@ def validate_async_params(initial_delay_sec, delay_sec, max_retries) raise ArgumentError, "Cannot set auto-poll retries to less than #{min_retries}" if max_retries < min_retries end - # Creates an endpoint with the given values. Raises an error if the endpoint is invalid. - # @param product_class [Mindee::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. - # - # @param account_name [String] For custom endpoints, your account or organization username on the API Builder. - # This is normally not required unless you have a custom endpoint which has the same name as a - # standard (off the shelf) endpoint. - # @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::Universal::Universal - raise Mindee::Errors::MindeeConfigurationError, 'Missing argument endpoint_name when using custom class' - end - - endpoint_name = fix_endpoint_name(product_class, endpoint_name) - account_name = fix_account_name(account_name) - version = fix_version(product_class, version) - - HTTP::Endpoint.new(account_name, endpoint_name, version, api_key: @api_key) - end - - def fix_endpoint_name(product_class, endpoint_name) - endpoint_name.nil? || endpoint_name.empty? ? product_class.endpoint_name : endpoint_name - end - - def fix_account_name(account_name) - if account_name.nil? || account_name.empty? - logger.info("No account name provided, #{OTS_OWNER} will be used by default.") - return OTS_OWNER - end + # If needed, converts the parsing options provided as a hash into a proper InferenceParameters object. + # @param params [Hash, InferenceParameters] Params. + # @return [InferenceParameters] + def normalize_inference_parameters(params) + return params if params.is_a?(InferenceParameters) - account_name + InferenceParameters.new(params: params) end - - def fix_version(product_class, version) - return version unless version.nil? || version.empty? - - if product_class.endpoint_version.nil? || product_class.endpoint_version.empty? - logger.debug('No version provided for a custom build, will attempt to poll version 1 by default.') - return '1' - end - product_class.endpoint_version - end - - # If needed, converts the parsing options provided as a hash into a proper ParseOptions object. - # @param options [Hash, ParseOptions] Options. - # @return [ParseOptions] - def normalize_parse_options(options) - return options if options.is_a?(ParseOptions) - - ParseOptions.new(params: options) - end - - # Processes a PDF if parameters were provided. - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] - # @param opts [ParseOptions] - def process_pdf_if_required(input_source, opts) - return unless input_source.is_a?(Mindee::Input::Source::LocalInputSource) && - opts.page_options.on_min_pages && - input_source.pdf? - - input_source.process_pdf(opts.page_options) - end - - private :parse_sync, :validate_async_params, :initialize_endpoint, :fix_endpoint_name, :fix_version, - :fix_account_name, :process_pdf_if_required, :normalize_parse_options end end diff --git a/lib/mindee/errors/mindee_http_error_v2.rb b/lib/mindee/errors/mindee_http_error_v2.rb index e4914298b..e7b3605f7 100644 --- a/lib/mindee/errors/mindee_http_error_v2.rb +++ b/lib/mindee/errors/mindee_http_error_v2.rb @@ -11,9 +11,9 @@ class MindeeHTTPErrorV2 < MindeeError # @return [String] attr_reader :detail - # @param http_error [Hash] - # @param code [Integer] + # @param http_error [Hash, Parsing::V2::ErrorResponse] def initialize(http_error) + http_error = http_error.as_hash if http_error.is_a?(Parsing::V2::ErrorResponse) @status = http_error['status'] @detail = http_error['detail'] super("HTTP error: #{@status} - #{@detail}") diff --git a/lib/mindee/http.rb b/lib/mindee/http.rb index 5b5a0d606..9f0e041be 100644 --- a/lib/mindee/http.rb +++ b/lib/mindee/http.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative 'http/api_settings_v2' require_relative 'http/endpoint' require_relative 'http/http_error_handler' +require_relative 'http/mindee_api_v2' require_relative 'http/workflow_endpoint' diff --git a/lib/mindee/http/api_settings_v2.rb b/lib/mindee/http/api_settings_v2.rb index e7a387287..00b74e155 100644 --- a/lib/mindee/http/api_settings_v2.rb +++ b/lib/mindee/http/api_settings_v2.rb @@ -46,7 +46,9 @@ def initialize(api_key: '') @user_agent = USER_AGENT end - # Checks API key + # Checks API key for a value. + # @return + # @raise [Errors::MindeeAPIError] Raises if the api key is empty or nil. def check_api_key return unless @api_key.nil? || @api_key.empty? diff --git a/lib/mindee/http/mindee_api_v2.rb b/lib/mindee/http/mindee_api_v2.rb index 600d79779..c9a19f517 100644 --- a/lib/mindee/http/mindee_api_v2.rb +++ b/lib/mindee/http/mindee_api_v2.rb @@ -19,7 +19,7 @@ def initialize(api_key = nil) # Sends a file to the inference queue. # - # @param input_source [Input::Source::BaseSource] + # @param input_source [Input::Source::LocalInputSource, Input::Source::URLInputSource] # @param params [Input::InferenceParameters] # @return [Mindee::Parsing::V2::JobResponse] # @raise [Mindee::Errors::MindeeHttpErrorV2] @@ -60,7 +60,7 @@ def req_get_job(job_id) # Converts an HTTP response to a parsed response object. # - # @param response [Net::HTTP::Response, nil] + # @param response [Net::HTTPResponse, nil] # @return [Hash] # @raise Throws if the server returned an error. def process_response(response) @@ -79,7 +79,7 @@ def process_response(response) # Polls a queue for either a result or a job. # @param url [String] URL, passed as a string. - # @return [Net::HTTP::Response] + # @return [Net::HTTPResponse] def poll(url) uri = URI(url) headers = { @@ -98,7 +98,7 @@ def poll(url) # Polls the API for the status of a job. # # @param job_id [String] ID of the job. - # @return [Net::HTTP::Response] + # @return [Net::HTTPResponse] def inference_job_req_get(job_id) poll("#{@url_root}/jobs/#{job_id}") end @@ -106,7 +106,7 @@ def inference_job_req_get(job_id) # Polls the API for the result of an inference. # # @param queue_id [String] ID of the queue. - # @return [Net::HTTP::Response] + # @return [Net::HTTPResponse] def inference_result_req_get(queue_id) poll("#{@url_root}/inferences/#{queue_id}") end diff --git a/lib/mindee/input.rb b/lib/mindee/input.rb index e83d1dcfe..8afb9bfac 100644 --- a/lib/mindee/input.rb +++ b/lib/mindee/input.rb @@ -1,3 +1,5 @@ # frozen_string_literal: true +require_relative 'input/inference_parameters' +require_relative 'input/polling_options' require_relative 'input/sources' diff --git a/lib/mindee/input/inference_parameters.rb b/lib/mindee/input/inference_parameters.rb index 0897ee58d..ed2570b50 100644 --- a/lib/mindee/input/inference_parameters.rb +++ b/lib/mindee/input/inference_parameters.rb @@ -3,46 +3,48 @@ module Mindee module Input # Parameters to set when sending a file for inference. - # - # Rough equivalent of the Python dataclass: - # mindee.input.inference_parameters.InferenceParameters class InferenceParameters # @return [String] ID of the model (required). attr_reader :model_id # @return [Boolean, nil] Enable Retrieval-Augmented Generation. - attr_accessor :rag + attr_reader :rag # @return [String, nil] Optional alias for the file. - attr_accessor :file_alias + attr_reader :file_alias # @return [Array, nil] Optional list of webhooks IDs to propagate the API response to. - attr_accessor :webhook_ids + attr_reader :webhook_ids - # @return [PollingOptions, nil] Options for polling. Set only if having timeout issues. - attr_accessor :polling_options + # @return [PollingOptions] Options for polling. Set only if having timeout issues. + attr_reader :polling_options # @return [Boolean, nil] Whether to close the file after parsing. - attr_accessor :close_file - - # @param model_id [String] ID of the model (required). - # @param rag [Boolean] Enable RAG (default: false). - # @param file_alias [String, nil] Optional alias (default: nil). - # @param webhook_ids [Array, nil] Webhook IDs (default: nil). - # @param polling_options [PollingOptions, nil] Polling options (default: nil). - # @param close_file [Boolean] Close the file after parsing (default: true). - def initialize(model_id:, - rag: false, - file_alias: nil, - webhook_ids: nil, - polling_options: nil, - close_file: true) - @model_id = model_id - @rag = rag - @file_alias = file_alias - @webhook_ids = webhook_ids.nil? ? [] : webhook_ids - @polling_options = polling_options.nil? ? PollingOptions.new : polling_options - @close_file = close_file.nil? || close_file + attr_reader :close_file + + # @param params [Hash] + def initialize(params: {}) + params = params.transform_keys(&:to_sym) + + if params.empty? || params[:model_id].nil? || params[:model_id].empty? + raise Errors::MindeeInputError, 'Model ID is required.' + end + + @model_id = params.fetch(:model_id) + @rag = params.fetch(:rag, false) + @file_alias = params.fetch(:file_alias, nil) + @webhook_ids = params.fetch(:webhook_ids, []) + polling_options = params.fetch(:page_options, PollingOptions.new) + if polling_options.is_a?(Hash) + polling_options = polling_options.transform_keys(&:to_sym) + @polling_options = PollingOptions.new( + initial_delay_sec: polling_options.fetch(:initial_delay_sec, 2.0), + delay_sec: polling_options.fetch(:delay_sec, 1.5), + max_retries: polling_options.fetch(:max_retries, 80) + ) + end + @polling_options = polling_options + @close_file = params.fetch(:close_file, true) end end end diff --git a/lib/mindee/input/local_response.rb b/lib/mindee/input/local_response.rb index e4b4df299..e1cc2306e 100644 --- a/lib/mindee/input/local_response.rb +++ b/lib/mindee/input/local_response.rb @@ -62,11 +62,20 @@ def get_hmac_signature(secret_key) end # @param secret_key [String] Secret key, either a string or a byte/byte array. - # @param signature [String] + # @param signature [String] Signature to match # @return [bool] def valid_hmac_signature?(secret_key, signature) signature == get_hmac_signature(secret_key) end + + # Deserializes a loaded response + # @param response_class [Parsing::V2::JobResponse, Parsing::V2::InferenceResponse] class to return. + # @return [Parsing::V2::JobResponse, Parsing::V2::InferenceResponse] + def deserialize_response(response_class) + response_class.new(as_hash) + rescue StandardError + raise Errors::MindeeInputError, 'Invalid response provided.' + end end end end diff --git a/lib/mindee/input/polling_options.rb b/lib/mindee/input/polling_options.rb index 0e9e89611..8cba695b3 100644 --- a/lib/mindee/input/polling_options.rb +++ b/lib/mindee/input/polling_options.rb @@ -3,26 +3,23 @@ module Mindee module Input # Options for asynchronous polling. - # - # Rough equivalent of: - # mindee.input.polling_options.PollingOptions (Python) class PollingOptions - # Initial delay before the first polling attempt (in seconds). - attr_accessor :initial_delay_sec + # @return [Integer, Float] Initial delay before the first polling attempt (in seconds). + attr_reader :initial_delay_sec - # Delay between each polling attempt (in seconds). - attr_accessor :delay_sec + # @return [Integer, Float] Delay between each polling attempt (in seconds). + attr_reader :delay_sec - # Total number of polling attempts. - attr_accessor :max_retries + # @return [Integer] Total number of polling attempts. + attr_reader :max_retries - # @param initial_delay_sec [Float] Initial delay before the first attempt (default: 2.0) - # @param delay_sec [Float] Delay between attempts (default: 1.5) - # @param max_retries [Integer] Maximum number of retries (default: 80) + # @param initial_delay_sec [Float] Initial delay before the first attempt (default:2.0). + # @param delay_sec [Float] Delay between attempts (default: 1.5). + # @param max_retries [Integer] Maximum number of retries (default:80). def initialize(initial_delay_sec: 2.0, delay_sec: 1.5, max_retries: 80) @initial_delay_sec = initial_delay_sec - @delay_sec = delay_sec - @max_retries = max_retries + @delay_sec = delay_sec + @max_retries = max_retries end end end diff --git a/lib/mindee/parsing/v2.rb b/lib/mindee/parsing/v2.rb index e69de29bb..746d0a4b2 100644 --- a/lib/mindee/parsing/v2.rb +++ b/lib/mindee/parsing/v2.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require_relative 'v2/common_response' +require_relative 'v2/error_response' +require_relative 'v2/field' +require_relative 'v2/inference' +require_relative 'v2/inference_file' +require_relative 'v2/inference_model' +require_relative 'v2/inference_response' +require_relative 'v2/inference_result' +require_relative 'v2/inference_result_options' +require_relative 'v2/job' +require_relative 'v2/job_response' +require_relative 'v2/job_webhook' +require_relative 'v2/raw_text' diff --git a/lib/mindee/parsing/v2/common_response.rb b/lib/mindee/parsing/v2/common_response.rb index 70053d1ae..6a30e799a 100644 --- a/lib/mindee/parsing/v2/common_response.rb +++ b/lib/mindee/parsing/v2/common_response.rb @@ -5,7 +5,7 @@ module Parsing module V2 # Base class for inference and job responses on the V2 API. class CommonResponse - # @return [String] + # @return [Hash] attr_reader :raw_http # @param http_response [Hash] diff --git a/lib/mindee/parsing/v2/error_response.rb b/lib/mindee/parsing/v2/error_response.rb index dd12faf46..a9280e765 100644 --- a/lib/mindee/parsing/v2/error_response.rb +++ b/lib/mindee/parsing/v2/error_response.rb @@ -21,6 +21,15 @@ def initialize(server_response) def to_s "Error\n=====\n:Status: #{@status}\n:Detail: #{@detail}" end + + # Hash representation + # @return [Hash] Hash representation of the object. + def as_hash + { + status: @status, + detail: @detail, + } + end end end end diff --git a/lib/mindee/parsing/v2/field.rb b/lib/mindee/parsing/v2/field.rb index e69de29bb..5ba30bf44 100644 --- a/lib/mindee/parsing/v2/field.rb +++ b/lib/mindee/parsing/v2/field.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require_relative 'field/base_field' +require_relative 'field/dynamic_field' +require_relative 'field/field_confidence' +require_relative 'field/field_location' +require_relative 'field/inference_fields' +require_relative 'field/list_field' +require_relative 'field/object_field' +require_relative 'field/simple_field' diff --git a/lib/mindee/parsing/v2/field/base_field.rb b/lib/mindee/parsing/v2/field/base_field.rb index d0bd97c56..e33c69f0e 100644 --- a/lib/mindee/parsing/v2/field/base_field.rb +++ b/lib/mindee/parsing/v2/field/base_field.rb @@ -10,16 +10,13 @@ class BaseField attr_reader :indent_level # @return [FieldConfidence, nil] Confidence score for the field. - attr_accessor :confidence + attr_reader :confidence # @param raw_prediction [Hash] Raw prediction hash. # @param indent_level [Integer] Level of indentation for rst display. def initialize(raw_prediction, indent_level = 0) @indent_level = indent_level - @confidence = nil - - # Process confidence if present - @confidence = raw_prediction['confidence'] if raw_prediction.key?('confidence') + @confidence = raw_prediction['confidence'] ? raw_prediction.key?('confidence') : nil end # Factory method to create appropriate field types. diff --git a/lib/mindee/parsing/v2/field/dynamic_field.rb b/lib/mindee/parsing/v2/field/dynamic_field.rb index 155457e64..4ae4b3654 100644 --- a/lib/mindee/parsing/v2/field/dynamic_field.rb +++ b/lib/mindee/parsing/v2/field/dynamic_field.rb @@ -7,7 +7,7 @@ module Field # Extension of the base field class for V2 fields, with location data. class DynamicField < BaseField # @return [Array, nil] List of possible locations for a field. - attr_accessor :locations + attr_reader :locations # @param raw_prediction [Hash] Raw prediction hash. # @param indent_level [Integer] Level of indentation for rst display. diff --git a/lib/mindee/parsing/v2/field/field_confidence.rb b/lib/mindee/parsing/v2/field/field_confidence.rb index d93d7b0dd..3a13c68b2 100644 --- a/lib/mindee/parsing/v2/field/field_confidence.rb +++ b/lib/mindee/parsing/v2/field/field_confidence.rb @@ -71,12 +71,6 @@ def ==(other) other.is_a?(FieldConfidence) && @value == other.value end - # Hash code for the confidence level. - # @return [Integer] Hash code based on the value. - def hash - @value.hash - end - # Make instances comparable and hashable alias eql? == diff --git a/lib/mindee/parsing/v2/field/inference_fields.rb b/lib/mindee/parsing/v2/field/inference_fields.rb index 9d2169286..5a9f9b1f3 100644 --- a/lib/mindee/parsing/v2/field/inference_fields.rb +++ b/lib/mindee/parsing/v2/field/inference_fields.rb @@ -48,10 +48,13 @@ def respond_to_missing?(method_name, include_private = false) key?(method_name.to_s) || super end + # rubocop:disable Metrics/CyclomaticComplexity + # rubocop:disable Metrics/PerceivedComplexity # Convert the fields to a string representation. - # @param indent [Integer, nil] Optional indentation level. + # @param original_indent [Integer, nil] Optional indentation level. # @return [String] String representation of all fields. - def to_s(indent = nil) + def to_s(original_indent = nil) + indent = indent.nil? ? 0 : original_indent return '' if empty? indent ||= @indent_level @@ -74,6 +77,8 @@ def to_s(indent = nil) if defined?(field_value.value) && field_value.value && !field_value.value.to_s.empty? line += " #{field_value.value}" end + else + logger.debug("Unknown value was passed to the field creator: #{field_key} : #{field_value}") end lines << line @@ -81,6 +86,8 @@ def to_s(indent = nil) lines.join("\n").rstrip end + # rubocop:enable Metrics/CyclomaticComplexity + # rubocop:enable Metrics/PerceivedComplexity end end end diff --git a/lib/mindee/parsing/v2/field/list_field.rb b/lib/mindee/parsing/v2/field/list_field.rb index 34dea3e3d..ebc7d6331 100644 --- a/lib/mindee/parsing/v2/field/list_field.rb +++ b/lib/mindee/parsing/v2/field/list_field.rb @@ -7,8 +7,8 @@ module Parsing module V2 module Field # A field containing a list of other fields. - class ListField < BaseField - # @return [Array] Items contained in the list. + class ListField < DynamicField + # @return [Array] Items contained in the list. attr_reader :items # @param server_response [Hash] Raw server response hash. @@ -67,7 +67,7 @@ def length # Iterate over the items in the list. # @yield [BaseField] Each item in the list. - # @return [Enumerator] If no block is given. + # @return [Array, Enumerator] If no block is given. def each(&block) return @items.to_enum unless block_given? diff --git a/lib/mindee/parsing/v2/field/object_field.rb b/lib/mindee/parsing/v2/field/object_field.rb index 7f290e4df..fe415f085 100644 --- a/lib/mindee/parsing/v2/field/object_field.rb +++ b/lib/mindee/parsing/v2/field/object_field.rb @@ -12,12 +12,12 @@ class ObjectField < DynamicField # @return [InferenceFields] Fields contained in the object. attr_reader :fields - # @param server_response [Hash] Raw server response hash. + # @param raw_prediction [Hash] Raw server response hash. # @param indent_level [Integer] Level of indentation for rst display. - def initialize(server_response, indent_level = 0) + def initialize(raw_prediction, indent_level = 0) super - inner_fields = server_response.fetch('fields', server_response) + inner_fields = raw_prediction.fetch('fields', raw_prediction) @fields = InferenceFields.new(inner_fields, @indent_level + 1) end @@ -80,7 +80,7 @@ def multi_str # Allow dot notation access to nested fields. # @param method_name [Symbol] The method name (field key). - # @return [BaseField, nil] The field or nil if not found. + # @return [ObjectField, nil] The field or nil if not found. def method_missing(method_name, ...) if @fields.respond_to?(method_name) @fields.send(method_name, ...) diff --git a/lib/mindee/parsing/v2/field/simple_field.rb b/lib/mindee/parsing/v2/field/simple_field.rb index 42429482b..385dc5292 100644 --- a/lib/mindee/parsing/v2/field/simple_field.rb +++ b/lib/mindee/parsing/v2/field/simple_field.rb @@ -9,7 +9,7 @@ module Field # A simple field with a scalar value. class SimpleField < DynamicField # @return [String, Integer, Float, Boolean, nil] Value contained in the field. - attr_accessor :value + attr_reader :value # @param server_response [Hash] Raw server response hash. # @param indent_level [Integer] Level of indentation for rst display. diff --git a/lib/mindee/parsing/v2/inference.rb b/lib/mindee/parsing/v2/inference.rb index f7666d846..c111c7a45 100644 --- a/lib/mindee/parsing/v2/inference.rb +++ b/lib/mindee/parsing/v2/inference.rb @@ -18,7 +18,7 @@ class Inference attr_reader :file # @return [InferenceResult] Result contents. attr_reader :result - # @return [String, nil] Identifier of the inference (when provided by API). + # @return [String] Identifier of the inference (when provided by API). attr_reader :id # @param server_response [Hash] Hash representation of the JSON returned by the service. @@ -29,7 +29,7 @@ def initialize(server_response) @file = InferenceFile.new(server_response['file']) @result = InferenceResult.new(server_response['result']) - @id = server_response['id'] if server_response.key?('id') + @id = server_response['id'] end # RST-style string representation (keeps parity with TS implementation). diff --git a/sig/custom/mini_magick.rbs b/sig/custom/mini_magick.rbs index d52fbfad1..11425857d 100644 --- a/sig/custom/mini_magick.rbs +++ b/sig/custom/mini_magick.rbs @@ -1,8 +1,8 @@ # 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 format: (String, Integer?, ?Hash[Symbol, untyped]?) -> Net::BufferedIO + def self.format: (String, Integer?, ?Hash[Symbol, untyped]?) -> Net::BufferedIO def self.quality: (String) -> Net::BufferedIO def self.crop: (String) -> Net::BufferedIO def self.height: () -> Integer diff --git a/sig/mindee/client_v2.rbs b/sig/mindee/client_v2.rbs new file mode 100644 index 000000000..fbcc2f858 --- /dev/null +++ b/sig/mindee/client_v2.rbs @@ -0,0 +1,16 @@ +# lib/mindee/client_v2.rb + +OTS_OWNER: String +module Mindee + class ClientV2 + attr_reader mindee_api: HTTP::MindeeApiV2 + + def initialize: (?api_key: String) -> void + def get_inference: (String) -> Parsing::V2::InferenceResponse + def get_job: (String) -> Parsing::V2::JobResponse + def enqueue_inference: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::InferenceParameters) -> Parsing::V2::JobResponse + def enqueue_and_get_inference: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::InferenceParameters) -> Parsing::V2::InferenceResponse + def validate_async_params: (Integer | Float, Integer | Float, Integer) -> void + def normalize_inference_parameters: (Hash[String | Symbol, untyped] | Input::InferenceParameters) -> Input::InferenceParameters + end +end diff --git a/sig/mindee/errors/mindee_http_error_v2.rbs b/sig/mindee/errors/mindee_http_error_v2.rbs new file mode 100644 index 000000000..96f3e36ac --- /dev/null +++ b/sig/mindee/errors/mindee_http_error_v2.rbs @@ -0,0 +1,12 @@ +# lib/mindee/errors/mindee_http_error_v2.rb +module Mindee + module Errors + # API V2 HttpError + class MindeeHTTPErrorV2 < MindeeError + + attr_reader detail: String + attr_reader status: Integer + def initialize: (Hash[String | Symbol, untyped] | Parsing::V2::ErrorResponse) -> void + end + end +end diff --git a/sig/mindee/http/api_settings_v2.rbs b/sig/mindee/http/api_settings_v2.rbs new file mode 100644 index 000000000..3a99adedd --- /dev/null +++ b/sig/mindee/http/api_settings_v2.rbs @@ -0,0 +1,22 @@ +# lib/mindee/http/api_settings_v2.rb +module Mindee + module HTTP + class ApiSettingsV2 + MINDEE_V2_API_KEY_ENV_NAME: String + MINDEE_V2_API_KEY_DEFAULT: String? + MINDEE_V2_BASE_URL_ENV_NAME: String + MINDEE_V2_BASE_URL_DEFAULT: String + MINDEE_V2_REQUEST_TIMEOUT_ENV_NAME: String + MINDEE_V2_TIMEOUT_DEFAULT: Integer + USER_AGENT: String + + attr_reader api_key: String? + attr_reader base_url: String + attr_reader request_timeout: Integer + attr_reader user_agent: String + + def initialize: (?api_key: String) -> void + def check_api_key: -> void + end + end +end diff --git a/sig/mindee/http/mindee_api_v2.rbs b/sig/mindee/http/mindee_api_v2.rbs new file mode 100644 index 000000000..972585306 --- /dev/null +++ b/sig/mindee/http/mindee_api_v2.rbs @@ -0,0 +1,18 @@ +# lib/mindee/http/mindee_api_v2.rb +module Mindee + module HTTP + class MindeeApiV2 + attr_reader settings: ApiSettingsV2 + + def initialize: (String?) -> void + def req_post_inference_enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Input::InferenceParameters) -> Parsing::V2::JobResponse + def req_get_inference: (String) -> Parsing::V2::InferenceResponse + def req_get_job: (String) -> Parsing::V2::JobResponse + def process_response: (Net::HTTPResponse?) -> Hash[String | Symbol, untyped] + def poll: (String) -> Net::HTTPResponse + def inference_job_req_get: (String) -> Net::HTTPResponse + def inference_result_req_get: (String) -> Net::HTTPResponse + def enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Input::InferenceParameters) -> Net::HTTPResponse? + end + end +end diff --git a/sig/mindee/input/inference_parameters.rbs b/sig/mindee/input/inference_parameters.rbs new file mode 100644 index 000000000..36e9600c8 --- /dev/null +++ b/sig/mindee/input/inference_parameters.rbs @@ -0,0 +1,15 @@ +# lib/mindee/input/inference_parameters.rb +module Mindee + module Input + class InferenceParameters + attr_reader close_file: bool + attr_reader file_alias: String? + attr_reader model_id: String + attr_reader polling_options: PollingOptions + attr_reader rag: bool? + attr_reader webhook_ids: Array[String]? + + def initialize: (params: Hash[String | Symbol, untyped]) -> void + end + end +end diff --git a/sig/mindee/input/local_response.rbs b/sig/mindee/input/local_response.rbs index 40306b8f0..a5377f712 100644 --- a/sig/mindee/input/local_response.rbs +++ b/sig/mindee/input/local_response.rbs @@ -3,11 +3,12 @@ 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 + def initialize: (File | IO | StringIO | String | Pathname) -> void + def as_hash: -> Hash[String | Symbol, untyped] + def self.process_secret_key: (String) -> String + def get_hmac_signature: (String) -> String + def valid_hmac_signature?: (String, String) -> bool + def deserialize_response: -> (Parsing::V2::JobResponse | Parsing::V2::InferenceResponse) end end end diff --git a/sig/mindee/input/polling_options.rbs b/sig/mindee/input/polling_options.rbs new file mode 100644 index 000000000..6a550c688 --- /dev/null +++ b/sig/mindee/input/polling_options.rbs @@ -0,0 +1,12 @@ +# lib/mindee/input/polling_options.rb +module Mindee + module Input + class PollingOptions + attr_reader delay_sec: Integer | Float + attr_reader initial_delay_sec: Integer | Float + attr_reader max_retries: Integer + + def initialize: (?initial_delay_sec: Float, ?delay_sec: Float, ?max_retries: Integer) -> Integer + end + end +end diff --git a/sig/mindee/parsing/standard/amount_field.rbs b/sig/mindee/parsing/standard/amount_field.rbs index 8d7ba0018..e3ceaff5e 100644 --- a/sig/mindee/parsing/standard/amount_field.rbs +++ b/sig/mindee/parsing/standard/amount_field.rbs @@ -2,10 +2,12 @@ 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 + class AmountField < BaseField + attr_reader value: Float? + + + def initialize: (Hash[String | Symbol, untyped], Integer?, ?reconstructed: bool) -> void + def to_s: -> String end end end diff --git a/sig/mindee/parsing/standard/date_field.rbs b/sig/mindee/parsing/standard/date_field.rbs index e3b276800..52053f2e8 100644 --- a/sig/mindee/parsing/standard/date_field.rbs +++ b/sig/mindee/parsing/standard/date_field.rbs @@ -2,12 +2,12 @@ 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 + class DateField < BaseField + def date_object: -> DateTime + def value: -> String? + def raw: -> String? + def is_computed: -> bool + def initialize: (Hash[String | Symbol, untyped], Integer?, ?reconstructed: bool) -> void end end end diff --git a/sig/mindee/parsing/standard/payment_details_field.rbs b/sig/mindee/parsing/standard/payment_details_field.rbs index f2de2ee4b..5ef7739aa 100644 --- a/sig/mindee/parsing/standard/payment_details_field.rbs +++ b/sig/mindee/parsing/standard/payment_details_field.rbs @@ -2,12 +2,13 @@ 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 + class PaymentDetailsField < BaseField + attr_reader account_number: String ? + attr_reader iban: String? + attr_reader routing_number: String? + attr_reader swift: String? + + def initialize: (Hash[String | Symbol, untyped], Integer?, ?reconstructed: bool) -> void def to_s: -> String end end diff --git a/sig/mindee/parsing/v2/common_response.rbs b/sig/mindee/parsing/v2/common_response.rbs new file mode 100644 index 000000000..8c94189a8 --- /dev/null +++ b/sig/mindee/parsing/v2/common_response.rbs @@ -0,0 +1,11 @@ +# lib/mindee/parsing/v2/common_response.rb +module Mindee + module Parsing + module V2 + class CommonResponse + attr_reader raw_http: Hash[String | Symbol, untyped] + def initialize: (Hash[String | Symbol, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/parsing/v2/error_response.rbs b/sig/mindee/parsing/v2/error_response.rbs new file mode 100644 index 000000000..1964d271a --- /dev/null +++ b/sig/mindee/parsing/v2/error_response.rbs @@ -0,0 +1,16 @@ +# lib/mindee/parsing/v2/error_response.rb +module Mindee + module Parsing + module V2 + class ErrorResponse + attr_reader detail: String + attr_reader status: Integer + def initialize: (Hash[String | Symbol, untyped]) -> void + + def as_hash: -> Hash[Symbol, String | Integer] + + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/v2/field/base_field.rbs b/sig/mindee/parsing/v2/field/base_field.rbs new file mode 100644 index 000000000..4d8fce4c7 --- /dev/null +++ b/sig/mindee/parsing/v2/field/base_field.rbs @@ -0,0 +1,16 @@ +# lib/mindee/parsing/v2/field/base_field.rb +module Mindee + module Parsing + module V2 + module Field + class BaseField + attr_reader indent_level: Integer + attr_reader confidence: FieldConfidence? + + def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void + def self.create_field: (Hash[String | Symbol, untyped], ?Integer) -> (ListField | Field::ObjectField | Field::SimpleField) + end + end + end + end +end diff --git a/sig/mindee/parsing/v2/field/dynamic_field.rbs b/sig/mindee/parsing/v2/field/dynamic_field.rbs new file mode 100644 index 000000000..62eb4b92d --- /dev/null +++ b/sig/mindee/parsing/v2/field/dynamic_field.rbs @@ -0,0 +1,14 @@ +# lib/mindee/parsing/v2/field/dynamic_field.rb +module Mindee + module Parsing + module V2 + module Field + class DynamicField < BaseField + attr_reader locations: Array[FieldLocation]? + + def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void + end + end + end + end +end diff --git a/sig/mindee/parsing/v2/field/field_confidence.rbs b/sig/mindee/parsing/v2/field/field_confidence.rbs new file mode 100644 index 000000000..dd43361c9 --- /dev/null +++ b/sig/mindee/parsing/v2/field/field_confidence.rbs @@ -0,0 +1,27 @@ +# lib/mindee/parsing/v2/field/field_confidence.rb +module Mindee + module Parsing + module V2 + module Field + class FieldConfidence + attr_reader value: String + CERTAIN: String + HIGH: String + MEDIUM: String + LOW: String + VALID_VALUES: Array[String] + def initialize: (Hash[String | Symbol, untyped]) -> void + def self.from_string: (String) -> FieldConfidence + def certain?: -> bool + def high?: -> bool + def medium?: -> bool + def low?: -> bool + def to_s: -> String + def ==: (FieldConfidence) -> bool + def eql?: (FieldConfidence) -> bool + def inspect: -> String + end + end + end + end +end diff --git a/sig/mindee/parsing/v2/field/field_location.rbs b/sig/mindee/parsing/v2/field/field_location.rbs new file mode 100644 index 000000000..f778cf921 --- /dev/null +++ b/sig/mindee/parsing/v2/field/field_location.rbs @@ -0,0 +1,16 @@ +# lib/mindee/parsing/v2/field/field_location.rb +module Mindee + module Parsing + module V2 + module Field + class FieldLocation + attr_reader page: Integer? + attr_reader polygon: Geometry::Polygon? + + def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void + def to_s: -> String + end + end + end + end +end diff --git a/sig/mindee/parsing/v2/field/inference_fields.rbs b/sig/mindee/parsing/v2/field/inference_fields.rbs new file mode 100644 index 000000000..f5914e02d --- /dev/null +++ b/sig/mindee/parsing/v2/field/inference_fields.rbs @@ -0,0 +1,18 @@ +# lib/mindee/parsing/v2/field/inference_fields.rb +module Mindee + module Parsing + module V2 + module Field + class InferenceFields < Hash[String, ListField | ObjectField | SimpleField | nil] + attr_reader indent_level: Integer + + def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void + def get: (String) -> (ListField | ObjectField | SimpleField | nil) + def method_missing: (Symbol, *untyped) -> (ListField | ObjectField | SimpleField | nil) + def respond_to_missing?: (Symbol, ?bool) -> bool + def to_s: (Integer?) -> String + end + end + end + end +end diff --git a/sig/mindee/parsing/v2/field/list_field.rbs b/sig/mindee/parsing/v2/field/list_field.rbs new file mode 100644 index 000000000..1cc4ce306 --- /dev/null +++ b/sig/mindee/parsing/v2/field/list_field.rbs @@ -0,0 +1,20 @@ +# lib/mindee/parsing/v2/field/list_field.rb +module Mindee + module Parsing + module V2 + module Field + class ListField < DynamicField + include Enumerable[untyped] + attr_reader items: Array[ListField | ObjectField | SimpleField | nil] + def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void + def to_s: -> String + def empty?: -> bool + def size: -> Integer + def length: -> Integer + def each: { (untyped) -> Object } -> (Array[ListField | ObjectField | SimpleField | nil] | Enumerator[ListField | ObjectField | SimpleField | nil, Array[ListField | ObjectField | SimpleField | nil]]) + def []: (Integer) -> (ListField | ObjectField | SimpleField | nil) + end + end + end + end +end diff --git a/sig/mindee/parsing/v2/field/object_field.rbs b/sig/mindee/parsing/v2/field/object_field.rbs new file mode 100644 index 000000000..818dfb45d --- /dev/null +++ b/sig/mindee/parsing/v2/field/object_field.rbs @@ -0,0 +1,21 @@ +# TypeProf 0.30.1 + +module Mindee + module Parsing + module V2 + module Field + # A field containing a nested set of inference fields. + class ObjectField < DynamicField + attr_reader fields: InferenceFields + def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void + def multi_str: -> String + def respond_to_missing?: (Symbol, bool) -> bool + def single_str: -> String + def to_s: -> String + def to_s_from_list: -> String + def method_missing: (Symbol, *untyped, untyped) -> (ObjectField | nil) + end + end + end + end +end \ No newline at end of file diff --git a/sig/mindee/parsing/v2/field/simple_field.rbs b/sig/mindee/parsing/v2/field/simple_field.rbs new file mode 100644 index 000000000..f420a0967 --- /dev/null +++ b/sig/mindee/parsing/v2/field/simple_field.rbs @@ -0,0 +1,16 @@ +# lib/mindee/parsing/v2/field/simple_field.rb +module Mindee + module Parsing + module V2 + module Field + class SimpleField < DynamicField + attr_reader value: String | Integer | Float | bool | nil + + def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void + def to_s: -> String + def format_numeric_value: (String | Integer | Float | bool | nil) -> String + end + end + end + end +end diff --git a/sig/mindee/parsing/v2/inference.rbs b/sig/mindee/parsing/v2/inference.rbs new file mode 100644 index 000000000..0d4387f87 --- /dev/null +++ b/sig/mindee/parsing/v2/inference.rbs @@ -0,0 +1,16 @@ +# lib/mindee/parsing/v2/inference.rb +module Mindee + module Parsing + module V2 + class Inference + attr_reader file: InferenceFile + attr_reader id: String + attr_reader model: InferenceModel + attr_reader result: InferenceResult + + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/v2/inference_file.rbs b/sig/mindee/parsing/v2/inference_file.rbs new file mode 100644 index 000000000..43e313115 --- /dev/null +++ b/sig/mindee/parsing/v2/inference_file.rbs @@ -0,0 +1,15 @@ +# lib/mindee/parsing/v2/inference_file.rb +module Mindee + module Parsing + module V2 + class InferenceFile + attr_reader name: String + attr_reader file_alias: String? + attr_reader page_count: Integer + attr_reader mime_type: String + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/v2/inference_model.rbs b/sig/mindee/parsing/v2/inference_model.rbs new file mode 100644 index 000000000..07a9be237 --- /dev/null +++ b/sig/mindee/parsing/v2/inference_model.rbs @@ -0,0 +1,11 @@ +# lib/mindee/parsing/v2/inference_model.rb +module Mindee + module Parsing + module V2 + class InferenceModel + attr_reader id: String + def initialize: (Hash[String | Symbol, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/parsing/v2/inference_response.rbs b/sig/mindee/parsing/v2/inference_response.rbs new file mode 100644 index 000000000..7254f9965 --- /dev/null +++ b/sig/mindee/parsing/v2/inference_response.rbs @@ -0,0 +1,12 @@ +# lib/mindee/parsing/v2/inference_response.rb +module Mindee + module Parsing + module V2 + class InferenceResponse < CommonResponse + attr_reader inference: V2::Inference + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/v2/inference_result.rbs b/sig/mindee/parsing/v2/inference_result.rbs new file mode 100644 index 000000000..b1b6bedc8 --- /dev/null +++ b/sig/mindee/parsing/v2/inference_result.rbs @@ -0,0 +1,13 @@ +# lib/mindee/parsing/v2/inference_result.rb +module Mindee + module Parsing + module V2 + class InferenceResult + attr_reader fields: Field::InferenceFields + attr_reader options: InferenceResultOptions? + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/v2/inference_result_options.rbs b/sig/mindee/parsing/v2/inference_result_options.rbs new file mode 100644 index 000000000..fd289c161 --- /dev/null +++ b/sig/mindee/parsing/v2/inference_result_options.rbs @@ -0,0 +1,11 @@ +# lib/mindee/parsing/v2/inference_result_options.rb +module Mindee + module Parsing + module V2 + class InferenceResultOptions + attr_reader raw_texts: Array[RawText] + def initialize: (Hash[String | Symbol, untyped]) -> void + end + end + end +end diff --git a/sig/mindee/parsing/v2/job.rbs b/sig/mindee/parsing/v2/job.rbs new file mode 100644 index 000000000..2a211e89f --- /dev/null +++ b/sig/mindee/parsing/v2/job.rbs @@ -0,0 +1,22 @@ +# lib/mindee/parsing/v2/job.rb +module Mindee + module Parsing + module V2 + class Job + attr_reader alias: String + attr_reader created_at: DateTime | nil + attr_reader error: ErrorResponse | nil + attr_reader filename: String + attr_reader id: String + attr_reader model_id: String + attr_reader polling_url: String + attr_reader result_url: String | nil + attr_reader status: String + attr_reader webhooks: Array[JobWebhook] + + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/v2/job_response.rbs b/sig/mindee/parsing/v2/job_response.rbs new file mode 100644 index 000000000..1ecf8683a --- /dev/null +++ b/sig/mindee/parsing/v2/job_response.rbs @@ -0,0 +1,12 @@ +# lib/mindee/parsing/v2/job_response.rb +module Mindee + module Parsing + module V2 + class JobResponse < CommonResponse + attr_reader job: Job + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String + end + end + end +end diff --git a/sig/mindee/parsing/v2/job_webhook.rbs b/sig/mindee/parsing/v2/job_webhook.rbs new file mode 100644 index 000000000..452dab2ff --- /dev/null +++ b/sig/mindee/parsing/v2/job_webhook.rbs @@ -0,0 +1,17 @@ +# lib/mindee/parsing/v2/job_webhook.rb +module Mindee + module Parsing + module V2 + class JobWebhook + attr_reader created_at: DateTime | nil + attr_reader error: ErrorResponse + attr_reader id: String + attr_reader status: String + + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String + def parse_date: (String?) -> DateTime? + end + end + end +end diff --git a/sig/mindee/parsing/v2/raw_text.rbs b/sig/mindee/parsing/v2/raw_text.rbs new file mode 100644 index 000000000..0f1ce2190 --- /dev/null +++ b/sig/mindee/parsing/v2/raw_text.rbs @@ -0,0 +1,12 @@ +# lib/mindee/parsing/v2/raw_text.rb +module Mindee + module Parsing + module V2 + class RawText + attr_reader page: Integer? + attr_reader content: String? + def initialize: (Hash[String | Symbol, untyped]) -> void + end + end + end +end From 2ecc725cc404cc0139af74b5e4d6ef0de572dc57 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 6 Aug 2025 11:11:41 +0200 Subject: [PATCH 05/19] :recycle: add missing & fix most type signatures --- lib/mindee/geometry/point.rb | 4 +- lib/mindee/geometry/quadrilateral.rb | 8 ++-- lib/mindee/geometry/utils.rb | 1 + lib/mindee/image/image_extractor.rb | 8 ++-- lib/mindee/parsing/common/execution.rb | 2 +- lib/mindee/parsing/common/ocr/ocr.rb | 6 +-- lib/mindee/parsing/common/orientation.rb | 4 +- lib/mindee/parsing/common/product.rb | 7 +++- .../parsing/universal/universal_list_field.rb | 4 +- .../universal/universal_object_field.rb | 7 +++- lib/mindee/pdf/extracted_pdf.rb | 6 ++- lib/mindee/pdf/pdf_extractor.rb | 2 +- lib/mindee/pdf/pdf_processor.rb | 10 ++--- lib/mindee/pdf/pdf_tools.rb | 6 ++- sig/custom/origami.rbs | 7 +++- sig/mindee/client.rbs | 4 +- sig/mindee/errors/mindee_http_error.rbs | 11 ++--- sig/mindee/errors/mindee_input_error.rbs | 5 ++- sig/mindee/geometry/min_max.rbs | 7 ++-- sig/mindee/geometry/point.rbs | 11 +++-- sig/mindee/geometry/polygon.rbs | 6 +-- sig/mindee/geometry/quadrilateral.rbs | 13 +++--- sig/mindee/geometry/utils.rbs | 16 +++---- sig/mindee/image/extracted_image.rbs | 2 +- sig/mindee/image/image_extractor.rbs | 10 ++--- sig/mindee/image/image_utils.rbs | 2 +- .../input/sources/local_input_source.rbs | 2 +- sig/mindee/input/sources/url_input_source.rbs | 2 +- sig/mindee/parsing/common/document.rbs | 20 ++++----- sig/mindee/parsing/common/execution.rbs | 29 ++++++------- sig/mindee/parsing/common/execution_file.rbs | 6 +-- .../parsing/common/extras/cropper_extra.rbs | 5 ++- sig/mindee/parsing/common/extras/extras.rbs | 11 ++--- sig/mindee/parsing/common/inference.rbs | 20 +++++---- sig/mindee/parsing/common/ocr/mvision_v1.rbs | 4 +- sig/mindee/parsing/common/ocr/ocr.rbs | 42 ++++++++++--------- sig/mindee/parsing/common/orientation.rbs | 7 ++-- sig/mindee/parsing/common/page.rbs | 11 ++--- sig/mindee/parsing/common/product.rbs | 8 ++-- .../standard/company_registration_field.rbs | 5 ++- sig/mindee/parsing/standard/tax_field.rbs | 15 +++---- .../universal/universal_list_field.rbs | 9 ++-- .../universal/universal_object_field.rbs | 17 ++++---- sig/mindee/pdf/extracted_pdf.rbs | 12 +++--- sig/mindee/pdf/pdf_compressor.rbs | 2 +- sig/mindee/pdf/pdf_extractor.rbs | 15 ++++--- sig/mindee/pdf/pdf_processor.rbs | 4 +- sig/mindee/pdf/pdf_tools.rbs | 31 +++++++------- sig/mindee/product/universal/universal.rbs | 10 ++--- spec/data | 2 +- 50 files changed, 243 insertions(+), 215 deletions(-) diff --git a/lib/mindee/geometry/point.rb b/lib/mindee/geometry/point.rb index 6058f81bb..18ff21354 100644 --- a/lib/mindee/geometry/point.rb +++ b/lib/mindee/geometry/point.rb @@ -6,9 +6,9 @@ module Geometry # A relative set of coordinates (X, Y) on the document. class Point # @return [Float] - attr_accessor :x + attr_reader :x # @return [Float] - attr_accessor :y + attr_reader :y # rubocop:disable Naming/MethodParameterName diff --git a/lib/mindee/geometry/quadrilateral.rb b/lib/mindee/geometry/quadrilateral.rb index 0f0e9689a..d3b008973 100644 --- a/lib/mindee/geometry/quadrilateral.rb +++ b/lib/mindee/geometry/quadrilateral.rb @@ -6,13 +6,13 @@ module Geometry # Contains exactly 4 relative vertices coordinates (Points). class Quadrilateral # @return [Mindee::Geometry::Point] - attr_accessor :top_left + attr_reader :top_left # @return [Mindee::Geometry::Point] - attr_accessor :top_right + attr_reader :top_right # @return [Mindee::Geometry::Point] - attr_accessor :bottom_right + attr_reader :bottom_right # @return [Mindee::Geometry::Point] - attr_accessor :bottom_left + attr_reader :bottom_left # @param top_left [Mindee::Geometry::Point] # @param top_right [Mindee::Geometry::Point] diff --git a/lib/mindee/geometry/utils.rb b/lib/mindee/geometry/utils.rb index 64bfce196..b5612ca73 100644 --- a/lib/mindee/geometry/utils.rb +++ b/lib/mindee/geometry/utils.rb @@ -83,6 +83,7 @@ def self.get_min_max_x(points) # @param anchor [Array>, Array] polygons List of coordinates + # @param [Array>, Array] List of coordinates # to extract. # @return [Array] Extracted Images. def self.extract_multiple_images_from_source(input_source, page_id, polygons) @@ -47,7 +47,7 @@ def self.extract_multiple_images_from_source(input_source, page_id, polygons) # @param [Mindee::Input::Source::LocalInputSource] input_source Local input source. # @param [StringIO] pdf_stream Buffer of the PDF. # @param [Integer] page_id Page ID. - # @param [Array] polygons + # @param [Array] polygons # @return [Array] Extracted Images. def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygons) extracted_elements = [] @@ -90,8 +90,8 @@ 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 universal from. - # @param [Object] element_id ID of the element of a given page. + # @param [Integer] page_id ID of the page the file was universal from. + # @param [Integer] element_id ID of the element of a given page. def self.create_extracted_image(buffer, file_name, page_id, element_id) buffer.rewind ExtractedImage.new( diff --git a/lib/mindee/parsing/common/execution.rb b/lib/mindee/parsing/common/execution.rb index 906505bf6..f2175d4c8 100644 --- a/lib/mindee/parsing/common/execution.rb +++ b/lib/mindee/parsing/common/execution.rb @@ -21,7 +21,7 @@ class Execution # @return [Mindee::Inference] attr_reader :inference # Priority of the execution. - # @return [ExecutionPriority] + # @return [ExecutionPriority, Symbol, nil] attr_reader :priority # The time at which the file was tagged as reviewed. # @return [Time, nil] diff --git a/lib/mindee/parsing/common/ocr/ocr.rb b/lib/mindee/parsing/common/ocr/ocr.rb index 8eb9c149c..5ee0c7cdd 100644 --- a/lib/mindee/parsing/common/ocr/ocr.rb +++ b/lib/mindee/parsing/common/ocr/ocr.rb @@ -11,7 +11,7 @@ module OCR class OCRWord # The confidence score, value will be between 0.0 and 1.0 # @return [Float] - attr_accessor :confidence + attr_reader :confidence # @return [String] attr_reader :text # @return [Mindee::Geometry::Quadrilateral] @@ -36,7 +36,7 @@ def to_s # A list of words which are on the same line. class OCRLine < Array # @param prediction [Hash, nil] - # @param from_array [Array, nil] + # @param from_array [Array] # @param lines [Array] def parse_one(sorted_words, current, indexes, lines) - line = OCRLine.new([]) + line = OCRLine.new(nil, []) sorted_words.each_with_index do |word, idx| next if indexes.include?(idx) diff --git a/lib/mindee/parsing/common/orientation.rb b/lib/mindee/parsing/common/orientation.rb index e8e213fd7..9d4876a81 100644 --- a/lib/mindee/parsing/common/orientation.rb +++ b/lib/mindee/parsing/common/orientation.rb @@ -5,7 +5,7 @@ module Parsing module Common # Page orientation class Orientation - # @return [Integer] + # @return [Integer, nil] attr_reader :page_id # A prediction among these 3 possible outputs: # * 0 degrees: the page is already upright @@ -15,7 +15,7 @@ class Orientation attr_reader :value # @param prediction [Hash] - # @param page_id [Integer] + # @param page_id [Integer, nil] def initialize(prediction, page_id) @value = prediction['value'] @page_id = page_id diff --git a/lib/mindee/parsing/common/product.rb b/lib/mindee/parsing/common/product.rb index c1864f714..e3f4bcd4e 100644 --- a/lib/mindee/parsing/common/product.rb +++ b/lib/mindee/parsing/common/product.rb @@ -5,7 +5,12 @@ module Parsing module Common # Product information class Product - attr_reader :name, :type, :version + # @return [String] Name of the product. + attr_reader :name + # @return [String?] Type of product. + attr_reader :type + # @return [String] Product version. + attr_reader :version # @param prediction [Hash] def initialize(prediction) diff --git a/lib/mindee/parsing/universal/universal_list_field.rb b/lib/mindee/parsing/universal/universal_list_field.rb index 54837d58e..2602ae357 100644 --- a/lib/mindee/parsing/universal/universal_list_field.rb +++ b/lib/mindee/parsing/universal/universal_list_field.rb @@ -12,11 +12,11 @@ class UniversalListField # ID of the page (as given by the API). # @return [Integer] - attr_accessor :page_id + attr_reader :page_id # List of word values # @return [Array] - attr_accessor :values + attr_reader :values # ID of the page the object was found on. # List of word values. diff --git a/lib/mindee/parsing/universal/universal_object_field.rb b/lib/mindee/parsing/universal/universal_object_field.rb index a45db73f1..33dbe0c4f 100644 --- a/lib/mindee/parsing/universal/universal_object_field.rb +++ b/lib/mindee/parsing/universal/universal_object_field.rb @@ -15,8 +15,11 @@ class UniversalObjectField # @return [Float] attr_reader :confidence # Value as String - # @return [Hash, nil] - attr_accessor :raw_value + # @return [String] + attr_reader :raw_value + # All values + # @return [Hash] + attr_reader :all_values # ID of the page the object was found on. # Confidence with which the value was assessed. diff --git a/lib/mindee/pdf/extracted_pdf.rb b/lib/mindee/pdf/extracted_pdf.rb index d70f9e559..87e0ff4a4 100644 --- a/lib/mindee/pdf/extracted_pdf.rb +++ b/lib/mindee/pdf/extracted_pdf.rb @@ -7,14 +7,14 @@ module PDFExtractor # An extracted sub-Pdf. class ExtractedPDF # Byte contents of the pdf - # @return [StreamIO] + # @return [StringIO] attr_reader :pdf_bytes # Name of the file. # @return [String] attr_reader :filename - # @param pdf_bytes [StreamIO] + # @param pdf_bytes [StringIO] # @param filename [String] def initialize(pdf_bytes, filename) @pdf_bytes = pdf_bytes @@ -50,6 +50,8 @@ def write_to_file(output_path, override: false) # Returns the current PDF object as a usable BytesInputSource. # @return [Mindee::Input::Source::BytesInputSource] def as_input_source + raise Errors::MindeePDFError, 'Bytes object is nil.' if @pdf_bytes.nil? + Mindee::Input::Source::BytesInputSource.new(@pdf_bytes.read, @filename) end end diff --git a/lib/mindee/pdf/pdf_extractor.rb b/lib/mindee/pdf/pdf_extractor.rb index 2b78ebf54..8014464df 100644 --- a/lib/mindee/pdf/pdf_extractor.rb +++ b/lib/mindee/pdf/pdf_extractor.rb @@ -29,7 +29,7 @@ def page_count # Creates a new Pdf from pages and save it into a buffer. # @param page_indexes [Array] List of page number to use for merging in the original Pdf. - # @return [StreamIO] The buffer containing the new Pdf. + # @return [StringIO] The buffer containing the new Pdf. def cut_pages(page_indexes) options = PageOptions.new(params: { page_indexes: page_indexes, diff --git a/lib/mindee/pdf/pdf_processor.rb b/lib/mindee/pdf/pdf_processor.rb index 1d7e38ebd..9552e8110 100644 --- a/lib/mindee/pdf/pdf_processor.rb +++ b/lib/mindee/pdf/pdf_processor.rb @@ -31,8 +31,8 @@ def self.parse(io_stream, options) current_pdf.to_io_stream end - # @param page_indexes [Array] - # @param all_pages [Array] + # @param page_indexes [Array] + # @param all_pages [Array] def self.indexes_from_keep(page_indexes, all_pages) pages_to_keep = Set.new page_indexes.each do |idx| @@ -42,11 +42,11 @@ def self.indexes_from_keep(page_indexes, all_pages) pages_to_keep << page end - all_pages.to_set - pages_to_keep + (all_pages.to_set - pages_to_keep).to_a end - # @param page_indexes [Array[Integer]] - # @param all_pages [Array] + # @param page_indexes [Array] + # @param all_pages [Array] def self.indexes_from_remove(page_indexes, all_pages) pages_to_remove = Set.new page_indexes.each do |idx| diff --git a/lib/mindee/pdf/pdf_tools.rb b/lib/mindee/pdf/pdf_tools.rb index d11f745b1..676862f5c 100644 --- a/lib/mindee/pdf/pdf_tools.rb +++ b/lib/mindee/pdf/pdf_tools.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'origami' + module Mindee module PDF # Collection of miscellaneous PDF operations,as well as some monkey-patching for Origami. @@ -84,7 +86,7 @@ def self.source_text?(pdf_data) # 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. + # @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) @@ -153,7 +155,7 @@ def self.set_page_dimensions(page, width, height) # Processes an image into an image XObject for PDF embedding. # - # @param [Hash] image_data The raw image data. + # @param [MiniMagick::Image, StringIO] 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. diff --git a/sig/custom/origami.rbs b/sig/custom/origami.rbs index 2f9b1e4e5..ebdf067cf 100644 --- a/sig/custom/origami.rbs +++ b/sig/custom/origami.rbs @@ -1,6 +1,10 @@ # Stubs for the origami library. # This one _should_ exist, but it would take too long, so this is a stub. module Origami + def intents_as_pdfa1: () -> void + def delinearize!: () -> void + def linearized?: () -> bool + def compile: (Hash[Symbol, untyped]) -> void class Array def each: { (untyped) -> untyped } -> untyped end @@ -9,7 +13,7 @@ module Origami def initialize: () -> void def append_page: (Page) -> void def delete_pages_at: (::Array[Integer]) -> void - def pages: () -> untyped + def pages: () -> ::Array[Page] def save: (StringIO) -> void def to_io_stream: -> StringIO class LinearParser @@ -17,6 +21,7 @@ module Origami def new: (Hash[Symbol, untyped]) -> void def parse: (StringIO?) -> PDF end + def compile: (Hash[String | Symbol, untyped]) -> StringIO end class Page diff --git a/sig/mindee/client.rbs b/sig/mindee/client.rbs index 328618d80..d4ff42009 100644 --- a/sig/mindee/client.rbs +++ b/sig/mindee/client.rbs @@ -31,10 +31,10 @@ module Mindee end class Client - @api_key: string |nil + @api_key: string | nil def initialize: (?api_key: String) -> void - def logger: () -> untyped + def logger: () -> Logging def parse: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), ?endpoint: (HTTP::Endpoint?), options: ParseOptions | Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse def parse_sync: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse def enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), ?endpoint: (HTTP::Endpoint?), options: ParseOptions|Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse diff --git a/sig/mindee/errors/mindee_http_error.rbs b/sig/mindee/errors/mindee_http_error.rbs index 29eaedc04..2811fa700 100644 --- a/sig/mindee/errors/mindee_http_error.rbs +++ b/sig/mindee/errors/mindee_http_error.rbs @@ -2,11 +2,12 @@ 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 + attr_reader api_code: Integer + attr_reader api_details: String + attr_reader api_message: String + attr_reader status_code: Integer + + def initialize: (Hash[String | Symbol, untyped], String, Integer) -> void end class MindeeHTTPClientError < MindeeHTTPError end diff --git a/sig/mindee/errors/mindee_input_error.rbs b/sig/mindee/errors/mindee_input_error.rbs index 170440e06..94fd985f5 100644 --- a/sig/mindee/errors/mindee_input_error.rbs +++ b/sig/mindee/errors/mindee_input_error.rbs @@ -6,8 +6,9 @@ module Mindee class MindeeSourceError < MindeeInputError end class MindeeMimeTypeError < MindeeSourceError - def invalid_mimetype: -> untyped - def initialize: (untyped) -> untyped + attr_reader invalid_mimetype: String + + def initialize: (String) -> void end class MindeeImageError < MindeeInputError end diff --git a/sig/mindee/geometry/min_max.rbs b/sig/mindee/geometry/min_max.rbs index 9735cd3bd..27144eae8 100644 --- a/sig/mindee/geometry/min_max.rbs +++ b/sig/mindee/geometry/min_max.rbs @@ -2,9 +2,10 @@ module Mindee module Geometry class MinMax - def min: -> untyped - def max: -> untyped - def initialize: (untyped, untyped) -> untyped + attr_reader max: Float + attr_reader min: Float + + def initialize: (Float, Float) -> void end end end diff --git a/sig/mindee/geometry/point.rbs b/sig/mindee/geometry/point.rbs index edbb9f789..9bac0dcf2 100644 --- a/sig/mindee/geometry/point.rbs +++ b/sig/mindee/geometry/point.rbs @@ -2,12 +2,11 @@ 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 + attr_accessor x: Float + attr_accessor y: Float + + def initialize: (Float, Float) -> void + def []: (Integer) -> Float end end end diff --git a/sig/mindee/geometry/polygon.rbs b/sig/mindee/geometry/polygon.rbs index 5100a56f0..559d912d6 100644 --- a/sig/mindee/geometry/polygon.rbs +++ b/sig/mindee/geometry/polygon.rbs @@ -1,9 +1,9 @@ # lib/mindee/geometry/polygon.rb module Mindee module Geometry - class Polygon < Array[untyped] - def centroid: -> untyped - def point_in_y?: (untyped) -> untyped + class Polygon < Array[Point] + def centroid: -> Point + def point_in_y?: (Point) -> bool end end end diff --git a/sig/mindee/geometry/quadrilateral.rbs b/sig/mindee/geometry/quadrilateral.rbs index 421ce9161..df65cae15 100644 --- a/sig/mindee/geometry/quadrilateral.rbs +++ b/sig/mindee/geometry/quadrilateral.rbs @@ -2,14 +2,11 @@ module Mindee module Geometry class Quadrilateral - def top_left: -> Point - def top_left=: (Point) -> bool - def top_right: -> Point - def top_right=: (Point) -> untyped - def bottom_right: -> Point - def bottom_right=: (Point) -> untyped - def bottom_left: -> Point - def bottom_left=: (Point) -> untyped + attr_accessor bottom_left: Point + attr_accessor bottom_right: Point + attr_accessor top_left: Point + attr_accessor top_right: Point + def initialize: (Point, Point, Point, Point) -> void def []: (Integer) -> Point def size: -> Integer diff --git a/sig/mindee/geometry/utils.rbs b/sig/mindee/geometry/utils.rbs index cfb2f36bb..a61eaca71 100644 --- a/sig/mindee/geometry/utils.rbs +++ b/sig/mindee/geometry/utils.rbs @@ -1,13 +1,13 @@ # lib/mindee/geometry/utils.rb module Mindee module Geometry - def self.quadrilateral_from_prediction: (untyped) -> untyped - def self.polygon_from_prediction: (untyped) -> untyped - def self.get_bbox: (untyped) -> [untyped, untyped, untyped, untyped] - def self.get_bounding_box: (untyped) -> Quadrilateral - def self.get_centroid: (untyped) -> untyped - def self.get_min_max_y: (untyped) -> untyped - def self.get_min_max_x: (untyped) -> untyped - def self.below?: (untyped, untyped, untyped, untyped) -> bool + def self.quadrilateral_from_prediction: (Array[Array[Float]]) -> Quadrilateral + def self.polygon_from_prediction: (Hash[String | Symbol, untyped]) -> Polygon + def self.get_bbox: (Array[Point]) -> [Float, Float, Float, Float] + def self.get_bounding_box: (Array[Point]) -> Quadrilateral + def self.get_centroid: (Array[Point]) -> Point + def self.get_min_max_y: (Array[Point]) -> MinMax + def self.get_min_max_x: (Array[Point]) -> MinMax + def self.below?: (Array[Point], Array[Point], Float, Float) -> bool end end diff --git a/sig/mindee/image/extracted_image.rbs b/sig/mindee/image/extracted_image.rbs index 2ad71f567..668a001ba 100644 --- a/sig/mindee/image/extracted_image.rbs +++ b/sig/mindee/image/extracted_image.rbs @@ -2,7 +2,7 @@ module Mindee module Image class ExtractedImage - def logger: () -> untyped + def logger: () -> Logger def page_id: -> Integer def element_id: -> Integer def buffer: -> StringIO diff --git a/sig/mindee/image/image_extractor.rbs b/sig/mindee/image/image_extractor.rbs index a8fcb8150..c2aa53d00 100644 --- a/sig/mindee/image/image_extractor.rbs +++ b/sig/mindee/image/image_extractor.rbs @@ -2,12 +2,12 @@ module Mindee module Image module ImageExtractor - def self.attach_image_as_new_file: (untyped, ?format: String) -> untyped + def self.attach_image_as_new_file: (StringIO, ?format: String) -> Origami::PDF 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 + def self.extract_multiple_images_from_source: (Input::Source::LocalInputSource, Integer, Array[Array[Geometry::Point] | Array[Geometry::Quadrilateral]]) -> Array[ExtractedImage] + def self.extract_images_from_polygons: (Input::Source::LocalInputSource, StringIO, Integer, Array[Geometry::Point] | Geometry::Quadrilateral) -> Array[ExtractedImage] + def self.create_extracted_image: (StringIO, String, Integer, Integer) -> void + def self.load_input_source_pdf_page_as_stringio: (Input::Source::LocalInputSource, Integer) -> StringIO end end end diff --git a/sig/mindee/image/image_utils.rbs b/sig/mindee/image/image_utils.rbs index 24bdaa885..9abc4a394 100644 --- a/sig/mindee/image/image_utils.rbs +++ b/sig/mindee/image/image_utils.rbs @@ -3,7 +3,7 @@ module Mindee module Image module ImageUtils def self.resize_image: (singleton(MiniMagick::Image) | MiniMagick::Image, Integer, Integer) -> void - def self.compress_image_quality: (singleton(MiniMagick::Image) | MiniMagick::Image, untyped) -> untyped + def self.compress_image_quality: (singleton(MiniMagick::Image) | MiniMagick::Image, untyped) -> void 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] diff --git a/sig/mindee/input/sources/local_input_source.rbs b/sig/mindee/input/sources/local_input_source.rbs index 1fdcf98cd..04b04596e 100644 --- a/sig/mindee/input/sources/local_input_source.rbs +++ b/sig/mindee/input/sources/local_input_source.rbs @@ -12,7 +12,7 @@ module Mindee def file_mimetype: -> String def io_stream: -> StringIO def initialize: (StringIO | File, String, ?repair_pdf: bool) -> void - def logger: () -> untyped + def logger: () -> Logger def rescue_broken_pdf: (StringIO|File) -> StringIO diff --git a/sig/mindee/input/sources/url_input_source.rbs b/sig/mindee/input/sources/url_input_source.rbs index 93d08b5f6..77d2e0361 100644 --- a/sig/mindee/input/sources/url_input_source.rbs +++ b/sig/mindee/input/sources/url_input_source.rbs @@ -4,7 +4,7 @@ module Mindee module Source class URLInputSource def url: -> String - def logger: () -> untyped + def logger: () -> Logger 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? diff --git a/sig/mindee/parsing/common/document.rbs b/sig/mindee/parsing/common/document.rbs index f7a0cb654..d3d63803d 100644 --- a/sig/mindee/parsing/common/document.rbs +++ b/sig/mindee/parsing/common/document.rbs @@ -3,17 +3,17 @@ 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 inference: -> Inference + def name: -> String + def id: -> String + def extras: -> Extras::Extras? + def ocr: -> OCR::OCR? + def n_pages: -> Integer + def self.load_ocr: (Hash[String | Symbol, untyped]) -> Parsing::Common::OCR::OCR? + def self.extract_extras: (Hash[String | Symbol, untyped]) -> Parsing::Common::Extras::Extras? + def initialize: (singleton(Parsing::Common::Inference), Hash[String | Symbol, untyped]) -> void def to_s: -> String - def inject_full_text_ocr: (untyped) -> untyped + def inject_full_text_ocr: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/parsing/common/execution.rbs b/sig/mindee/parsing/common/execution.rbs index 18fc0a22b..3ba71c11c 100644 --- a/sig/mindee/parsing/common/execution.rbs +++ b/sig/mindee/parsing/common/execution.rbs @@ -3,20 +3,21 @@ 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 + attr_reader available_at: Time? + attr_reader batch_name: String + attr_reader created_at: Time + attr_reader file: ExecutionFile + attr_reader id: String + attr_reader inference: Inference + attr_reader priority: Symbol? + attr_reader reviewed_at: Time? + attr_reader reviewed_prediction: Prediction? + attr_reader status: Symbol + attr_reader type: String? + attr_reader uploaded_at: Time? + attr_reader workflow_id: String + + def initialize: (singleton(Parsing::Common::Inference), Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/parsing/common/execution_file.rbs b/sig/mindee/parsing/common/execution_file.rbs index 9dd72a561..4d8d16f00 100644 --- a/sig/mindee/parsing/common/execution_file.rbs +++ b/sig/mindee/parsing/common/execution_file.rbs @@ -3,9 +3,9 @@ module Mindee module Parsing module Common class ExecutionFile - def name: -> untyped - def alias: -> untyped - def initialize: (untyped) -> untyped + def name: -> String + def alias: -> String? + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/parsing/common/extras/cropper_extra.rbs b/sig/mindee/parsing/common/extras/cropper_extra.rbs index b2c9c16c7..884502efb 100644 --- a/sig/mindee/parsing/common/extras/cropper_extra.rbs +++ b/sig/mindee/parsing/common/extras/cropper_extra.rbs @@ -4,8 +4,9 @@ module Mindee module Common module Extras class CropperExtra - def croppings: -> Array[Standard::PositionField] - def initialize: (untyped, ?nil) -> untyped + attr_reader croppings: Array[Standard::PositionField] + + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/parsing/common/extras/extras.rbs b/sig/mindee/parsing/common/extras/extras.rbs index 99303fe4c..9f9a02e32 100644 --- a/sig/mindee/parsing/common/extras/extras.rbs +++ b/sig/mindee/parsing/common/extras/extras.rbs @@ -4,12 +4,13 @@ module Mindee module Common module Extras class Extras - def cropper: -> untyped - def full_text_ocr: -> untyped - def initialize: (untyped) -> void - def new: (untyped) -> void + attr_reader cropper: CropperExtra? + attr_reader full_text_ocr: FullTextOCRExtra? + attr_reader rag: RAGExtra? + + def initialize: (Hash[String | Symbol, untyped]) -> void def to_s: -> String - def add_artificial_extra: (untyped) -> nil + def add_artificial_extra: (Hash[String | Symbol, untyped]) -> void end def empty?: -> bool end diff --git a/sig/mindee/parsing/common/inference.rbs b/sig/mindee/parsing/common/inference.rbs index 6b75aa717..749e92619 100644 --- a/sig/mindee/parsing/common/inference.rbs +++ b/sig/mindee/parsing/common/inference.rbs @@ -3,16 +3,18 @@ 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 + attr_reader endpoint_name: String + attr_reader endpoint_version: String + attr_reader extras: Extras::Extras + attr_reader has_async: bool + attr_reader has_sync: bool + attr_reader is_rotation_applied: bool + attr_reader pages: Integer + attr_reader prediction: Prediction + attr_reader product: Mindee::Product + + def initialize: (Hash[String | Symbol, 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 diff --git a/sig/mindee/parsing/common/ocr/mvision_v1.rbs b/sig/mindee/parsing/common/ocr/mvision_v1.rbs index e178c3e05..aeaf6b25f 100644 --- a/sig/mindee/parsing/common/ocr/mvision_v1.rbs +++ b/sig/mindee/parsing/common/ocr/mvision_v1.rbs @@ -5,9 +5,9 @@ module Mindee module OCR class MVisionV1 def pages: -> [] - def initialize: (untyped) -> untyped + def initialize: (Hash[String | Symbol, untyped]) -> void def to_s: -> String - def reconstruct_vertically: (untyped, untyped, untyped) -> untyped + def reconstruct_vertically: (Array[Geometry::Point], Integer, Float) -> OCRLine end end end diff --git a/sig/mindee/parsing/common/ocr/ocr.rbs b/sig/mindee/parsing/common/ocr/ocr.rbs index dbf97e19e..1d638d627 100644 --- a/sig/mindee/parsing/common/ocr/ocr.rbs +++ b/sig/mindee/parsing/common/ocr/ocr.rbs @@ -4,34 +4,36 @@ module Mindee module Common module OCR class OCRWord - def confidence: -> untyped - def confidence=: (untyped) -> untyped - def text: -> untyped - def bounding_box: -> untyped - def polygon: -> untyped - def initialize: (untyped) -> void - def to_s: -> untyped + attr_reader bounding_box: Geometry::Quadrilateral + attr_accessor confidence: Float + attr_reader polygon: Geometry::Polygon + attr_reader text: String + + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String end - class OCRLine < Array[untyped] - def initialize: (?Array[untyped]?, ?Array[untyped]?) -> void + class OCRLine < Array[OCRWord] + def initialize: (?Array[untyped]?, ?Array[OCRWord]?) -> 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] + attr_reader all_words: Array[OCRWord] + attr_reader lines: Array[OCRLine] + + def initialize: (Hash[String | Symbol, untyped]) -> void + def all_lines: -> Array[OCRLine] 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 + def parse_one: (Array[OCRWord], OCRWord, Array[Integer], Array[OCRLine]) -> Array[OCRLine]? + def to_lines: -> Array[OCRLine] + def words_on_same_line?: (OCRWord, OCRWord) -> bool end class OCR - def mvision_v1: -> untyped - def initialize: (untyped) -> untyped - def to_s: -> untyped - def reconstruct_vertically: (untyped, untyped, ?Float) -> untyped + attr_reader mvision_v1: MVisionV1 + + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String + def reconstruct_vertically: (Array[Geometry::Point], Integer, ?Float) -> OCRLine end end end diff --git a/sig/mindee/parsing/common/orientation.rbs b/sig/mindee/parsing/common/orientation.rbs index 1c7891442..3e0438978 100644 --- a/sig/mindee/parsing/common/orientation.rbs +++ b/sig/mindee/parsing/common/orientation.rbs @@ -3,9 +3,10 @@ module Mindee module Parsing module Common class Orientation - def page_id: -> untyped - def value: -> untyped - def initialize: (untyped, untyped) -> untyped + attr_reader page_id: Integer? + attr_reader value: Integer? + + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void end end end diff --git a/sig/mindee/parsing/common/page.rbs b/sig/mindee/parsing/common/page.rbs index b01496322..e86768565 100644 --- a/sig/mindee/parsing/common/page.rbs +++ b/sig/mindee/parsing/common/page.rbs @@ -3,11 +3,12 @@ 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 + attr_reader extras: Extras::Extras + attr_reader orientation: Common::Orientation + attr_reader page_id: Integer + attr_reader prediction: Common::Prediction + + def initialize: (Hash[String | Symbol, untyped]) -> void def to_s: -> String end end diff --git a/sig/mindee/parsing/common/product.rbs b/sig/mindee/parsing/common/product.rbs index 066b25774..e9b1c873e 100644 --- a/sig/mindee/parsing/common/product.rbs +++ b/sig/mindee/parsing/common/product.rbs @@ -3,10 +3,10 @@ module Mindee module Parsing module Common class Product - def name: -> untyped - def type: -> untyped - def version: -> untyped - def initialize: (Hash[String, untyped]) -> untyped + attr_reader name: String + attr_reader type: String? + attr_reader version: String + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/parsing/standard/company_registration_field.rbs b/sig/mindee/parsing/standard/company_registration_field.rbs index 4e18c623f..58b38d9cf 100644 --- a/sig/mindee/parsing/standard/company_registration_field.rbs +++ b/sig/mindee/parsing/standard/company_registration_field.rbs @@ -3,8 +3,9 @@ module Mindee module Parsing module Standard class CompanyRegistrationField < BaseField - def type: -> untyped - def initialize: (untyped, untyped, ?reconstructed: false) -> untyped + attr_reader type: String + + def initialize: (Hash[String | Symbol, untyped], Integer?, ?reconstructed: false) -> void def to_table_line: -> String def to_s: -> String def printable_values: -> Hash[String, untyped] diff --git a/sig/mindee/parsing/standard/tax_field.rbs b/sig/mindee/parsing/standard/tax_field.rbs index 0a62bfe56..6b07d7d65 100644 --- a/sig/mindee/parsing/standard/tax_field.rbs +++ b/sig/mindee/parsing/standard/tax_field.rbs @@ -3,18 +3,19 @@ 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 + attr_reader base: Float + attr_reader code: String + attr_reader rate: Float + attr_reader value: Float? + + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void + def print_float: (Float) -> 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 initialize: (Hash[String | Symbol, untyped], Integer?) -> void def line_separator: (String) -> String def to_s: -> String end diff --git a/sig/mindee/parsing/universal/universal_list_field.rbs b/sig/mindee/parsing/universal/universal_list_field.rbs index 692cb141e..3a8cfa6f3 100644 --- a/sig/mindee/parsing/universal/universal_list_field.rbs +++ b/sig/mindee/parsing/universal/universal_list_field.rbs @@ -3,11 +3,10 @@ module Mindee module Parsing module Universal class UniversalListField - def page_id: -> Integer? - def page_id=: (Integer?) -> untyped - def values: -> Array[UniversalObjectField | Standard::StringField] - def values=: (Array[UniversalObjectField | Standard::StringField]) -> Array[UniversalObjectField | Standard::StringField] - def initialize: (Array[Hash[Symbol | String, untyped]], ?nil) -> untyped + attr_reader page_id: Integer + attr_reader values: Array[UniversalObjectField | Standard::StringField] + + def initialize: (Array[Hash[Symbol | String, untyped]], Integer?) -> void def contents_list: -> Array[String] def contents_string: (?String) -> String def to_s: -> String diff --git a/sig/mindee/parsing/universal/universal_object_field.rbs b/sig/mindee/parsing/universal/universal_object_field.rbs index 5e97e6724..bddb869cd 100644 --- a/sig/mindee/parsing/universal/universal_object_field.rbs +++ b/sig/mindee/parsing/universal/universal_object_field.rbs @@ -3,19 +3,18 @@ module Mindee module Parsing module Universal class UniversalObjectField - def page_id: -> Integer? - def page_id=: (Integer?) -> untyped - def confidence: -> Float? - def confidence=: (Float?) -> untyped - def raw_value: -> Hash[Symbol | String, untyped] - def raw_value=: (Hash[Symbol | String, untyped]) -> untyped + attr_reader all_values: Hash[String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil] + attr_reader confidence: Float + attr_reader page_id: Integer + attr_reader raw_value: String + def initialize: (Hash[Symbol | String, untyped], ?Integer?) -> void def str_level: (?Integer) -> String - def method_missing: (Symbol, *Array[untyped]) -> Object + def method_missing: (Symbol, *Array[untyped]) -> (Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil) def respond_to_missing?: (Symbol, ?bool) -> bool def to_s: -> String - def handle_position_field: (String | Symbol, untyped, Integer?) -> void - def handle_default_field: (String | Symbol, untyped) -> void + def handle_position_field: (String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil, Integer?) -> void + def handle_default_field: (String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil) -> void end def self.universal_object?: (Hash[Symbol | String, untyped]) -> bool end diff --git a/sig/mindee/pdf/extracted_pdf.rbs b/sig/mindee/pdf/extracted_pdf.rbs index ed76f17f7..d2f2427aa 100644 --- a/sig/mindee/pdf/extracted_pdf.rbs +++ b/sig/mindee/pdf/extracted_pdf.rbs @@ -3,12 +3,12 @@ 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 + attr_reader pdf_bytes: StringIO + attr_reader filename: String + def initialize: (StringIO, String) -> void + def page_count: -> Integer + def write_to_file: (String, ?override: bool) -> Integer + def as_input_source: -> Input::Source::BytesInputSource end end end diff --git a/sig/mindee/pdf/pdf_compressor.rbs b/sig/mindee/pdf/pdf_compressor.rbs index 91e0bbfed..8ece7fff4 100644 --- a/sig/mindee/pdf/pdf_compressor.rbs +++ b/sig/mindee/pdf/pdf_compressor.rbs @@ -4,7 +4,7 @@ PDF: untyped module Mindee module PDF module PDFCompressor - def self.logger: () -> untyped + def self.logger: () -> Logger 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 diff --git a/sig/mindee/pdf/pdf_extractor.rbs b/sig/mindee/pdf/pdf_extractor.rbs index 0ee8ba94c..d8b25fdc3 100644 --- a/sig/mindee/pdf/pdf_extractor.rbs +++ b/sig/mindee/pdf/pdf_extractor.rbs @@ -3,13 +3,16 @@ 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: bool) -> Array[untyped] + attr_reader filename: String + attr_reader source_pdf: StringIO + + def initialize: (Input::Source::LocalInputSource) -> void + def page_count: -> Integer + def cut_pages: (Array[Integer]) -> StringIO + def extract_sub_documents: (Array[Array[Integer]]) -> Array[ExtractedPDF] + def extract_invoices: (Array[Array[Integer]], ?strict: bool) -> Array[ExtractedPDF] def source_pdf: -> StringIO - def filename: -> untyped + def filename: -> String end end end diff --git a/sig/mindee/pdf/pdf_processor.rbs b/sig/mindee/pdf/pdf_processor.rbs index 3697527a7..3c0a5a33b 100644 --- a/sig/mindee/pdf/pdf_processor.rbs +++ b/sig/mindee/pdf/pdf_processor.rbs @@ -3,8 +3,8 @@ module Mindee module PDF module PDFProcessor def self.parse: (StringIO, PageOptions) -> StringIO - def self.indexes_from_keep: (Array[Integer], Array[untyped]) -> (Array[Integer] | Array[untyped]) - def self.indexes_from_remove: (Array[Integer], Array[untyped]) -> (Array[Integer] | Array[untyped]) + def self.indexes_from_keep: (Array[Integer], Array[Integer]) -> (Array[Integer]) + def self.indexes_from_remove: (Array[Integer], Array[Integer]) -> (Array[Integer]) def self.open_pdf: (StringIO) -> Origami::PDF def self.get_page: (Origami::PDF, Integer) -> StringIO end diff --git a/sig/mindee/pdf/pdf_tools.rbs b/sig/mindee/pdf/pdf_tools.rbs index 5e96d9f38..5ecc723c6 100644 --- a/sig/mindee/pdf/pdf_tools.rbs +++ b/sig/mindee/pdf/pdf_tools.rbs @@ -2,22 +2,21 @@ 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 + BitsPerComponent: Integer + ColorSpace: Symbol + Height: Integer | Float + Width: Integer | Float + + def to_io_stream: (?Hash[String | Symbol, untyped]) -> StringIO + def self.stream_has_text?: (StringIO) -> bool + def self.source_text?: (StringIO) -> bool + def self.create_xobject: (singleton(MiniMagick::Image) | MiniMagick::Image | StringIO) -> Origami::Graphics::ImageXObject + def self.set_xobject_properties: (Origami::Graphics::ImageXObject, Hash[String | Symbol, untyped]) -> void + def self.determine_filter: (Hash[String | Symbol, untyped]) -> (:DCTDecode | :FlateDecode | :LZWDecode) + def self.determine_colorspace: (Hash[String | Symbol, untyped]) -> (:DeviceCMYK | :DeviceGray | :DeviceRGB) + def self.add_content_to_page: (Origami::Page, String, Integer, Integer) -> void + def self.set_page_dimensions: (Origami::Page, Integer | Float, Integer | Float) -> void + def self.process_image_xobject: (singleton(MiniMagick::Image) | MiniMagick::Image | StringIO, Integer, Integer | Float, Integer | Float) -> Origami::Graphics::ImageXObject end end end diff --git a/sig/mindee/product/universal/universal.rbs b/sig/mindee/product/universal/universal.rbs index 12ce49b1e..4371feccb 100644 --- a/sig/mindee/product/universal/universal.rbs +++ b/sig/mindee/product/universal/universal.rbs @@ -3,11 +3,11 @@ 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 + def initialize: (Hash[String | Symbol, untyped]) -> void + def endpoint_name: -> String + def endpoint_version: -> String + def has_async: -> bool + def has_sync: -> bool end end end diff --git a/spec/data b/spec/data index 632af76d6..f0175f0ee 160000 --- a/spec/data +++ b/spec/data @@ -1 +1 @@ -Subproject commit 632af76d6eefe551cdeb2b7fa2f325cecec1b66f +Subproject commit f0175f0ee644b57b409e6ad7e1c030f28fbe57ef From 49f44ef3683942ab9d1786b94b021f511356acfc Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 6 Aug 2025 11:32:46 +0200 Subject: [PATCH 06/19] apply suggested fixes --- lib/mindee/client_v2.rb | 33 ++++--------------- lib/mindee/input/inference_parameters.rb | 20 +++++++++++ lib/mindee/parsing/v2/field.rb | 1 - lib/mindee/parsing/v2/field/base_field.rb | 12 ++++++- lib/mindee/parsing/v2/field/dynamic_field.rb | 28 ---------------- lib/mindee/parsing/v2/field/list_field.rb | 2 +- lib/mindee/parsing/v2/field/object_field.rb | 2 +- lib/mindee/parsing/v2/field/simple_field.rb | 2 +- sig/mindee/input/inference_parameters.rbs | 2 ++ sig/mindee/parsing/v2/field/base_field.rbs | 1 + sig/mindee/parsing/v2/field/dynamic_field.rbs | 14 -------- sig/mindee/parsing/v2/field/list_field.rbs | 2 +- sig/mindee/parsing/v2/field/object_field.rbs | 2 +- sig/mindee/parsing/v2/field/simple_field.rbs | 2 +- 14 files changed, 46 insertions(+), 77 deletions(-) delete mode 100644 lib/mindee/parsing/v2/field/dynamic_field.rb delete mode 100644 sig/mindee/parsing/v2/field/dynamic_field.rbs diff --git a/lib/mindee/client_v2.rb b/lib/mindee/client_v2.rb index a52331053..209dcfc97 100644 --- a/lib/mindee/client_v2.rb +++ b/lib/mindee/client_v2.rb @@ -58,8 +58,7 @@ def enqueue_inference(input_source, params) # @return [Mindee::Parsing::V2::InferenceResponse] def enqueue_and_get_inference(input_source, params) normalized_params = normalize_inference_parameters(params) - validate_async_params(normalized_params.initial_delay_sec, normalized_params.delay_sec, - normalized_params.max_retries) + normalized_params.validate_async_params enqueue_response = enqueue_inference(input_source, normalized_params) if enqueue_response.job.id.nil? || enqueue_response.job.id.empty? @@ -67,12 +66,12 @@ def enqueue_and_get_inference(input_source, params) raise Mindee::Errors::MindeeError, 'Enqueueing of the document failed.' end - queue_id = enqueue_response.job.id - logger.debug("Successfully enqueued document with job id: #{queue_id}.") + job_id = enqueue_response.job.id + logger.debug("Successfully enqueued document with job id: #{job_id}.") sleep(normalized_params.polling_options.initial_delay_sec) retry_counter = 1 - poll_results = get_job(queue_id) + poll_results = get_job(job_id) while retry_counter < normalized_params.polling_options.max_retries if poll_results.job.status == 'Failed' @@ -82,13 +81,13 @@ def enqueue_and_get_inference(input_source, params) end logger.debug( - "Polling server for parsing result with queueId: #{queue_id}.\n" \ + "Successfully enqueued inference with job id: #{job_id}.\n" \ "Attempt n°#{retry_counter}/#{normalized_params.polling_options.max_retries}.\n" \ "Job status: #{poll_results.job.status}." ) sleep(normalized_params.polling_options.delay_sec) - poll_results = get_job(queue_id) + poll_results = get_job(job_id) retry_counter += 1 end @@ -104,26 +103,6 @@ def enqueue_and_get_inference(input_source, params) "Asynchronous parsing request timed out after #{sec_count} seconds" 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 max_retries [Integer] maximum amount of retries. - def validate_async_params(initial_delay_sec, delay_sec, max_retries) - min_delay_sec = 1 - min_initial_delay_sec = 1 - min_retries = 2 - - 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 ArgumentError, - "Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)" - end - raise ArgumentError, "Cannot set auto-poll retries to less than #{min_retries}" if max_retries < min_retries - end - # If needed, converts the parsing options provided as a hash into a proper InferenceParameters object. # @param params [Hash, InferenceParameters] Params. # @return [InferenceParameters] diff --git a/lib/mindee/input/inference_parameters.rb b/lib/mindee/input/inference_parameters.rb index ed2570b50..55d1c6e18 100644 --- a/lib/mindee/input/inference_parameters.rb +++ b/lib/mindee/input/inference_parameters.rb @@ -46,6 +46,26 @@ def initialize(params: {}) @polling_options = polling_options @close_file = params.fetch(:close_file, true) end + + # Validates the parameters for async auto-polling + def validate_async_params + min_delay_sec = 1 + min_initial_delay_sec = 1 + min_retries = 2 + + if @polling_options.delay_sec < min_delay_sec + raise ArgumentError, + "Cannot set auto-poll delay to less than #{min_delay_sec} second(s)" + end + if @polling_options.initial_delay_sec < min_initial_delay_sec + raise ArgumentError, + "Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)" + end + return unless @polling_options.max_retries < min_retries + + raise ArgumentError, + "Cannot set auto-poll retries to less than #{min_retries}" + end end end end diff --git a/lib/mindee/parsing/v2/field.rb b/lib/mindee/parsing/v2/field.rb index 5ba30bf44..b90f7fc7a 100644 --- a/lib/mindee/parsing/v2/field.rb +++ b/lib/mindee/parsing/v2/field.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require_relative 'field/base_field' -require_relative 'field/dynamic_field' require_relative 'field/field_confidence' require_relative 'field/field_location' require_relative 'field/inference_fields' diff --git a/lib/mindee/parsing/v2/field/base_field.rb b/lib/mindee/parsing/v2/field/base_field.rb index e33c69f0e..172404dd3 100644 --- a/lib/mindee/parsing/v2/field/base_field.rb +++ b/lib/mindee/parsing/v2/field/base_field.rb @@ -12,11 +12,21 @@ class BaseField # @return [FieldConfidence, nil] Confidence score for the field. attr_reader :confidence + # @return [Array] List of locations the field was found at. + attr_reader :locations + # @param raw_prediction [Hash] Raw prediction hash. # @param indent_level [Integer] Level of indentation for rst display. def initialize(raw_prediction, indent_level = 0) @indent_level = indent_level - @confidence = raw_prediction['confidence'] ? raw_prediction.key?('confidence') : nil + @confidence = raw_prediction.key?('confidence') ? raw_prediction['confidence'] : nil + @locations = if raw_prediction.key?('locations') + raw_prediction['locations'].map do |location| + FieldLocation.new(location) + end + else + [] + end end # Factory method to create appropriate field types. diff --git a/lib/mindee/parsing/v2/field/dynamic_field.rb b/lib/mindee/parsing/v2/field/dynamic_field.rb deleted file mode 100644 index 4ae4b3654..000000000 --- a/lib/mindee/parsing/v2/field/dynamic_field.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module Mindee - module Parsing - module V2 - module Field - # Extension of the base field class for V2 fields, with location data. - class DynamicField < BaseField - # @return [Array, nil] List of possible locations for a field. - attr_reader :locations - - # @param raw_prediction [Hash] Raw prediction hash. - # @param indent_level [Integer] Level of indentation for rst display. - def initialize(raw_prediction, indent_level = 0) - super - - # Process locations if present - return unless raw_prediction['locations'] - - @locations = raw_prediction['locations'].map do |location| - location ? FieldLocation.new(location) : nil - end.compact - end - end - end - end - end -end diff --git a/lib/mindee/parsing/v2/field/list_field.rb b/lib/mindee/parsing/v2/field/list_field.rb index ebc7d6331..1eafc3046 100644 --- a/lib/mindee/parsing/v2/field/list_field.rb +++ b/lib/mindee/parsing/v2/field/list_field.rb @@ -7,7 +7,7 @@ module Parsing module V2 module Field # A field containing a list of other fields. - class ListField < DynamicField + class ListField < BaseField # @return [Array] Items contained in the list. attr_reader :items diff --git a/lib/mindee/parsing/v2/field/object_field.rb b/lib/mindee/parsing/v2/field/object_field.rb index fe415f085..89342a3e3 100644 --- a/lib/mindee/parsing/v2/field/object_field.rb +++ b/lib/mindee/parsing/v2/field/object_field.rb @@ -8,7 +8,7 @@ module Parsing module V2 module Field # A field containing a nested set of inference fields. - class ObjectField < DynamicField + class ObjectField < BaseField # @return [InferenceFields] Fields contained in the object. attr_reader :fields diff --git a/lib/mindee/parsing/v2/field/simple_field.rb b/lib/mindee/parsing/v2/field/simple_field.rb index 385dc5292..c54ea15ee 100644 --- a/lib/mindee/parsing/v2/field/simple_field.rb +++ b/lib/mindee/parsing/v2/field/simple_field.rb @@ -7,7 +7,7 @@ module Parsing module V2 module Field # A simple field with a scalar value. - class SimpleField < DynamicField + class SimpleField < BaseField # @return [String, Integer, Float, Boolean, nil] Value contained in the field. attr_reader :value diff --git a/sig/mindee/input/inference_parameters.rbs b/sig/mindee/input/inference_parameters.rbs index 36e9600c8..7b166b79a 100644 --- a/sig/mindee/input/inference_parameters.rbs +++ b/sig/mindee/input/inference_parameters.rbs @@ -10,6 +10,8 @@ module Mindee attr_reader webhook_ids: Array[String]? def initialize: (params: Hash[String | Symbol, untyped]) -> void + + def validate_async_params: -> void end end end diff --git a/sig/mindee/parsing/v2/field/base_field.rbs b/sig/mindee/parsing/v2/field/base_field.rbs index 4d8fce4c7..5c401ab1a 100644 --- a/sig/mindee/parsing/v2/field/base_field.rbs +++ b/sig/mindee/parsing/v2/field/base_field.rbs @@ -6,6 +6,7 @@ module Mindee class BaseField attr_reader indent_level: Integer attr_reader confidence: FieldConfidence? + attr_reader locations: Array[FieldLocation] def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void def self.create_field: (Hash[String | Symbol, untyped], ?Integer) -> (ListField | Field::ObjectField | Field::SimpleField) diff --git a/sig/mindee/parsing/v2/field/dynamic_field.rbs b/sig/mindee/parsing/v2/field/dynamic_field.rbs deleted file mode 100644 index 62eb4b92d..000000000 --- a/sig/mindee/parsing/v2/field/dynamic_field.rbs +++ /dev/null @@ -1,14 +0,0 @@ -# lib/mindee/parsing/v2/field/dynamic_field.rb -module Mindee - module Parsing - module V2 - module Field - class DynamicField < BaseField - attr_reader locations: Array[FieldLocation]? - - def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void - end - end - end - end -end diff --git a/sig/mindee/parsing/v2/field/list_field.rbs b/sig/mindee/parsing/v2/field/list_field.rbs index 1cc4ce306..c867ca2c5 100644 --- a/sig/mindee/parsing/v2/field/list_field.rbs +++ b/sig/mindee/parsing/v2/field/list_field.rbs @@ -3,7 +3,7 @@ module Mindee module Parsing module V2 module Field - class ListField < DynamicField + class ListField < BaseField include Enumerable[untyped] attr_reader items: Array[ListField | ObjectField | SimpleField | nil] def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void diff --git a/sig/mindee/parsing/v2/field/object_field.rbs b/sig/mindee/parsing/v2/field/object_field.rbs index 818dfb45d..52c159ea4 100644 --- a/sig/mindee/parsing/v2/field/object_field.rbs +++ b/sig/mindee/parsing/v2/field/object_field.rbs @@ -5,7 +5,7 @@ module Mindee module V2 module Field # A field containing a nested set of inference fields. - class ObjectField < DynamicField + class ObjectField < BaseField attr_reader fields: InferenceFields def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void def multi_str: -> String diff --git a/sig/mindee/parsing/v2/field/simple_field.rbs b/sig/mindee/parsing/v2/field/simple_field.rbs index f420a0967..282763389 100644 --- a/sig/mindee/parsing/v2/field/simple_field.rbs +++ b/sig/mindee/parsing/v2/field/simple_field.rbs @@ -3,7 +3,7 @@ module Mindee module Parsing module V2 module Field - class SimpleField < DynamicField + class SimpleField < BaseField attr_reader value: String | Integer | Float | bool | nil def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void From e9276106c1e4434b9222b8165c39507033072118 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 6 Aug 2025 12:29:57 +0200 Subject: [PATCH 07/19] minimal working version (no tests, no typecheck) --- docs/code_samples/default_v2.txt | 29 +++++++++++++++++ lib/mindee.rb | 5 +++ lib/mindee/client_v2.rb | 5 +-- lib/mindee/http/mindee_api_v2.rb | 31 ++++++++++--------- lib/mindee/parsing/v2/job.rb | 9 ++++-- .../input/sources/base64_input_source.rbs | 2 +- spec/test_code_samples.sh | 10 ++++++ 7 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 docs/code_samples/default_v2.txt diff --git a/docs/code_samples/default_v2.txt b/docs/code_samples/default_v2.txt new file mode 100644 index 000000000..73dfcc3d9 --- /dev/null +++ b/docs/code_samples/default_v2.txt @@ -0,0 +1,29 @@ +require 'mindee' + +input_path = '/path/to/the/file.ext' +api_key = 'MY_API_KEY' +model_id = 'MY_MODEL_ID' + +# Init a new client +mindee_client = Mindee::ClientV2.new(api_key: api_key) + +# Set inference parameters +params = Mindee::Input::InferenceParameters.new( + params: { + # ID of the model, required. + model_id: model_id, + # If set to `True`, will enable Retrieval-Augmented Generation. + rag: false, + } +) + +# Load a file from disk +input_source = Mindee::Input::Source::PathInputSource.new(input_path) + +# Send for processing +response = mindee_client.enqueue_and_get_inference( + input_source, params +) + +# Print a brief summary of the parsed data +puts response.inference diff --git a/lib/mindee.rb b/lib/mindee.rb index 6c5bdb8d3..05378eb4e 100644 --- a/lib/mindee.rb +++ b/lib/mindee.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'mindee/client' +require 'mindee/client_v2' require 'mindee/page_options' require 'mindee/logging' @@ -55,6 +56,10 @@ module Standard # Universal fields and functions. module Universal end + + # V2-specific module. + module V2 + end end # Document input-related internals. diff --git a/lib/mindee/client_v2.rb b/lib/mindee/client_v2.rb index 209dcfc97..30100b1fd 100644 --- a/lib/mindee/client_v2.rb +++ b/lib/mindee/client_v2.rb @@ -8,9 +8,6 @@ require_relative 'parsing/common/workflow_response' require_relative 'logging' -# Default owner for products. -OTS_OWNER = 'mindee' - module Mindee # Mindee API Client. # See: https://developers.mindee.com/docs @@ -107,7 +104,7 @@ def enqueue_and_get_inference(input_source, params) # @param params [Hash, InferenceParameters] Params. # @return [InferenceParameters] def normalize_inference_parameters(params) - return params if params.is_a?(InferenceParameters) + return params if params.is_a?(Mindee::Input::InferenceParameters) InferenceParameters.new(params: params) end diff --git a/lib/mindee/http/mindee_api_v2.rb b/lib/mindee/http/mindee_api_v2.rb index c9a19f517..92cf3b3ab 100644 --- a/lib/mindee/http/mindee_api_v2.rb +++ b/lib/mindee/http/mindee_api_v2.rb @@ -50,7 +50,7 @@ def req_get_inference(inference_id) # @return [Mindee::Parsing::V2::JobResponse] def req_get_job(job_id) @settings.check_api_key - response = inference_result_req_get( + response = inference_job_req_get( job_id ) Parsing::V2::JobResponse.new(process_response(response)) @@ -100,7 +100,7 @@ def poll(url) # @param job_id [String] ID of the job. # @return [Net::HTTPResponse] def inference_job_req_get(job_id) - poll("#{@url_root}/jobs/#{job_id}") + poll("#{@settings.base_url}/jobs/#{job_id}") end # Polls the API for the result of an inference. @@ -108,31 +108,32 @@ def inference_job_req_get(job_id) # @param queue_id [String] ID of the queue. # @return [Net::HTTPResponse] def inference_result_req_get(queue_id) - poll("#{@url_root}/inferences/#{queue_id}") + poll("#{@settings.base_url}/inferences/#{queue_id}") end # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # @param params [Input::InferenceParameters] Parse options. # @return [Net::HTTPResponse, nil] def enqueue(input_source, params) - uri = URI("#{@settings.url_root}/inferences/enqueue") - - req_params = { model_id: params[:model_id] } - req_params[:rag] = 'true' if params.rag - req_params[:file_alias] = params.full_text if params.full_text - req_params[:webhook_ids] = params.webhook_ids.join(',') if params.webhook_ids - uri.query = URI.encode_www_form(req_params) + uri = URI("#{@settings.base_url}/inferences/enqueue") + form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource) + [['url', input_source.url]] # : Array[untyped] + else + file_data, file_metadata = input_source.read_contents(close: params.close_file) + [['file', file_data, file_metadata]] # : Array[untyped] + end + form_data.push ['model_id', params.model_id] + form_data.push ['rag', 'true'] if params.rag + form_data.push ['file_alias', params.file_alias] if params.file_alias + unless params.webhook_ids.nil? || params.webhook_ids.empty? + form_data.push ['webhook_ids', params.webhook_ids.join(',')] + end headers = { 'Authorization' => @settings.api_key, 'User-Agent' => @settings.user_agent, } req = Net::HTTP::Post.new(uri, headers) - form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource) - [['url', input_source.url]] # : Array[untyped] - else - ['file', input_source.read_contents(close: params.close_file)] # : Array[untyped] - end req.set_form(form_data, 'multipart/form-data') req['Transfer-Encoding'] = 'chunked' diff --git a/lib/mindee/parsing/v2/job.rb b/lib/mindee/parsing/v2/job.rb index c0c74de80..67e7e8501 100644 --- a/lib/mindee/parsing/v2/job.rb +++ b/lib/mindee/parsing/v2/job.rb @@ -36,14 +36,19 @@ def initialize(server_response) @id = server_response['id'] @status = server_response['status'] if server_response.key?('status') - @error = build_error(server_response['error']) + unless server_response['error'].nil? || server_response['error'].empty? + @error = ErrorResponse.new(server_response['error']) + end @created_at = Time.iso8601(server_response['created_at']) @model_id = server_response['model_id'] @polling_url = server_response['polling_url'] @filename = server_response['filename'] @result_url = server_response['result_url'] @alias = server_response['alias'] - @webhooks = JobWebhook.new(server_response['webhooks']) + @webhooks = [] + server_response['webhooks'].each do |webhook| + @webhooks.push JobWebhook.new(webhook) + end end # RST-style string representation, useful for debugging or logs. diff --git a/sig/mindee/input/sources/base64_input_source.rbs b/sig/mindee/input/sources/base64_input_source.rbs index babd5a6f9..6216e3049 100644 --- a/sig/mindee/input/sources/base64_input_source.rbs +++ b/sig/mindee/input/sources/base64_input_source.rbs @@ -4,7 +4,7 @@ module Mindee module Source class Base64InputSource < LocalInputSource def initialize: (String, String, ?repair_pdf: bool) -> void - def read_contents: (?close: bool) -> [String, Hash[Symbol, untyped]] + def read_contents: (?close: bool) -> [String?, Hash[:filename, String]] end end end diff --git a/spec/test_code_samples.sh b/spec/test_code_samples.sh index 2860be1c8..5bce39501 100755 --- a/spec/test_code_samples.sh +++ b/spec/test_code_samples.sh @@ -5,6 +5,8 @@ OUTPUT_FILE='./_test.rb' ACCOUNT=$1 ENDPOINT=$2 API_KEY=$3 +API_KEY_V2=$4 +MODEL_ID=$5 if [ -z "${ACCOUNT}" ]; then echo "ACCOUNT is required"; exit 1; fi if [ -z "${ENDPOINT}" ]; then echo "ENDPOINT is required"; exit 1; fi @@ -20,6 +22,14 @@ do sed "s/my-api-key/${API_KEY}/" "$f" > $OUTPUT_FILE sed -i 's/\/path\/to\/the\/file.ext/.\/spec\/data\/file_types\/pdf\/blank_1.pdf/' $OUTPUT_FILE + if echo "${f}" | grep -q "default_v2.txt" + then + sed -i "s/MY_API_KEY/$API_KEY_V2/" $OUTPUT_FILE + sed -i "s/MY_MODEL_ID/$MODEL_ID/" $OUTPUT_FILE + else + sed -i "s/my-api-key/$API_KEY/" $OUTPUT_FILE + fi + if echo "$f" | grep -q "custom_v1.txt" then sed -i "s/my-account/$ACCOUNT/g" $OUTPUT_FILE From ba4be04bb0b3600a79dafe2ac39e1be26ed34d3b Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Fri, 8 Aug 2025 11:10:14 +0200 Subject: [PATCH 08/19] fix all typing issues. --- .github/workflows/pull-request.yml | 12 +++++++---- lib/mindee/client.rb | 10 ++++----- lib/mindee/client_v2.rb | 6 +++--- lib/mindee/errors/mindee_http_error_v2.rb | 5 ++++- lib/mindee/http/api_settings_v2.rb | 4 ++-- lib/mindee/http/endpoint.rb | 10 +++++++-- lib/mindee/http/http_error_handler.rb | 10 ++++----- lib/mindee/http/mindee_api_v2.rb | 7 ++++--- lib/mindee/image/extracted_image.rb | 2 +- .../input/sources/local_input_source.rb | 15 ++++++------- lib/mindee/parsing/common/extras/extras.rb | 4 ++-- lib/mindee/parsing/common/ocr/ocr.rb | 4 +--- lib/mindee/parsing/standard/amount_field.rb | 4 ++-- lib/mindee/parsing/standard/tax_field.rb | 2 +- lib/mindee/parsing/v2/field/base_field.rb | 2 +- lib/mindee/parsing/v2/field/field_location.rb | 2 +- .../parsing/v2/field/inference_fields.rb | 19 +++++++++-------- lib/mindee/parsing/v2/field/list_field.rb | 20 +++++++----------- lib/mindee/parsing/v2/field/object_field.rb | 4 ++-- lib/mindee/parsing/v2/field/simple_field.rb | 6 ++++-- lib/mindee/parsing/v2/job_webhook.rb | 2 +- lib/mindee/pdf/extracted_pdf.rb | 2 +- lib/mindee/pdf/pdf_extractor.rb | 16 ++++++++------ sig/custom/mini_magick.rbs | 21 ++++++++++++------- sig/custom/net_http.rbs | 5 +++-- sig/custom/origami.rbs | 14 ++++++------- sig/mindee/client.rbs | 2 +- sig/mindee/client_v2.rbs | 1 + sig/mindee/errors/mindee_http_error_v2.rbs | 2 +- sig/mindee/geometry/utils.rbs | 2 +- sig/mindee/http/api_settings_v2.rbs | 3 ++- sig/mindee/http/endpoint.rbs | 8 +------ sig/mindee/http/http_error_handler.rbs | 10 ++++++--- sig/mindee/http/mindee_api_v2.rbs | 2 +- sig/mindee/image/extracted_image.rbs | 2 +- sig/mindee/image/image_compressor.rbs | 2 +- sig/mindee/image/image_extractor.rbs | 10 ++++----- sig/mindee/image/image_utils.rbs | 8 +++---- sig/mindee/input/local_response.rbs | 2 +- .../input/sources/local_input_source.rbs | 8 ++----- sig/mindee/logging/logger.rbs | 2 ++ sig/mindee/page_options.rbs | 14 +++++++------ .../parsing/common/extras/cropper_extra.rbs | 2 +- sig/mindee/parsing/common/extras/extras.rbs | 2 +- .../common/extras/full_text_ocr_extra.rbs | 3 ++- sig/mindee/parsing/common/inference.rbs | 9 ++++++-- sig/mindee/parsing/common/ocr/ocr.rbs | 2 +- sig/mindee/parsing/standard/date_field.rbs | 2 +- sig/mindee/parsing/standard/tax_field.rbs | 2 +- .../universal/universal_list_field.rbs | 2 +- .../universal/universal_object_field.rbs | 11 ++++++++-- .../parsing/v2/field/field_confidence.rbs | 2 +- .../parsing/v2/field/field_location.rbs | 2 +- .../parsing/v2/field/inference_fields.rbs | 3 ++- sig/mindee/parsing/v2/field/list_field.rbs | 10 +++++---- sig/mindee/parsing/v2/field/simple_field.rbs | 2 +- sig/mindee/pdf/pdf_compressor.rbs | 6 +++--- sig/mindee/pdf/pdf_extractor.rbs | 4 +--- sig/mindee/pdf/pdf_processor.rbs | 4 ++-- sig/mindee/pdf/pdf_tools.rbs | 21 ++++++++++++------- 60 files changed, 210 insertions(+), 165 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2690f22cd..6527968fb 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -3,18 +3,22 @@ name: Pull Request on: pull_request: +permissions: + contents: read + pull-requests: read + jobs: static_analysis: - uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@main + uses: ./.github/workflows/_static-analysis.yml test_units: - uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@main + uses: ./.github/workflows/_test-units.yml needs: static_analysis secrets: inherit test_integrations: - uses: mindee/mindee-api-ruby/.github/workflows/_test-integrations.yml@main + uses: ./.github/workflows/_test-integrations.yml needs: test_units secrets: inherit test_code_samples: - uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@main + uses: ./.github/workflows/_test-code-samples.yml needs: test_units secrets: inherit diff --git a/lib/mindee/client.rb b/lib/mindee/client.rb index 67122b2d9..39ef0dec8 100644 --- a/lib/mindee/client.rb +++ b/lib/mindee/client.rb @@ -307,7 +307,7 @@ def execute_workflow(input_source, workflow_id, options: {}) process_pdf_if_required(input_source, opts) end - workflow_endpoint = Mindee::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key) + workflow_endpoint = Mindee::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key.to_s) logger.debug("Sending document to workflow '#{workflow_id}'") prediction, raw_http = workflow_endpoint.execute_workflow( @@ -436,11 +436,11 @@ def initialize_endpoint(product_class, endpoint_name: '', account_name: '', vers 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) + HTTP::Endpoint.new(account_name, endpoint_name, version, api_key: @api_key.to_s) end def fix_endpoint_name(product_class, endpoint_name) - endpoint_name.nil? || endpoint_name.empty? ? product_class.endpoint_name : endpoint_name + endpoint_name.nil? || endpoint_name.empty? ? product_class.endpoint_name.to_s : endpoint_name.to_s end def fix_account_name(account_name) @@ -455,11 +455,11 @@ def fix_account_name(account_name) def fix_version(product_class, version) return version unless version.nil? || version.empty? - if product_class.endpoint_version.nil? || product_class.endpoint_version.empty? + if product_class.endpoint_version.nil? || product_class.endpoint_version.to_s.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 + product_class.endpoint_version || '' end # If needed, converts the parsing options provided as a hash into a proper ParseOptions object. diff --git a/lib/mindee/client_v2.rb b/lib/mindee/client_v2.rb index 30100b1fd..de751b2ef 100644 --- a/lib/mindee/client_v2.rb +++ b/lib/mindee/client_v2.rb @@ -17,7 +17,7 @@ class ClientV2 # @param api_key [String] def initialize(api_key: '') - @mindee_api = Mindee::HTTP::MindeeApiV2.new(api_key) + @mindee_api = Mindee::HTTP::MindeeApiV2.new(api_key: api_key) end # Retrieves an inference. @@ -104,9 +104,9 @@ def enqueue_and_get_inference(input_source, params) # @param params [Hash, InferenceParameters] Params. # @return [InferenceParameters] def normalize_inference_parameters(params) - return params if params.is_a?(Mindee::Input::InferenceParameters) + return params if params.is_a?(Input::InferenceParameters) - InferenceParameters.new(params: params) + Input::InferenceParameters.new(params: params) end end end diff --git a/lib/mindee/errors/mindee_http_error_v2.rb b/lib/mindee/errors/mindee_http_error_v2.rb index e7b3605f7..7daaa8eed 100644 --- a/lib/mindee/errors/mindee_http_error_v2.rb +++ b/lib/mindee/errors/mindee_http_error_v2.rb @@ -13,7 +13,10 @@ class MindeeHTTPErrorV2 < MindeeError # @param http_error [Hash, Parsing::V2::ErrorResponse] def initialize(http_error) - http_error = http_error.as_hash if http_error.is_a?(Parsing::V2::ErrorResponse) + if http_error.is_a?(Parsing::V2::ErrorResponse) + http_error = { 'detail' => http_error.detail, + 'status' => http_error.status } + end @status = http_error['status'] @detail = http_error['detail'] super("HTTP error: #{@status} - #{@detail}") diff --git a/lib/mindee/http/api_settings_v2.rb b/lib/mindee/http/api_settings_v2.rb index 00b74e155..0e09dfb4d 100644 --- a/lib/mindee/http/api_settings_v2.rb +++ b/lib/mindee/http/api_settings_v2.rb @@ -31,7 +31,7 @@ class ApiSettingsV2 # @return [String] attr_reader :user_agent - def initialize(api_key: '') + def initialize(api_key: nil) @request_timeout = ENV.fetch(MINDEE_V2_REQUEST_TIMEOUT_ENV_NAME, MINDEE_V2_TIMEOUT_DEFAULT).to_i if api_key.nil? && !ENV.fetch(MINDEE_V2_API_KEY_ENV_NAME, MINDEE_V2_API_KEY_DEFAULT).to_s.empty? logger.debug('API key set from environment') @@ -50,7 +50,7 @@ def initialize(api_key: '') # @return # @raise [Errors::MindeeAPIError] Raises if the api key is empty or nil. def check_api_key - return unless @api_key.nil? || @api_key.empty? + return unless @api_key.nil? || @api_key.to_s.empty? raise Errors::MindeeAPIError, "Missing API key. check your Client Configuration.\nYou can set this using the " \ diff --git a/lib/mindee/http/endpoint.rb b/lib/mindee/http/endpoint.rb index 4345f0db1..ee4b8be67 100644 --- a/lib/mindee/http/endpoint.rb +++ b/lib/mindee/http/endpoint.rb @@ -66,6 +66,9 @@ def predict(input_source, opts) ResponseValidation.clean_request!(response) end + + raise Errors::MindeeError, 'Could not resolve server response.' if response.nil? + error = ErrorHandler.handle_error(@url_name, response) raise error end @@ -84,8 +87,9 @@ def predict_async(input_source, opts) ResponseValidation.clean_request!(response) end - error = ErrorHandler.handle_error(@url_name, response) - raise error + raise Errors::MindeeError, 'Could not resolve server response.' if response.nil? + + raise ErrorHandler.handle_error(@url_name, response) end # Calls the parsed async doc. @@ -189,6 +193,8 @@ def document_queue_req_get(job_id) http.request(req) end + raise Errors::MindeeError, 'Could not resolve server response.' if response.nil? + if response.code.to_i > 299 && response.code.to_i < 400 req = Net::HTTP::Get.new(response['location'], headers) Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @request_timeout) do |http| diff --git a/lib/mindee/http/http_error_handler.rb b/lib/mindee/http/http_error_handler.rb index 7aad09cc3..90d2b718b 100644 --- a/lib/mindee/http/http_error_handler.rb +++ b/lib/mindee/http/http_error_handler.rb @@ -65,7 +65,7 @@ def create_error_obj(response) end end - error_obj.nil? ? {} : error_obj + error_obj end # Creates an appropriate HTTP error exception, based on retrieved http error code @@ -81,18 +81,18 @@ def handle_error(url, response) error_obj = create_error_obj(parsed_hash) case code when 400..499 - Errors::MindeeHTTPClientError.new(error_obj, url, code) + Errors::MindeeHTTPClientError.new(error_obj || {}, url, code) when 500..599 - Errors::MindeeHTTPServerError.new(error_obj, url, code) + Errors::MindeeHTTPServerError.new(error_obj || {}, url, code) else - Errors::MindeeHTTPError.new(error_obj, url, code) + Errors::MindeeHTTPError.new(error_obj || {}, url, code) end end # Creates an appropriate HTTP error exception for a V2 API response, based on retrieved http error code. # @param hashed_response [Hash] dictionary response retrieved by the server def generate_v2_error(hashed_response) - code = hashed_response.code.to_i + code = hashed_response['code'].to_i if hashed_response.key?('status') Errors::MindeeHTTPErrorV2.new(hashed_response) elsif code < 200 || code > 399 diff --git a/lib/mindee/http/mindee_api_v2.rb b/lib/mindee/http/mindee_api_v2.rb index 92cf3b3ab..ec2f4f41e 100644 --- a/lib/mindee/http/mindee_api_v2.rb +++ b/lib/mindee/http/mindee_api_v2.rb @@ -13,7 +13,7 @@ class MindeeApiV2 attr_reader :settings # @param api_key [String, nil] - def initialize(api_key = nil) + def initialize(api_key: nil) @settings = ApiSettingsV2.new(api_key: api_key) end @@ -61,7 +61,7 @@ def req_get_job(job_id) # Converts an HTTP response to a parsed response object. # # @param response [Net::HTTPResponse, nil] - # @return [Hash] + # @return [Hash] # @raise Throws if the server returned an error. def process_response(response) if !response.nil? && response.respond_to?(:body) && ResponseValidation.valid_v2_response?(response) @@ -74,7 +74,8 @@ def process_response(response) else response.body end - raise ErrorHandler.generate_v2_error(response_body) + error = ErrorHandler.generate_v2_error(response_body.to_hash) # @type error: Errors::MindeeHTTPErrorV2 + raise error end # Polls a queue for either a result or a job. diff --git a/lib/mindee/image/extracted_image.rb b/lib/mindee/image/extracted_image.rb index ff764de62..71d525455 100644 --- a/lib/mindee/image/extracted_image.rb +++ b/lib/mindee/image/extracted_image.rb @@ -69,7 +69,7 @@ def write_to_file(output_path, file_format = nil) # @return [FileInputSource] A BufferInput source. def as_source @buffer.rewind - Mindee::Input::Source::BytesInputSource.new(@buffer.read, @internal_file_name) + Mindee::Input::Source::BytesInputSource.new(@buffer.read || '', @internal_file_name) end end end diff --git a/lib/mindee/input/sources/local_input_source.rb b/lib/mindee/input/sources/local_input_source.rb index 3aaced4ce..8e85b0cd4 100644 --- a/lib/mindee/input/sources/local_input_source.rb +++ b/lib/mindee/input/sources/local_input_source.rb @@ -27,7 +27,7 @@ class LocalInputSource attr_reader :filename # @return [String] attr_reader :file_mimetype - # @return [StringIO] + # @return [StringIO | File] attr_reader :io_stream # @param io_stream [StringIO, File] @@ -113,14 +113,15 @@ def read_contents(close: true) # 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 + t_path = if File.directory?(path || '') || path.to_s.end_with?('/') + File.join(path || '', @filename) + else + path + end + full_path = File.expand_path(t_path || '') FileUtils.mkdir_p(File.dirname(full_path)) @io_stream.rewind - File.binwrite(full_path, @io_stream.read) + File.binwrite(full_path, @io_stream.read || '') logger.debug("Wrote file successfully to #{full_path}") @io_stream.rewind end diff --git a/lib/mindee/parsing/common/extras/extras.rb b/lib/mindee/parsing/common/extras/extras.rb index b45a48550..d593b9821 100644 --- a/lib/mindee/parsing/common/extras/extras.rb +++ b/lib/mindee/parsing/common/extras/extras.rb @@ -11,7 +11,7 @@ module Extras class Extras # @return [CropperExtra, nil] attr_reader :cropper - # @return [Mindee::Parsing::Common::Extras::FullTextOCRExtra, nil] + # @return [Mindee::Parsing::Common::Extras::FullTextOCRExtra] attr_reader :full_text_ocr # @return [RAGExtra, nil] attr_reader :rag @@ -26,7 +26,7 @@ def initialize(raw_prediction) @rag = Mindee::Parsing::Common::Extras::RAGExtra.new(raw_prediction['rag']) if raw_prediction['rag'] raw_prediction.each do |key, value| - instance_variable_set("@#{key}", value) unless ['cropper', 'full_text_ocr', 'rag'].include?(key) + instance_variable_set("@#{key}", value) unless ['cropper', 'full_text_ocr', 'rag'].include?(key.to_s) end end diff --git a/lib/mindee/parsing/common/ocr/ocr.rb b/lib/mindee/parsing/common/ocr/ocr.rb index 5ee0c7cdd..4bc195ffc 100644 --- a/lib/mindee/parsing/common/ocr/ocr.rb +++ b/lib/mindee/parsing/common/ocr/ocr.rb @@ -48,9 +48,7 @@ def initialize(prediction = nil, from_array = nil) # Sort the words on the line from left to right. # @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 + from_array = sort_by { |word| Geometry.get_min_max_x(word.polygon).min } OCRLine.new(nil, from_array) end diff --git a/lib/mindee/parsing/standard/amount_field.rb b/lib/mindee/parsing/standard/amount_field.rb index 63074bbda..465a97d49 100644 --- a/lib/mindee/parsing/standard/amount_field.rb +++ b/lib/mindee/parsing/standard/amount_field.rb @@ -13,12 +13,12 @@ class AmountField < BaseField def initialize(prediction, page_id, reconstructed: false) super - @value = @value.round(3) unless @value.nil? + @value = @value.to_f.round(3).to_f unless @value.to_s.empty? end # @return [String] def to_s - BaseField.float_to_string(@value) + @value.nil? ? '' : BaseField.float_to_string(@value.to_f) end end end diff --git a/lib/mindee/parsing/standard/tax_field.rb b/lib/mindee/parsing/standard/tax_field.rb index a449f667f..045e180fb 100644 --- a/lib/mindee/parsing/standard/tax_field.rb +++ b/lib/mindee/parsing/standard/tax_field.rb @@ -52,7 +52,7 @@ def printable_values out_h[:code] = @code.nil? ? '' : @code out_h[:base] = @base.nil? ? '' : print_float(@base) out_h[:rate] = @rate.nil? ? '' : print_float(@rate).to_s - out_h[:value] = @value.nil? ? '' : print_float(@value).to_s + out_h[:value] = @value.to_s.empty? ? '' : print_float(@value.to_f).to_s out_h end diff --git a/lib/mindee/parsing/v2/field/base_field.rb b/lib/mindee/parsing/v2/field/base_field.rb index 172404dd3..73b50b154 100644 --- a/lib/mindee/parsing/v2/field/base_field.rb +++ b/lib/mindee/parsing/v2/field/base_field.rb @@ -50,7 +50,7 @@ def self.create_field(raw_prediction, indent_level = 0) return SimpleField.new(raw_prediction, indent_level) end - raise MindeeError, "Unrecognized field format in #{raw_prediction.to_json}" + raise Errors::MindeeError, "Unrecognized field format in #{raw_prediction.to_json}" end end end diff --git a/lib/mindee/parsing/v2/field/field_location.rb b/lib/mindee/parsing/v2/field/field_location.rb index b45f5a084..424473c9c 100644 --- a/lib/mindee/parsing/v2/field/field_location.rb +++ b/lib/mindee/parsing/v2/field/field_location.rb @@ -20,7 +20,7 @@ def initialize(server_response) @polygon = polygon_data ? Mindee::Geometry::Polygon.new(polygon_data) : nil page_id = server_response['page'] || server_response[:page] - @page = page_id.is_a?(Numeric) ? page_id.to_i : nil + @page = page_id.is_a?(Float) || page_id.is_a?(Integer) ? page_id.to_i : nil end # String representation of the polygon (empty string when none). diff --git a/lib/mindee/parsing/v2/field/inference_fields.rb b/lib/mindee/parsing/v2/field/inference_fields.rb index 5a9f9b1f3..a9bca5904 100644 --- a/lib/mindee/parsing/v2/field/inference_fields.rb +++ b/lib/mindee/parsing/v2/field/inference_fields.rb @@ -18,7 +18,7 @@ def initialize(server_response, indent_level = 0) @indent_level = indent_level server_response.each do |key, value| - self[key] = BaseField.create_field(value, 1) + self[key.to_s] = BaseField.create_field(value, 1) end end @@ -51,10 +51,9 @@ def respond_to_missing?(method_name, include_private = false) # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Metrics/PerceivedComplexity # Convert the fields to a string representation. - # @param original_indent [Integer, nil] Optional indentation level. + # @param indent [Integer, nil] Optional indentation level. # @return [String] String representation of all fields. - def to_s(original_indent = nil) - indent = indent.nil? ? 0 : original_indent + def to_s(indent = 0) return '' if empty? indent ||= @indent_level @@ -64,18 +63,20 @@ def to_s(original_indent = nil) each do |field_key, field_value| line = "#{padding}:#{field_key}:" - case field_value.class.name.split('::').last + case (field_value.class.name || '').split('::').last when 'ListField' # Check if ListField has items and they're not empty - if defined?(field_value.items) && field_value.items && !field_value.items.empty? - line += field_value.to_s + list_f = field_value # @type var list_f: ListField + if defined?(list_f.items) && list_f.items && !list_f.items.empty? + line += list_f.to_s end when 'ObjectField' line += field_value.to_s when 'SimpleField' # Check if SimpleField has a non-empty value - if defined?(field_value.value) && field_value.value && !field_value.value.to_s.empty? - line += " #{field_value.value}" + simple_f = field_value # @type var simple_f: SimpleField + if defined?(simple_f.value) && simple_f.value && !simple_f.value.to_s.empty? + line += " #{simple_f.value}" end else logger.debug("Unknown value was passed to the field creator: #{field_key} : #{field_value}") diff --git a/lib/mindee/parsing/v2/field/list_field.rb b/lib/mindee/parsing/v2/field/list_field.rb index 1eafc3046..e284950aa 100644 --- a/lib/mindee/parsing/v2/field/list_field.rb +++ b/lib/mindee/parsing/v2/field/list_field.rb @@ -8,6 +8,7 @@ module V2 module Field # A field containing a list of other fields. class ListField < BaseField + include Enumerable # @return [Array] Items contained in the list. attr_reader :items @@ -18,7 +19,7 @@ def initialize(server_response, indent_level = 0) super unless server_response.key?('items') && server_response['items'].is_a?(Array) - raise MindeeError, + raise Errors::MindeeError, "Expected \"items\" to be an array in #{server_response.to_json}." end @@ -65,15 +66,6 @@ def length @items.length end - # Iterate over the items in the list. - # @yield [BaseField] Each item in the list. - # @return [Array, Enumerator] If no block is given. - def each(&block) - return @items.to_enum unless block_given? - - @items.each(&block) - end - # Get an item by index. # @param index [Integer] The index of the item to retrieve. # @return [BaseField, nil] The item at the given index. @@ -81,8 +73,12 @@ def [](index) @items[index] end - # Array-like access methods - include Enumerable + def each(&block) + return to_enum(:each) unless block_given? + + @items.each(&block) + self + end end end end diff --git a/lib/mindee/parsing/v2/field/object_field.rb b/lib/mindee/parsing/v2/field/object_field.rb index 89342a3e3..a68aaf4f9 100644 --- a/lib/mindee/parsing/v2/field/object_field.rb +++ b/lib/mindee/parsing/v2/field/object_field.rb @@ -32,11 +32,11 @@ def to_s # String representation suitable for list display. # @return [String] String representation without leading spaces. def to_s_from_list + return '' if @fields.nil? return '' unless @fields && !@fields.empty? field_str = @fields.to_s(2) - # Remove the first 4 characters - field_str.length > 4 ? field_str[4..] : '' + field_str.length > 4 ? (field_str[4..] || '') : '' end # String representation of a single object field diff --git a/lib/mindee/parsing/v2/field/simple_field.rb b/lib/mindee/parsing/v2/field/simple_field.rb index c54ea15ee..1bb676765 100644 --- a/lib/mindee/parsing/v2/field/simple_field.rb +++ b/lib/mindee/parsing/v2/field/simple_field.rb @@ -28,8 +28,10 @@ def to_s 'True' when FalseClass 'False' - when Numeric - format_numeric_value(@value) + when Integer, Float + # NOTE: explicitly typing because steep is very, very dumb + num = @value # @type var num: Integer | Float + format_numeric_value(num) else @value.to_s end diff --git a/lib/mindee/parsing/v2/job_webhook.rb b/lib/mindee/parsing/v2/job_webhook.rb index c9e1e0007..4dd831853 100644 --- a/lib/mindee/parsing/v2/job_webhook.rb +++ b/lib/mindee/parsing/v2/job_webhook.rb @@ -50,7 +50,7 @@ def to_s def parse_date(str) return nil if str.to_s.empty? - DateTime.iso8601(str) + DateTime.iso8601(str || '') rescue ArgumentError nil end diff --git a/lib/mindee/pdf/extracted_pdf.rb b/lib/mindee/pdf/extracted_pdf.rb index 87e0ff4a4..5ac3f7671 100644 --- a/lib/mindee/pdf/extracted_pdf.rb +++ b/lib/mindee/pdf/extracted_pdf.rb @@ -52,7 +52,7 @@ def write_to_file(output_path, override: false) def as_input_source raise Errors::MindeePDFError, 'Bytes object is nil.' if @pdf_bytes.nil? - Mindee::Input::Source::BytesInputSource.new(@pdf_bytes.read, @filename) + Mindee::Input::Source::BytesInputSource.new(@pdf_bytes.read || '', @filename) end end end diff --git a/lib/mindee/pdf/pdf_extractor.rb b/lib/mindee/pdf/pdf_extractor.rb index 8014464df..45be549d8 100644 --- a/lib/mindee/pdf/pdf_extractor.rb +++ b/lib/mindee/pdf/pdf_extractor.rb @@ -75,24 +75,28 @@ def extract_sub_documents(page_indexes) # @return [Array] def extract_invoices(page_indexes, strict: false) raise Errors::MindeePDFError, 'No indexes provided.' if page_indexes.empty? + if page_indexes[0].is_a?(Array) && page_indexes[0].all? { |i| i.is_a?(Integer) } - return extract_sub_documents(page_indexes) + page_indexes_as_array = page_indexes # @type var page_indexes : Array[Array[Integer]] + return extract_sub_documents(page_indexes_as_array) end - return extract_sub_documents(page_indexes.map(&:page_indexes)) unless strict + 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 = [] previous_confidence = nil - page_indexes.each_with_index do |page_index, i| - confidence = page_index.confidence + p_ids.each_with_index do |p_i, i| + page_index = p_i # @type var page_index: Product::InvoiceSplitter::InvoiceSplitterV1InvoicePageGroup + confidence = page_index.confidence.to_f page_list = page_index.page_indexes if confidence >= 0.5 && previous_confidence.nil? current_list = page_list - elsif confidence >= 0.5 && i < page_indexes.length - 1 + elsif confidence >= 0.5 && i < p_ids.length - 1 correct_page_indexes << current_list current_list = page_list - elsif confidence < 0.5 && i == page_indexes.length - 1 + elsif confidence < 0.5 && i == p_ids.length - 1 current_list.concat page_list correct_page_indexes << current_list else diff --git a/sig/custom/mini_magick.rbs b/sig/custom/mini_magick.rbs index 11425857d..842bfbe59 100644 --- a/sig/custom/mini_magick.rbs +++ b/sig/custom/mini_magick.rbs @@ -1,24 +1,31 @@ # Stub for the mini_magick library. +# Note: though typing annotations for the MiniMagick library now exist, it seems that they aren't strict enough +# to match the rules we have on the repo, hence the existence of this file and the overrides present below. 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.format: (String, ?Integer?, ?Hash[Symbol, untyped]?) -> Net::BufferedIO + def format: (String, ?Integer?, ?Hash[Symbol, untyped]?) -> Net::BufferedIO def self.quality: (String) -> Net::BufferedIO def self.crop: (String) -> Net::BufferedIO + def crop: (String) -> Net::BufferedIO def self.height: () -> Integer - def height: () -> Integer def self.width: () -> Integer + def height: () -> Integer def width: () -> Integer - def self.read: (untyped) -> self + def self.data: (?untyped?, ?untyped?) -> untyped + def data: (?untyped?, ?untyped) -> instance + def self.read: (?untyped?, ?untyped?) -> Image + def read: (?untyped?, ?untyped) -> Image def self.resolution: () -> Array[Float | Integer] + def resolution: () -> Array[Float | Integer] def self.write: (StringIO | String) -> Net::BufferedIO def write: (StringIO | String) -> Net::BufferedIO - def quality: (Integer) -> void + def quality: (String) -> 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 + 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 8d6d08a43..a9052ab15 100644 --- a/sig/custom/net_http.rbs +++ b/sig/custom/net_http.rbs @@ -12,7 +12,7 @@ module Net # Stub for the HTTP POST request class. class Post - def initialize: (untyped, Hash[String, String]?) -> void + def initialize: (untyped, Hash[String, String?]?) -> void def set_form: (untyped, String?) -> void def new: (untyped, untyped) -> void def []=: (?untyped, ?untyped) -> bool @@ -20,7 +20,7 @@ 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 @@ -29,6 +29,7 @@ module Net class HTTPResponse def self.body: -> untyped + def body: -> untyped def []: (untyped) -> untyped def key?: (untyped) -> bool def code: -> String diff --git a/sig/custom/origami.rbs b/sig/custom/origami.rbs index ebdf067cf..070fbf74d 100644 --- a/sig/custom/origami.rbs +++ b/sig/custom/origami.rbs @@ -1,33 +1,32 @@ # Stubs for the origami library. # This one _should_ exist, but it would take too long, so this is a stub. module Origami - def intents_as_pdfa1: () -> void - def delinearize!: () -> void - def linearized?: () -> bool def compile: (Hash[Symbol, untyped]) -> void class Array def each: { (untyped) -> untyped } -> untyped end class PDF - def self.read: (StringIO) -> untyped + def self.read: (StringIO | File) -> untyped def initialize: () -> void def append_page: (Page) -> void def delete_pages_at: (::Array[Integer]) -> void def pages: () -> ::Array[Page] - def save: (StringIO) -> void + def save: (StringIO | File) -> void def to_io_stream: -> StringIO class LinearParser def initialize: (Hash[Symbol, untyped]) -> void def new: (Hash[Symbol, untyped]) -> void - def parse: (StringIO?) -> PDF + def parse: (StringIO | File | nil) -> PDF end - def compile: (Hash[String | Symbol, untyped]) -> StringIO end class Page def initialize: () -> void def add_xobject: (Graphics::ImageXObject, String) -> untyped def Contents: (?untyped?) -> untyped + def Contents=: (?untyped?, untyped?) -> untyped + def []: (untyped) -> untyped + def []=: (untyped, untyped) -> bool end module Graphics @@ -36,6 +35,7 @@ module Origami def BitsPerComponent=: (Integer) -> untyped def ColorSpace=: (Symbol) -> untyped + def dictionary: () -> Hash[Symbol, untyped] def data=: (StringIO) -> untyped def self.from_image_file: (StringIO, String) -> untyped def Height=: (Integer | Float) -> untyped diff --git a/sig/mindee/client.rbs b/sig/mindee/client.rbs index d4ff42009..9d7e1f883 100644 --- a/sig/mindee/client.rbs +++ b/sig/mindee/client.rbs @@ -31,7 +31,7 @@ module Mindee end class Client - @api_key: string | nil + @api_key: String? def initialize: (?api_key: String) -> void def logger: () -> Logging diff --git a/sig/mindee/client_v2.rbs b/sig/mindee/client_v2.rbs index fbcc2f858..d33cdbb5a 100644 --- a/sig/mindee/client_v2.rbs +++ b/sig/mindee/client_v2.rbs @@ -5,6 +5,7 @@ module Mindee class ClientV2 attr_reader mindee_api: HTTP::MindeeApiV2 + def logger: () -> Logger def initialize: (?api_key: String) -> void def get_inference: (String) -> Parsing::V2::InferenceResponse def get_job: (String) -> Parsing::V2::JobResponse diff --git a/sig/mindee/errors/mindee_http_error_v2.rbs b/sig/mindee/errors/mindee_http_error_v2.rbs index 96f3e36ac..b687f43cc 100644 --- a/sig/mindee/errors/mindee_http_error_v2.rbs +++ b/sig/mindee/errors/mindee_http_error_v2.rbs @@ -6,7 +6,7 @@ module Mindee attr_reader detail: String attr_reader status: Integer - def initialize: (Hash[String | Symbol, untyped] | Parsing::V2::ErrorResponse) -> void + def initialize: (Hash[String, untyped] | Parsing::V2::ErrorResponse) -> void end end end diff --git a/sig/mindee/geometry/utils.rbs b/sig/mindee/geometry/utils.rbs index a61eaca71..3631722cb 100644 --- a/sig/mindee/geometry/utils.rbs +++ b/sig/mindee/geometry/utils.rbs @@ -2,7 +2,7 @@ module Mindee module Geometry def self.quadrilateral_from_prediction: (Array[Array[Float]]) -> Quadrilateral - def self.polygon_from_prediction: (Hash[String | Symbol, untyped]) -> Polygon + def self.polygon_from_prediction: (Array[Array[Float]]) -> Polygon def self.get_bbox: (Array[Point]) -> [Float, Float, Float, Float] def self.get_bounding_box: (Array[Point]) -> Quadrilateral def self.get_centroid: (Array[Point]) -> Point diff --git a/sig/mindee/http/api_settings_v2.rbs b/sig/mindee/http/api_settings_v2.rbs index 3a99adedd..594b926cd 100644 --- a/sig/mindee/http/api_settings_v2.rbs +++ b/sig/mindee/http/api_settings_v2.rbs @@ -10,12 +10,13 @@ module Mindee MINDEE_V2_TIMEOUT_DEFAULT: Integer USER_AGENT: String + def logger: () -> Logger attr_reader api_key: String? attr_reader base_url: String attr_reader request_timeout: Integer attr_reader user_agent: String - def initialize: (?api_key: String) -> void + def initialize: (?api_key: String?) -> void def check_api_key: -> void end end diff --git a/sig/mindee/http/endpoint.rbs b/sig/mindee/http/endpoint.rbs index 563d79210..b5fe29eeb 100644 --- a/sig/mindee/http/endpoint.rbs +++ b/sig/mindee/http/endpoint.rbs @@ -9,18 +9,12 @@ module Mindee TIMEOUT_DEFAULT: Integer USER_AGENT: String class Endpoint - attr_reader api_key: String | nil - + attr_reader api_key: String attr_reader base_url: String attr_reader request_timeout: Integer - attr_reader url_root: String def logger: () -> Logger - def api_key: -> String? - def request_timeout: -> Integer - def url_root: -> String - def base_url: -> String def initialize: (String, String, String | nil, ?api_key: String) -> String def predict: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Net::HTTPResponse, Hash[Symbol, untyped]] def predict_async: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Net::HTTPResponse, Hash[Symbol, untyped]] diff --git a/sig/mindee/http/http_error_handler.rbs b/sig/mindee/http/http_error_handler.rbs index c46c742ef..88f739460 100644 --- a/sig/mindee/http/http_error_handler.rbs +++ b/sig/mindee/http/http_error_handler.rbs @@ -2,9 +2,13 @@ module Mindee module HTTP module ErrorHandler - def extract_error: (Hash[String | Symbol, untyped]) -> void - def create_error_obj: (Hash[String | Symbol, untyped]) -> (Hash[String, String] | Hash[String | Symbol, untyped])? - def handle_error: (String, Hash[String | Symbol, untyped]) -> void + def extract_error: (Hash[String | Symbol, untyped]) -> Hash[String | Symbol, untyped]? + def create_error_obj: (Hash[String | Symbol, untyped]) -> Hash[String | Symbol, untyped] + def self.generate_v2_error: (Hash[String, Integer | String]) -> Errors::MindeeHTTPErrorV2 + def generate_v2_error: (Hash[String, String | Integer]) -> Errors::MindeeHTTPErrorV2 + + def self.handle_error: (String, Net::HTTPResponse) -> Errors::MindeeHTTPError + def handle_error: (String, Net::HTTPResponse) -> Errors::MindeeHTTPError def handle_v2_error: (Hash[String | Symbol, untyped]) -> void end end diff --git a/sig/mindee/http/mindee_api_v2.rbs b/sig/mindee/http/mindee_api_v2.rbs index 972585306..8aa55f036 100644 --- a/sig/mindee/http/mindee_api_v2.rbs +++ b/sig/mindee/http/mindee_api_v2.rbs @@ -4,7 +4,7 @@ module Mindee class MindeeApiV2 attr_reader settings: ApiSettingsV2 - def initialize: (String?) -> void + def initialize: (?api_key: String?) -> void def req_post_inference_enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Input::InferenceParameters) -> Parsing::V2::JobResponse def req_get_inference: (String) -> Parsing::V2::InferenceResponse def req_get_job: (String) -> Parsing::V2::JobResponse diff --git a/sig/mindee/image/extracted_image.rbs b/sig/mindee/image/extracted_image.rbs index 668a001ba..8f7c3d872 100644 --- a/sig/mindee/image/extracted_image.rbs +++ b/sig/mindee/image/extracted_image.rbs @@ -8,7 +8,7 @@ module Mindee def buffer: -> StringIO def internal_file_name: -> String def initialize: (Input::Source::LocalInputSource, Integer, Integer) -> Integer - def write_to_file: (String, ?String?) -> nil + def write_to_file: (String, ?String?) -> void def as_source: -> Input::Source::BytesInputSource end end diff --git a/sig/mindee/image/image_compressor.rbs b/sig/mindee/image/image_compressor.rbs index dd4eda57b..c3b7a5829 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: (singleton(MiniMagick::Image) | MiniMagick::Image | StringIO, ?quality: Integer, ?max_width: Integer?, ?max_height: Integer?) -> StringIO + def self.compress_image: (singleton(MiniMagick::Image) | MiniMagick::Image | StringIO | File, ?quality: Integer | Float | nil, ?max_width: Integer | Float | nil, ?max_height: Integer | Float | nil) -> StringIO end end end diff --git a/sig/mindee/image/image_extractor.rbs b/sig/mindee/image/image_extractor.rbs index c2aa53d00..a92fe154c 100644 --- a/sig/mindee/image/image_extractor.rbs +++ b/sig/mindee/image/image_extractor.rbs @@ -2,12 +2,12 @@ module Mindee module Image module ImageExtractor - def self.attach_image_as_new_file: (StringIO, ?format: String) -> Origami::PDF + def self.attach_image_as_new_file: (StringIO | File, ?format: String) -> Origami::PDF def self.to_blob: () -> String - def self.extract_multiple_images_from_source: (Input::Source::LocalInputSource, Integer, Array[Array[Geometry::Point] | Array[Geometry::Quadrilateral]]) -> Array[ExtractedImage] - def self.extract_images_from_polygons: (Input::Source::LocalInputSource, StringIO, Integer, Array[Geometry::Point] | Geometry::Quadrilateral) -> Array[ExtractedImage] - def self.create_extracted_image: (StringIO, String, Integer, Integer) -> void - def self.load_input_source_pdf_page_as_stringio: (Input::Source::LocalInputSource, Integer) -> StringIO + def self.extract_multiple_images_from_source: (Input::Source::LocalInputSource, Integer, Array[Array[Geometry::Point] |Geometry::Polygon | Geometry::Quadrilateral]) -> Array[ExtractedImage] + def self.extract_images_from_polygons: (Input::Source::LocalInputSource, StringIO | File, Integer, Array[Array[Geometry::Point] | Geometry::Polygon | Geometry::Quadrilateral]) -> Array[ExtractedImage] + def self.create_extracted_image: (StringIO | File, String, Integer, Integer) -> void + def self.load_input_source_pdf_page_as_stringio: (Input::Source::LocalInputSource, Integer) -> (StringIO | File) end end end diff --git a/sig/mindee/image/image_utils.rbs b/sig/mindee/image/image_utils.rbs index 9abc4a394..955371a07 100644 --- a/sig/mindee/image/image_utils.rbs +++ b/sig/mindee/image/image_utils.rbs @@ -8,11 +8,11 @@ module Mindee 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.pdf_to_magick_image: (StringIO | File, Integer) -> 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.read_page_content: (StringIO | File) -> (singleton(MiniMagick::Image) | MiniMagick::Image) + def self.crop_image: (singleton(MiniMagick::Image) | MiniMagick::Image, Geometry::MinMax, Geometry::MinMax) -> (singleton(MiniMagick::Image) | MiniMagick::Image) + def self.write_image_to_buffer: (singleton(MiniMagick::Image) | MiniMagick::Image, StringIO) -> void def self.determine_file_extension: (Input::Source::LocalInputSource) -> String? end end diff --git a/sig/mindee/input/local_response.rbs b/sig/mindee/input/local_response.rbs index a5377f712..622c229dd 100644 --- a/sig/mindee/input/local_response.rbs +++ b/sig/mindee/input/local_response.rbs @@ -8,7 +8,7 @@ module Mindee def self.process_secret_key: (String) -> String def get_hmac_signature: (String) -> String def valid_hmac_signature?: (String, String) -> bool - def deserialize_response: -> (Parsing::V2::JobResponse | Parsing::V2::InferenceResponse) + def deserialize_response: (singleton(Parsing::V2::JobResponse) | singleton(Parsing::V2::InferenceResponse))-> (Parsing::V2::JobResponse | Parsing::V2::InferenceResponse) end end end diff --git a/sig/mindee/input/sources/local_input_source.rbs b/sig/mindee/input/sources/local_input_source.rbs index 04b04596e..d70a2c9c5 100644 --- a/sig/mindee/input/sources/local_input_source.rbs +++ b/sig/mindee/input/sources/local_input_source.rbs @@ -7,21 +7,17 @@ module Mindee attr_reader file_mimetype: String attr_reader filename: String attr_reader io_stream: StringIO|File - - def filename: -> String - def file_mimetype: -> String - def io_stream: -> StringIO def initialize: (StringIO | File, String, ?repair_pdf: bool) -> void def logger: () -> Logger - def rescue_broken_pdf: (StringIO|File) -> StringIO + def rescue_broken_pdf: (StringIO|File) -> (StringIO | File) def pdf?: -> bool def apply_page_options: (PageOptions) -> StringIO? def process_pdf: (PageOptions) -> StringIO? def read_contents: (?close: bool) -> [String?, Hash[:filename, String]] def count_pages: -> Integer - def write_to_file: (String) -> void + 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/logging/logger.rbs b/sig/mindee/logging/logger.rbs index 7ef7e1129..0eaf4aaa4 100644 --- a/sig/mindee/logging/logger.rbs +++ b/sig/mindee/logging/logger.rbs @@ -3,6 +3,8 @@ module Mindee @logger: Logger def self.logger: -> Logger + def debug: (?untyped?) -> void + def info: (?untyped?) -> void def self.logger=: (Logger) -> Logger end diff --git a/sig/mindee/page_options.rbs b/sig/mindee/page_options.rbs index 759efe8fa..c212b474d 100644 --- a/sig/mindee/page_options.rbs +++ b/sig/mindee/page_options.rbs @@ -1,9 +1,11 @@ # lib/mindee/page_options.rb -class PageOptions - attr_accessor page_indexes: Array[Integer] - attr_accessor operation: :KEEP_ONLY | :REMOVE - attr_accessor on_min_pages: Integer? +module Mindee + 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 \ No newline at end of file + def initialize: (params: Hash[Symbol | String, untyped]) -> void + end +end diff --git a/sig/mindee/parsing/common/extras/cropper_extra.rbs b/sig/mindee/parsing/common/extras/cropper_extra.rbs index 884502efb..958c5201d 100644 --- a/sig/mindee/parsing/common/extras/cropper_extra.rbs +++ b/sig/mindee/parsing/common/extras/cropper_extra.rbs @@ -6,7 +6,7 @@ module Mindee class CropperExtra attr_reader croppings: Array[Standard::PositionField] - def initialize: (Hash[String | Symbol, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], ?Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/parsing/common/extras/extras.rbs b/sig/mindee/parsing/common/extras/extras.rbs index 9f9a02e32..9c549a234 100644 --- a/sig/mindee/parsing/common/extras/extras.rbs +++ b/sig/mindee/parsing/common/extras/extras.rbs @@ -5,7 +5,7 @@ module Mindee module Extras class Extras attr_reader cropper: CropperExtra? - attr_reader full_text_ocr: FullTextOCRExtra? + attr_reader full_text_ocr: FullTextOCRExtra attr_reader rag: RAGExtra? def initialize: (Hash[String | Symbol, untyped]) -> void diff --git a/sig/mindee/parsing/common/extras/full_text_ocr_extra.rbs b/sig/mindee/parsing/common/extras/full_text_ocr_extra.rbs index 72f7f4936..a7eb65dff 100644 --- a/sig/mindee/parsing/common/extras/full_text_ocr_extra.rbs +++ b/sig/mindee/parsing/common/extras/full_text_ocr_extra.rbs @@ -6,8 +6,9 @@ module Mindee class FullTextOCRExtra def contents: -> String? def language: -> String? - def initialize: (untyped) -> nil + def initialize: (Hash[String | Symbol, untyped]) -> nil def to_s: -> String + def <<: (?untyped?) -> untyped end end end diff --git a/sig/mindee/parsing/common/inference.rbs b/sig/mindee/parsing/common/inference.rbs index 749e92619..a1a02e0cc 100644 --- a/sig/mindee/parsing/common/inference.rbs +++ b/sig/mindee/parsing/common/inference.rbs @@ -3,15 +3,20 @@ module Mindee module Parsing module Common class Inference + def self.endpoint_name: () -> String? + def self.endpoint_version: () -> String? + def self.has_async: () -> bool + def self.has_sync: () -> bool + attr_reader endpoint_name: String attr_reader endpoint_version: String attr_reader extras: Extras::Extras attr_reader has_async: bool attr_reader has_sync: bool attr_reader is_rotation_applied: bool - attr_reader pages: Integer + attr_reader pages: Array[Page] attr_reader prediction: Prediction - attr_reader product: Mindee::Product + attr_reader product: Product def initialize: (Hash[String | Symbol, untyped]) -> void def to_s: -> String diff --git a/sig/mindee/parsing/common/ocr/ocr.rbs b/sig/mindee/parsing/common/ocr/ocr.rbs index 1d638d627..e902ab574 100644 --- a/sig/mindee/parsing/common/ocr/ocr.rbs +++ b/sig/mindee/parsing/common/ocr/ocr.rbs @@ -24,7 +24,7 @@ module Mindee def initialize: (Hash[String | Symbol, untyped]) -> void def all_lines: -> Array[OCRLine] def to_s: -> String - def parse_one: (Array[OCRWord], OCRWord, Array[Integer], Array[OCRLine]) -> Array[OCRLine]? + def parse_one: (Array[OCRWord], OCRWord?, Array[Integer], Array[OCRLine]) -> Array[OCRLine]? def to_lines: -> Array[OCRLine] def words_on_same_line?: (OCRWord, OCRWord) -> bool end diff --git a/sig/mindee/parsing/standard/date_field.rbs b/sig/mindee/parsing/standard/date_field.rbs index 52053f2e8..a10222acd 100644 --- a/sig/mindee/parsing/standard/date_field.rbs +++ b/sig/mindee/parsing/standard/date_field.rbs @@ -7,7 +7,7 @@ module Mindee def value: -> String? def raw: -> String? def is_computed: -> bool - def initialize: (Hash[String | Symbol, untyped], Integer?, ?reconstructed: bool) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void end end end diff --git a/sig/mindee/parsing/standard/tax_field.rbs b/sig/mindee/parsing/standard/tax_field.rbs index 6b07d7d65..4f8faf2d2 100644 --- a/sig/mindee/parsing/standard/tax_field.rbs +++ b/sig/mindee/parsing/standard/tax_field.rbs @@ -15,7 +15,7 @@ module Mindee def to_table_line: -> String end class Taxes < Array[TaxField] - def initialize: (Hash[String | Symbol, untyped], Integer?) -> void + def initialize: (Array[untyped], Integer?) -> void def line_separator: (String) -> String def to_s: -> String end diff --git a/sig/mindee/parsing/universal/universal_list_field.rbs b/sig/mindee/parsing/universal/universal_list_field.rbs index 3a8cfa6f3..254794b29 100644 --- a/sig/mindee/parsing/universal/universal_list_field.rbs +++ b/sig/mindee/parsing/universal/universal_list_field.rbs @@ -6,7 +6,7 @@ module Mindee attr_reader page_id: Integer attr_reader values: Array[UniversalObjectField | Standard::StringField] - def initialize: (Array[Hash[Symbol | String, untyped]], Integer?) -> void + def initialize: (Array[Hash[Symbol | String, untyped]], ?Integer?) -> void def contents_list: -> Array[String] def contents_string: (?String) -> String def to_s: -> String diff --git a/sig/mindee/parsing/universal/universal_object_field.rbs b/sig/mindee/parsing/universal/universal_object_field.rbs index bddb869cd..3decc1136 100644 --- a/sig/mindee/parsing/universal/universal_object_field.rbs +++ b/sig/mindee/parsing/universal/universal_object_field.rbs @@ -3,14 +3,21 @@ module Mindee module Parsing module Universal class UniversalObjectField - attr_reader all_values: Hash[String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil] + attr_reader all_values: Hash[String | Symbol, String | Standard::PositionField | nil] attr_reader confidence: Float attr_reader page_id: Integer attr_reader raw_value: String def initialize: (Hash[Symbol | String, untyped], ?Integer?) -> void def str_level: (?Integer) -> String - def method_missing: (Symbol, *Array[untyped]) -> (Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil) + def method_missing: (Symbol, *untyped, untyped) + -> (String + | Integer + | Float + | bool + | Standard::PositionField + | Hash[String | Symbol, untyped] + | nil) def respond_to_missing?: (Symbol, ?bool) -> bool def to_s: -> String def handle_position_field: (String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil, Integer?) -> void diff --git a/sig/mindee/parsing/v2/field/field_confidence.rbs b/sig/mindee/parsing/v2/field/field_confidence.rbs index dd43361c9..16ee1eef8 100644 --- a/sig/mindee/parsing/v2/field/field_confidence.rbs +++ b/sig/mindee/parsing/v2/field/field_confidence.rbs @@ -10,7 +10,7 @@ module Mindee MEDIUM: String LOW: String VALID_VALUES: Array[String] - def initialize: (Hash[String | Symbol, untyped]) -> void + def initialize: (String) -> void def self.from_string: (String) -> FieldConfidence def certain?: -> bool def high?: -> bool diff --git a/sig/mindee/parsing/v2/field/field_location.rbs b/sig/mindee/parsing/v2/field/field_location.rbs index f778cf921..d72e31cc6 100644 --- a/sig/mindee/parsing/v2/field/field_location.rbs +++ b/sig/mindee/parsing/v2/field/field_location.rbs @@ -7,7 +7,7 @@ module Mindee attr_reader page: Integer? attr_reader polygon: Geometry::Polygon? - def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void def to_s: -> String end end diff --git a/sig/mindee/parsing/v2/field/inference_fields.rbs b/sig/mindee/parsing/v2/field/inference_fields.rbs index f5914e02d..ec936eda0 100644 --- a/sig/mindee/parsing/v2/field/inference_fields.rbs +++ b/sig/mindee/parsing/v2/field/inference_fields.rbs @@ -6,11 +6,12 @@ module Mindee class InferenceFields < Hash[String, ListField | ObjectField | SimpleField | nil] attr_reader indent_level: Integer + def logger: () -> Logger def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void def get: (String) -> (ListField | ObjectField | SimpleField | nil) def method_missing: (Symbol, *untyped) -> (ListField | ObjectField | SimpleField | nil) def respond_to_missing?: (Symbol, ?bool) -> bool - def to_s: (Integer?) -> String + def to_s: (?Integer) -> String end end end diff --git a/sig/mindee/parsing/v2/field/list_field.rbs b/sig/mindee/parsing/v2/field/list_field.rbs index c867ca2c5..2383d1299 100644 --- a/sig/mindee/parsing/v2/field/list_field.rbs +++ b/sig/mindee/parsing/v2/field/list_field.rbs @@ -4,15 +4,17 @@ module Mindee module V2 module Field class ListField < BaseField - include Enumerable[untyped] - attr_reader items: Array[ListField | ObjectField | SimpleField | nil] + include Enumerable[BaseField] + + attr_reader items: Array[BaseField] def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void def to_s: -> String def empty?: -> bool def size: -> Integer def length: -> Integer - def each: { (untyped) -> Object } -> (Array[ListField | ObjectField | SimpleField | nil] | Enumerator[ListField | ObjectField | SimpleField | nil, Array[ListField | ObjectField | SimpleField | nil]]) - def []: (Integer) -> (ListField | ObjectField | SimpleField | nil) + # NOTE: Steep is incapable of handling typing of `each` when multiple types are used. + def each: () { (untyped) -> untyped } -> untyped + def []: (Integer) -> (BaseField) end end end diff --git a/sig/mindee/parsing/v2/field/simple_field.rbs b/sig/mindee/parsing/v2/field/simple_field.rbs index 282763389..facf0b121 100644 --- a/sig/mindee/parsing/v2/field/simple_field.rbs +++ b/sig/mindee/parsing/v2/field/simple_field.rbs @@ -8,7 +8,7 @@ module Mindee def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void def to_s: -> String - def format_numeric_value: (String | Integer | Float | bool | nil) -> String + def format_numeric_value: (Integer | Float) -> String end end end diff --git a/sig/mindee/pdf/pdf_compressor.rbs b/sig/mindee/pdf/pdf_compressor.rbs index 8ece7fff4..11fe4e349 100644 --- a/sig/mindee/pdf/pdf_compressor.rbs +++ b/sig/mindee/pdf/pdf_compressor.rbs @@ -5,10 +5,10 @@ module Mindee module PDF module PDFCompressor def self.logger: () -> Logger - def self.compress_pdf: (StringIO, ?quality: Integer, ?force_source_text_compression: bool, ?disable_source_text: bool) -> StringIO + def self.compress_pdf: (StringIO | File, ?quality: Integer, ?force_source_text_compression: bool, ?disable_source_text: bool) -> (StringIO | File) 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.create_output_pdf: (Array[Origami::Page], bool, StringIO | File) -> Origami::PDF + def self.inject_text: (StringIO | File, Array[Origami::Page]) -> nil def self.process_pdf_page: (StringIO, Integer, Integer, Array[Integer]?) -> Origami::Page end end diff --git a/sig/mindee/pdf/pdf_extractor.rbs b/sig/mindee/pdf/pdf_extractor.rbs index d8b25fdc3..38a5a1fb4 100644 --- a/sig/mindee/pdf/pdf_extractor.rbs +++ b/sig/mindee/pdf/pdf_extractor.rbs @@ -10,9 +10,7 @@ module Mindee def page_count: -> Integer def cut_pages: (Array[Integer]) -> StringIO def extract_sub_documents: (Array[Array[Integer]]) -> Array[ExtractedPDF] - def extract_invoices: (Array[Array[Integer]], ?strict: bool) -> Array[ExtractedPDF] - def source_pdf: -> StringIO - def filename: -> String + def extract_invoices: (Array[Product::InvoiceSplitter::InvoiceSplitterV1InvoicePageGroup] | Array [Array[Integer]], ?strict: bool) -> Array[ExtractedPDF] end end end diff --git a/sig/mindee/pdf/pdf_processor.rbs b/sig/mindee/pdf/pdf_processor.rbs index 3c0a5a33b..38085f3ab 100644 --- a/sig/mindee/pdf/pdf_processor.rbs +++ b/sig/mindee/pdf/pdf_processor.rbs @@ -2,10 +2,10 @@ module Mindee module PDF module PDFProcessor - def self.parse: (StringIO, PageOptions) -> StringIO + def self.parse: (StringIO | File, PageOptions) -> StringIO def self.indexes_from_keep: (Array[Integer], Array[Integer]) -> (Array[Integer]) def self.indexes_from_remove: (Array[Integer], Array[Integer]) -> (Array[Integer]) - def self.open_pdf: (StringIO) -> Origami::PDF + def self.open_pdf: (StringIO | File) -> Origami::PDF def self.get_page: (Origami::PDF, Integer) -> StringIO end end diff --git a/sig/mindee/pdf/pdf_tools.rbs b/sig/mindee/pdf/pdf_tools.rbs index 5ecc723c6..cd0137a60 100644 --- a/sig/mindee/pdf/pdf_tools.rbs +++ b/sig/mindee/pdf/pdf_tools.rbs @@ -4,16 +4,23 @@ module Mindee module PDFTools BitsPerComponent: Integer ColorSpace: Symbol + Contents: Origami::Stream Height: Integer | Float Width: Integer | Float - def to_io_stream: (?Hash[String | Symbol, untyped]) -> StringIO - def self.stream_has_text?: (StringIO) -> bool - def self.source_text?: (StringIO) -> bool - def self.create_xobject: (singleton(MiniMagick::Image) | MiniMagick::Image | StringIO) -> Origami::Graphics::ImageXObject - def self.set_xobject_properties: (Origami::Graphics::ImageXObject, Hash[String | Symbol, untyped]) -> void - def self.determine_filter: (Hash[String | Symbol, untyped]) -> (:DCTDecode | :FlateDecode | :LZWDecode) - def self.determine_colorspace: (Hash[String | Symbol, untyped]) -> (:DeviceCMYK | :DeviceGray | :DeviceRGB) + def to_io_stream: (?Hash[Symbol, untyped]) -> StringIO + def intents_as_pdfa1: () -> void + def delinearize!: () -> void + def linearized?: () -> bool + def compile: (Hash[String | Symbol, untyped]) -> StringIO + def output: (Hash[String | Symbol, untyped]) -> String + def load_all_objects: () -> void + def self.stream_has_text?: (Origami::Stream) -> bool + def self.source_text?: (StringIO | File) -> bool + def self.create_xobject: (singleton(MiniMagick::Image) | MiniMagick::Image) -> Origami::Graphics::ImageXObject + def self.set_xobject_properties: (Origami::Graphics::ImageXObject, MiniMagick::Image | singleton(MiniMagick::Image)) -> void + def self.determine_filter: (singleton(MiniMagick::Image) | MiniMagick::Image) -> (:DCTDecode | :FlateDecode | :LZWDecode) + def self.determine_colorspace: (singleton(MiniMagick::Image) | MiniMagick::Image) -> (:DeviceCMYK | :DeviceGray | :DeviceRGB) def self.add_content_to_page: (Origami::Page, String, Integer, Integer) -> void def self.set_page_dimensions: (Origami::Page, Integer | Float, Integer | Float) -> void def self.process_image_xobject: (singleton(MiniMagick::Image) | MiniMagick::Image | StringIO, Integer, Integer | Float, Integer | Float) -> Origami::Graphics::ImageXObject From dc3260270fde2b5c59040c96a5994e9319ac962e Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Fri, 8 Aug 2025 11:13:47 +0200 Subject: [PATCH 09/19] fix rubocop issues --- lib/mindee/parsing/standard/feature_field.rb | 2 +- lib/mindee/pdf/pdf_processor.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mindee/parsing/standard/feature_field.rb b/lib/mindee/parsing/standard/feature_field.rb index 4280104ba..ecd658fcd 100644 --- a/lib/mindee/parsing/standard/feature_field.rb +++ b/lib/mindee/parsing/standard/feature_field.rb @@ -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.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]}..." + 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/pdf/pdf_processor.rb b/lib/mindee/pdf/pdf_processor.rb index 9552e8110..4f37116f4 100644 --- a/lib/mindee/pdf/pdf_processor.rb +++ b/lib/mindee/pdf/pdf_processor.rb @@ -17,7 +17,7 @@ def self.parse(io_stream, options) pages_count = current_pdf.pages.size return current_pdf.to_io_stream if options.on_min_pages.to_i > pages_count - all_pages = (0..pages_count - 1).to_a + all_pages = (0..(pages_count - 1)).to_a if options.operation == :KEEP_ONLY pages_to_remove = indexes_from_keep(options.page_indexes, all_pages) From f889e2b575cec452a36540621e505ad86d036d18 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Fri, 8 Aug 2025 11:22:52 +0200 Subject: [PATCH 10/19] add missing doc + fix rubocop again --- lib/mindee/image/image_extractor.rb | 16 ++++++++-------- lib/mindee/parsing/common/api_response.rb | 4 ++++ lib/mindee/parsing/common/extras/rag_extra.rb | 2 ++ lib/mindee/parsing/v2/field/base_field.rb | 1 + lib/mindee/parsing/v2/field/field_confidence.rb | 5 +++++ lib/mindee/parsing/v2/field/list_field.rb | 7 ++++++- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/mindee/image/image_extractor.rb b/lib/mindee/image/image_extractor.rb index bee28cbd1..bb0599800 100644 --- a/lib/mindee/image/image_extractor.rb +++ b/lib/mindee/image/image_extractor.rb @@ -30,11 +30,11 @@ def self.attach_image_as_new_file(input_buffer, format: 'jpg') # Extracts multiple images from a given local input source. # - # @param [Mindee::Input::Source::LocalInputSource] input_source + # @param [Input::Source::LocalInputSource] input_source # @param [Integer] page_id ID of the Page to extract from. - # @param [Array>, Array] List of coordinates + # @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_stringio(input_source, page_id) new_stream.seek(0) @@ -44,11 +44,11 @@ def self.extract_multiple_images_from_source(input_source, page_id, polygons) # Extracts images from their positions on a file (as polygons). # - # @param [Mindee::Input::Source::LocalInputSource] input_source Local input source. + # @param [Input::Source::LocalInputSource] input_source Local input source. # @param [StringIO] pdf_stream Buffer of the PDF. # @param [Integer] page_id Page ID. - # @param [Array] polygons - # @return [Array] Extracted Images. + # @param [Array] polygons + # @return [Array] Extracted Images. def self.extract_images_from_polygons(input_source, pdf_stream, page_id, polygons) extracted_elements = [] @@ -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.to_s, file_name), + Input::Source::BytesInputSource.new(buffer.read.to_s, file_name), page_id, element_id ) @@ -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) + PDF::PDFProcessor.get_page(Origami::PDF.read(input_file.io_stream), page_id) else input_file.io_stream end diff --git a/lib/mindee/parsing/common/api_response.rb b/lib/mindee/parsing/common/api_response.rb index 056d391b3..195c95bad 100644 --- a/lib/mindee/parsing/common/api_response.rb +++ b/lib/mindee/parsing/common/api_response.rb @@ -8,9 +8,13 @@ module Parsing module Common # Potential values for queue in asynchronous calls. module JobStatus + # Job is still waiting to be processed. WAITING = :waiting + # Job is still processing. PROCESSING = :processing + # Job is completed. COMPLETED = :completed + # Job failed. FAILURE = :failed end diff --git a/lib/mindee/parsing/common/extras/rag_extra.rb b/lib/mindee/parsing/common/extras/rag_extra.rb index 08717cb30..55c016b36 100644 --- a/lib/mindee/parsing/common/extras/rag_extra.rb +++ b/lib/mindee/parsing/common/extras/rag_extra.rb @@ -14,6 +14,8 @@ def initialize(raw_prediction) @matching_document_id = raw_prediction['matching_document_id'] if raw_prediction['matching_document_id'] end + # String representation. + # @return [String] def to_s @matching_document_id || '' end diff --git a/lib/mindee/parsing/v2/field/base_field.rb b/lib/mindee/parsing/v2/field/base_field.rb index 73b50b154..6a5966a27 100644 --- a/lib/mindee/parsing/v2/field/base_field.rb +++ b/lib/mindee/parsing/v2/field/base_field.rb @@ -3,6 +3,7 @@ module Mindee module Parsing module V2 + # Field submodule for V2. module Field # Base class for V2 fields. class BaseField diff --git a/lib/mindee/parsing/v2/field/field_confidence.rb b/lib/mindee/parsing/v2/field/field_confidence.rb index 3a13c68b2..d11fa2c28 100644 --- a/lib/mindee/parsing/v2/field/field_confidence.rb +++ b/lib/mindee/parsing/v2/field/field_confidence.rb @@ -9,11 +9,16 @@ class FieldConfidence # @return [String] The confidence level value. attr_reader :value + # Absolute certainty about the field's extraction. CERTAIN = 'Certain' + # High certainty about the field's extraction. HIGH = 'High' + # Medium certainty about the field's extraction. MEDIUM = 'Medium' + # Low certainty about the field's extraction. LOW = 'Low' + # List of valid values, as frozen strings. VALID_VALUES = [CERTAIN, HIGH, MEDIUM, LOW].freeze # @param value [String] The confidence level value. diff --git a/lib/mindee/parsing/v2/field/list_field.rb b/lib/mindee/parsing/v2/field/list_field.rb index e284950aa..aec4a8612 100644 --- a/lib/mindee/parsing/v2/field/list_field.rb +++ b/lib/mindee/parsing/v2/field/list_field.rb @@ -6,7 +6,10 @@ module Mindee module Parsing module V2 module Field - # A field containing a list of other fields. + # Represents a field that contains a list of items. + # The list can include various field types such as ListField, ObjectField, + # or SimpleField. Implements the Enumerable module for traversal and + # manipulation. class ListField < BaseField include Enumerable # @return [Array] Items contained in the list. @@ -73,6 +76,8 @@ def [](index) @items[index] end + # Iterator for Enumerator inheritance. + # Untyped due to incomplete support in steep. def each(&block) return to_enum(:each) unless block_given? From 521eca8f7aabbe833c47e89c31d6e84176af20aa Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Mon, 11 Aug 2025 15:24:01 +0200 Subject: [PATCH 11/19] add v2 unit tests + fix more typing issues --- .github/workflows/_test-code-samples.yml | 2 +- .github/workflows/_test-integrations.yml | 3 + lib/mindee/errors.rb | 1 + lib/mindee/http/http_error_handler.rb | 6 +- lib/mindee/http/mindee_api_v2.rb | 7 +- lib/mindee/http/response_validation.rb | 8 +- lib/mindee/parsing/common/api_response.rb | 4 - .../parsing/v2/field/inference_fields.rb | 2 +- lib/mindee/parsing/v2/field/simple_field.rb | 9 +- lib/mindee/parsing/v2/inference_file.rb | 2 +- sig/custom/net_http.rbs | 4 +- sig/mindee/http/endpoint.rbs | 6 +- sig/mindee/http/http_error_handler.rbs | 2 +- spec/client_v2_spec.rb | 89 ++++++ spec/parsing/v2/inference_spec.rb | 263 ++++++++++++++++++ 15 files changed, 380 insertions(+), 28 deletions(-) create mode 100644 spec/client_v2_spec.rb create mode 100644 spec/parsing/v2/inference_spec.rb diff --git a/.github/workflows/_test-code-samples.yml b/.github/workflows/_test-code-samples.yml index bbd5e8ce5..ca03e5b8a 100644 --- a/.github/workflows/_test-code-samples.yml +++ b/.github/workflows/_test-code-samples.yml @@ -32,4 +32,4 @@ jobs: env: MINDEE_LOG_LEVEL: DEBUG run: | - ./spec/test_code_samples.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }} ${{ secrets.MINDEE_API_KEY_SE_TESTS }} + ./spec/test_code_samples.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }} ${{ secrets.MINDEE_API_KEY_SE_TESTS }} ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }} ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }} diff --git a/.github/workflows/_test-integrations.yml b/.github/workflows/_test-integrations.yml index f6df327c0..e046b7578 100644 --- a/.github/workflows/_test-integrations.yml +++ b/.github/workflows/_test-integrations.yml @@ -56,6 +56,9 @@ jobs: env: MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }} WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }} + MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }} + MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }} + MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }} MINDEE_LOG_LEVEL: DEBUG run: | bundle exec rake integration diff --git a/lib/mindee/errors.rb b/lib/mindee/errors.rb index 59117d6c5..3c403704f 100644 --- a/lib/mindee/errors.rb +++ b/lib/mindee/errors.rb @@ -2,4 +2,5 @@ require_relative 'errors/mindee_error' require_relative 'errors/mindee_http_error' +require_relative 'errors/mindee_http_error_v2' require_relative 'errors/mindee_input_error' diff --git a/lib/mindee/http/http_error_handler.rb b/lib/mindee/http/http_error_handler.rb index 90d2b718b..8785aabef 100644 --- a/lib/mindee/http/http_error_handler.rb +++ b/lib/mindee/http/http_error_handler.rb @@ -92,9 +92,9 @@ def handle_error(url, response) # Creates an appropriate HTTP error exception for a V2 API response, based on retrieved http error code. # @param hashed_response [Hash] dictionary response retrieved by the server def generate_v2_error(hashed_response) - code = hashed_response['code'].to_i - if hashed_response.key?('status') - Errors::MindeeHTTPErrorV2.new(hashed_response) + code = hashed_response[:code].to_i + if hashed_response.key?(:status) + Errors::MindeeHTTPErrorV2.new(hashed_response.transform_keys(&:to_s)) elsif code < 200 || code > 399 Errors::MindeeHTTPErrorV2.new({ 'status' => code, 'detail' => 'No details available.' }) else diff --git a/lib/mindee/http/mindee_api_v2.rb b/lib/mindee/http/mindee_api_v2.rb index ec2f4f41e..07af28478 100644 --- a/lib/mindee/http/mindee_api_v2.rb +++ b/lib/mindee/http/mindee_api_v2.rb @@ -69,13 +69,12 @@ def process_response(response) end response_body = if response.nil? || !response.respond_to?(:body) - { 'status' => -1, - 'detail' => 'Empty server response.' } + '{ "status": -1, + "detail": "Empty server response." }' else response.body end - error = ErrorHandler.generate_v2_error(response_body.to_hash) # @type error: Errors::MindeeHTTPErrorV2 - raise error + raise ErrorHandler.generate_v2_error(JSON.parse(response_body).transform_keys(&:to_sym)) end # Polls a queue for either a result or a job. diff --git a/lib/mindee/http/response_validation.rb b/lib/mindee/http/response_validation.rb index 9ed086607..05d883208 100644 --- a/lib/mindee/http/response_validation.rb +++ b/lib/mindee/http/response_validation.rb @@ -31,7 +31,11 @@ def self.valid_v2_response?(response) return false if hashed_response.dig('job', 'status').to_s == 'Failed' - return false if hashed_response.dig('job', 'error') && !hashed_response.dig('job', 'error').empty? + return false if hashed_response.dig('job', + 'error') && !(hashed_response.dig('job', + 'error').empty? || hashed_response.dig( + 'job', 'error' + ).nil?) true end @@ -67,7 +71,7 @@ def self.clean_request!(response) end return if !hashed_response.dig('job', 'error').empty? && - (hashed_response.dig('job', 'status') != Mindee::Parsing::Common::JobStatus::FAILURE.to_s) + (hashed_response.dig('job', 'status').downcase != Mindee::Parsing::Common::JobStatus::FAILURE.to_s) response.instance_variable_set(:@code, '500') end diff --git a/lib/mindee/parsing/common/api_response.rb b/lib/mindee/parsing/common/api_response.rb index 195c95bad..056d391b3 100644 --- a/lib/mindee/parsing/common/api_response.rb +++ b/lib/mindee/parsing/common/api_response.rb @@ -8,13 +8,9 @@ module Parsing module Common # Potential values for queue in asynchronous calls. module JobStatus - # Job is still waiting to be processed. WAITING = :waiting - # Job is still processing. PROCESSING = :processing - # Job is completed. COMPLETED = :completed - # Job failed. FAILURE = :failed end diff --git a/lib/mindee/parsing/v2/field/inference_fields.rb b/lib/mindee/parsing/v2/field/inference_fields.rb index a9bca5904..19debf4de 100644 --- a/lib/mindee/parsing/v2/field/inference_fields.rb +++ b/lib/mindee/parsing/v2/field/inference_fields.rb @@ -76,7 +76,7 @@ def to_s(indent = 0) # Check if SimpleField has a non-empty value simple_f = field_value # @type var simple_f: SimpleField if defined?(simple_f.value) && simple_f.value && !simple_f.value.to_s.empty? - line += " #{simple_f.value}" + line += " #{simple_f}" end else logger.debug("Unknown value was passed to the field creator: #{field_key} : #{field_value}") diff --git a/lib/mindee/parsing/v2/field/simple_field.rb b/lib/mindee/parsing/v2/field/simple_field.rb index 1bb676765..d3d3b0457 100644 --- a/lib/mindee/parsing/v2/field/simple_field.rb +++ b/lib/mindee/parsing/v2/field/simple_field.rb @@ -23,12 +23,9 @@ def initialize(server_response, indent_level = 0) def to_s return '' if @value.nil? - case @value - when TrueClass - 'True' - when FalseClass - 'False' - when Integer, Float + if @value.is_a?(TrueClass) || @value.is_a?(FalseClass) + @value ? 'True' : 'False' + elsif @value.is_a?(Integer) || @value.is_a?(Float) # NOTE: explicitly typing because steep is very, very dumb num = @value # @type var num: Integer | Float format_numeric_value(num) diff --git a/lib/mindee/parsing/v2/inference_file.rb b/lib/mindee/parsing/v2/inference_file.rb index d7f27aefd..7dc7f29f4 100644 --- a/lib/mindee/parsing/v2/inference_file.rb +++ b/lib/mindee/parsing/v2/inference_file.rb @@ -30,7 +30,7 @@ def to_s ":Name: #{@name}\n" \ ":Alias:#{" #{@file_alias}" if @file_alias}\n" \ ":Page Count: #{@page_count}\n" \ - ":MIME Type: #{@mime_type}" + ":MIME Type: #{@mime_type}\n" end end end diff --git a/sig/custom/net_http.rbs b/sig/custom/net_http.rbs index a9052ab15..9d24bc515 100644 --- a/sig/custom/net_http.rbs +++ b/sig/custom/net_http.rbs @@ -28,8 +28,8 @@ module Net end class HTTPResponse - def self.body: -> untyped - def body: -> untyped + def self.body: -> String + def body: -> String def []: (untyped) -> untyped def key?: (untyped) -> bool def code: -> String diff --git a/sig/mindee/http/endpoint.rbs b/sig/mindee/http/endpoint.rbs index b5fe29eeb..e4c9021cc 100644 --- a/sig/mindee/http/endpoint.rbs +++ b/sig/mindee/http/endpoint.rbs @@ -16,9 +16,9 @@ module Mindee def logger: () -> Logger def initialize: (String, String, String | nil, ?api_key: String) -> String - def predict: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Net::HTTPResponse, Hash[Symbol, untyped]] - def predict_async: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Net::HTTPResponse, Hash[Symbol, untyped]] - def parse_async: (String) -> [Net::HTTPResponse, Hash[Symbol, untyped]] + def predict: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Hash[Symbol | String, untyped], String] + def predict_async: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Hash[Symbol | String, untyped], String] + def parse_async: (String) -> [Hash[Symbol | String, untyped], String] def predict_req_post: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> Net::HTTPResponse def document_queue_req_post: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> Net::HTTPResponse def document_queue_req_get: (String) -> Net::HTTPResponse diff --git a/sig/mindee/http/http_error_handler.rbs b/sig/mindee/http/http_error_handler.rbs index 88f739460..1ab8b3697 100644 --- a/sig/mindee/http/http_error_handler.rbs +++ b/sig/mindee/http/http_error_handler.rbs @@ -5,7 +5,7 @@ module Mindee def extract_error: (Hash[String | Symbol, untyped]) -> Hash[String | Symbol, untyped]? def create_error_obj: (Hash[String | Symbol, untyped]) -> Hash[String | Symbol, untyped] def self.generate_v2_error: (Hash[String, Integer | String]) -> Errors::MindeeHTTPErrorV2 - def generate_v2_error: (Hash[String, String | Integer]) -> Errors::MindeeHTTPErrorV2 + def generate_v2_error: (Hash[Symbol, String | Integer]) -> Errors::MindeeHTTPErrorV2 def self.handle_error: (String, Net::HTTPResponse) -> Errors::MindeeHTTPError def handle_error: (String, Net::HTTPResponse) -> Errors::MindeeHTTPError diff --git a/spec/client_v2_spec.rb b/spec/client_v2_spec.rb new file mode 100644 index 000000000..65c6209dc --- /dev/null +++ b/spec/client_v2_spec.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require 'json' +require 'mindee' +require_relative 'http/mock_http_response' # <- the original helper + +RSpec.describe Mindee::ClientV2 do + let(:file_types_dir) { File.join(__dir__ || './', 'data', 'file_types') } + let(:v2_data_dir) { File.join(__dir__ || './', 'data', 'v2') } + let(:input_doc) { Mindee::Input::Source::PathInputSource.new(File.join(file_types_dir, 'pdf', 'blank.pdf')) } + let(:base_url) { 'https://dummy-url' } + let(:api_key) { 'dummy-api-key' } + + let(:client) do + ENV['MINDEE_V2_BASE_URL'] = 'https://dummy-url' + Mindee::ClientV2.new(api_key: api_key) + end + let(:api) do + client.instance_variable_get(:@mindee_api) + end + + let(:json400) do + { + status: 400, + detail: 'Unsupported content.', + } + end + + def build_mock_http_response(hash, status_code = 400, status_msg = 'Bad Request') + MockHTTPResponse.new('1.1', status_code.to_s, status_msg, hash) + end + + def stub_next_request_with(method, hash:, status_code: 0) + fake_response = build_mock_http_response(hash, status_code) + allow_any_instance_of(Mindee::HTTP::MindeeApiV2) + .to receive(method) + .and_return(fake_response) + end + + it 'inherits base URL, token & headers from the env / options' do + settings = api.settings + + expect(settings.base_url).to eq(base_url) + expect(settings.api_key).to eq(api_key) + end + + it 'enqueue(path) raises MindeeHTTPErrorV2 on 4xx' do + expect do + stub_next_request_with(:enqueue, hash: JSON.generate(json400)) + client.enqueue_inference(input_doc, model_id: 'dummy-model') + end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| + expect(e.status).to eq(400) + expect(e.detail).to eq('Unsupported content.') + } + end + + it 'enqueue_and_get_inference(path) raises MindeeHTTPErrorV2 on 4xx' do + expect do + stub_next_request_with(:enqueue, hash: JSON.generate(json400)) + client.enqueue_and_get_inference(input_doc, model_id: 'dummy-model') + end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| + expect(e.status).to eq(400) + expect(e.detail).to eq('Unsupported content.') + } + end + + it 'bubbles-up HTTP errors with details' do + error_hash = json400.merge({ status: 413, detail: 'File exceeds size limit' }) + + expect do + stub_next_request_with(:enqueue, hash: JSON.generate(error_hash)) + client.enqueue_inference(input_doc, model_id: 'dummy-model') + end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| + expect(e.status).to eq(413) + expect(e.detail).to include('File exceeds size limit') + } + end + + it 'get_job(job_id) returns a fully-formed JobResponse' do + json_path = File.join(v2_data_dir, 'job', 'ok_processing.json') + parsed = File.read(json_path) + stub_next_request_with(:inference_job_req_get, hash: parsed, status_code: 200) + + resp = client.get_job('123e4567-e89b-12d3-a456-426614174000') + expect(resp).to be_a(Mindee::Parsing::V2::JobResponse) + expect(resp.job.status).to eq('Processing') + end + ENV.delete('MINDEE_V2_BASE_URL') +end diff --git a/spec/parsing/v2/inference_spec.rb b/spec/parsing/v2/inference_spec.rb new file mode 100644 index 000000000..ead03ffdb --- /dev/null +++ b/spec/parsing/v2/inference_spec.rb @@ -0,0 +1,263 @@ +# frozen_string_literal: true + +require 'mindee' + +RSpec.describe 'inference' do + let(:v2_data_dir) { File.join(DATA_DIR, 'v2') } + let(:findoc_path) { File.join(v2_data_dir, 'products', 'financial_document') } + let(:inference_path) { File.join(v2_data_dir, 'inference') } + let(:deep_nested_field_path) { File.join(inference_path, 'deep_nested_fields.json') } + let(:standard_field_path) { File.join(inference_path, 'standard_field_types.json') } + let(:standard_field_rst_path) { File.join(inference_path, 'standard_field_types.rst') } + let(:location_field_path) { File.join(findoc_path, 'complete_with_coordinates.json') } + let(:raw_text_path) { File.join(inference_path, 'raw_texts.json') } + let(:blank_path) { File.join(findoc_path, 'blank.json') } + let(:complete_path) { File.join(findoc_path, 'complete.json') } + + def load_v2_inference(resource_path) + local_response = Mindee::Input::LocalResponse.new(resource_path) + local_response.deserialize_response(Mindee::Parsing::V2::InferenceResponse) + end + + simple_field = Mindee::Parsing::V2::Field::SimpleField + object_field = Mindee::Parsing::V2::Field::ObjectField + list_field = Mindee::Parsing::V2::Field::ListField + field_conf = Mindee::Parsing::V2::Field::FieldConfidence + + describe 'simple' do + it 'loads a blank inference with valid properties' do + response = load_v2_inference(blank_path) + fields = response.inference.result.fields + + expect(fields).not_to be_empty + expect(fields.size).to eq(21) + expect(fields).to have_key('taxes') + expect(fields['taxes']).not_to be_nil + expect(fields['taxes']).to be_a(list_field) + + expect(fields['supplier_address']).not_to be_nil + expect(fields['supplier_address']).to be_a(object_field) + + fields.each_value do |entry| + next if entry.is_a?(simple_field) && entry.value.nil? + + case entry + when simple_field + expect(entry.value).not_to be_nil + when object_field + expect(entry.fields).not_to be_nil + when list_field + expect(entry.items).not_to be_nil + else + raise "Unknown field type: #{entry.class}" + end + end + end + + it 'loads a complete inference with valid properties' do + response = load_v2_inference(complete_path) + inf = response.inference + + expect(inf).not_to be_nil + expect(inf.id).to eq('12345678-1234-1234-1234-123456789abc') + + model = inf.model + expect(model).not_to be_nil + expect(model.id).to eq('12345678-1234-1234-1234-123456789abc') + + file = inf.file + expect(file).not_to be_nil + expect(file.name).to eq('complete.jpg') + expect(file.file_alias).to be_nil + expect(file.page_count).to eq(1) + expect(file.mime_type).to eq('image/jpeg') + + fields = inf.result.fields + expect(fields).not_to be_empty + expect(fields.size).to eq(21) + + date_field = fields['date'] + expect(date_field).to be_a(simple_field) + expect(date_field.value).to eq('2019-11-02') + + expect(fields).to have_key('taxes') + taxes = fields['taxes'] + expect(taxes).to be_a(list_field) + + taxes_list = taxes + expect(taxes_list.items.length).to eq(1) + expect(taxes_list.to_s).to be_a(String) + expect(taxes_list.to_s).to_not be_empty + + first_tax_item = taxes_list.items.first + expect(first_tax_item).to be_a(object_field) + + tax_item_obj = first_tax_item + expect(tax_item_obj.fields.size).to eq(3) + + base_field = tax_item_obj.fields['base'] + expect(base_field).to be_a(simple_field) + expect(base_field.value).to eq(31.5) + + expect(fields).to have_key('supplier_address') + supplier_address = fields['supplier_address'] + expect(supplier_address).to be_a(object_field) + + supplier_obj = supplier_address + country_field = supplier_obj.fields['country'] + expect(country_field).to be_a(simple_field) + expect(country_field.value).to eq('USA') + expect(country_field.to_s).to eq('USA') + expect(supplier_address.to_s).to be_a(String) + expect(supplier_address.to_s).to_not be_empty + + customer_addr = fields['customer_address'] + expect(customer_addr).to be_a(object_field) + city_field = customer_addr.fields['city'] + expect(city_field).to be_a(simple_field) + expect(city_field.value).to eq('New York') + + expect(inf.result.options).to be_nil + end + end + + describe 'nested' do + it 'loads a deep nested object' do + response = load_v2_inference(deep_nested_field_path) + fields = response.inference.result.fields + + expect(fields['field_simple']).to be_a(simple_field) + expect(fields['field_object']).to be_a(object_field) + + field_object = fields['field_object'] + lvl1 = field_object.fields + + expect(lvl1['sub_object_list']).to be_a(list_field) + expect(lvl1['sub_object_object']).to be_a(object_field) + + sub_object_object = lvl1['sub_object_object'] + lvl2 = sub_object_object.fields + + expect(lvl2['sub_object_object_sub_object_list']).to be_a(list_field) + + nested_list = lvl2['sub_object_object_sub_object_list'] + expect(nested_list.items).not_to be_empty + expect(nested_list.items.first).to be_a(object_field) + + first_item_obj = nested_list.items.first + deep_simple = first_item_obj.fields['sub_object_object_sub_object_list_simple'] + + expect(deep_simple).to be_a(simple_field) + expect(deep_simple.value).to eq('value_9') + end + end + + describe 'standard field types' do + it 'recognizes all field variants' do + response = load_v2_inference(standard_field_path) + fields = response.inference.result.fields + + expect(fields['field_simple_string']).to be_a(simple_field) + expect(fields['field_simple_string'].value).to eq('field_simple_string-value') + + expect(fields['field_simple_float']).to be_a(simple_field) + expect(fields['field_simple_float'].value).to eq(1.1) + + expect(fields['field_simple_int']).to be_a(simple_field) + expect(fields['field_simple_int'].value).to eq(12.0) + + expect(fields['field_simple_zero']).to be_a(simple_field) + expect(fields['field_simple_zero'].value).to eq(0) + + expect(fields['field_simple_bool']).to be_a(simple_field) + expect(fields['field_simple_bool'].value).to eq(true) + + expect(fields['field_simple_null']).to be_a(simple_field) + expect(fields['field_simple_null'].value).to be_nil + + expect(fields['field_object']).to be_a(object_field) + expect(fields['field_simple_list']).to be_a(list_field) + expect(fields['field_object_list']).to be_a(list_field) + end + end + + describe 'options' do + it 'exposes raw texts' do + response = load_v2_inference(raw_text_path) + opts = response.inference.result.options + + expect(opts).not_to be_nil + raw_texts = + if opts.respond_to?(:raw_texts) + opts.raw_texts + elsif opts.respond_to?(:get_raw_texts) + opts.get_raw_texts + else + [] + end + + expect(raw_texts).to be_a(Array) + expect(raw_texts.length).to eq(2) + + first = raw_texts.first + page = first.respond_to?(:page) ? first.page : first[:page] + content = first.respond_to?(:content) ? first.content : first[:content] + + expect(page).to eq(0) + expect(content).to eq('This is the raw text of the first page...') + end + end + + describe 'rst display' do + it 'is properly exposed' do + response = load_v2_inference(standard_field_path) + rst_string = File.read(standard_field_rst_path, encoding: 'UTF-8') + + expect(response.inference).not_to be_nil + expect(response.inference.to_s).to eq(rst_string) + end + end + + describe 'field locations and confidence' do + it 'are properly exposed' do + response = load_v2_inference(location_field_path) + + expect(response.inference).not_to be_nil + + date_field = response.inference.result.fields['date'] + expect(date_field).to be_a(simple_field) + expect(date_field.locations).to be_an(Array) + expect(date_field.locations[0]).not_to be_nil + expect(date_field.locations[0].page).to eq(0) + + polygon = date_field.locations[0].polygon + expect(polygon[0].length).to eq(2) + + expect(polygon[0][0]).to be_within(1e-12).of(0.948979073166918) + expect(polygon[0][1]).to be_within(1e-12).of(0.23097924535067715) + + expect(polygon[1][0]).to be_within(1e-12).of(0.85422) + expect(polygon[1][1]).to be_within(1e-12).of(0.230072) + + expect(polygon[2][0]).to be_within(1e-12).of(0.8540899268330819) + expect(polygon[2][1]).to be_within(1e-12).of(0.24365775464932288) + + expect(polygon[3][0]).to be_within(1e-12).of(0.948849) + expect(polygon[3][1]).to be_within(1e-12).of(0.244565) + + # Confidence can be a FieldConfidence instance or a String depending on implementation. + conf_value = + if date_field.confidence.respond_to?(:to_s) + date_field.confidence.to_s + else + date_field.confidence + end + expect(conf_value).to eq('Medium') + + # Optional strict check if equality supports comparing with FieldConfidence constants: + if defined?(field_conf) && field_conf.respond_to?(:from_string) + expect(conf_value).to eq(field_conf.from_string('Medium').to_s) + end + end + end +end From 48a352578a9197b0025f44606b30ce9a1668e649 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Mon, 11 Aug 2025 15:30:56 +0200 Subject: [PATCH 12/19] unify some signatures --- lib/mindee/http/endpoint.rb | 4 ++-- lib/mindee/http/workflow_endpoint.rb | 2 +- .../parsing/universal/universal_object_field.rb | 2 +- lib/mindee/product/universal/universal_prediction.rb | 8 ++++---- lib/mindee/version.rb | 2 +- sig/mindee/client.rbs | 12 ++++++------ sig/mindee/http/endpoint.rbs | 6 +++--- sig/mindee/page_options.rbs | 2 +- sig/mindee/parsing/common/api_response.rbs | 2 +- sig/mindee/parsing/common/job.rbs | 4 ++-- sig/mindee/parsing/common/workflow_response.rbs | 2 +- sig/mindee/parsing/standard/abstract_field.rbs | 2 +- sig/mindee/parsing/standard/address_field.rbs | 2 +- sig/mindee/parsing/standard/base_field.rbs | 2 +- sig/mindee/parsing/standard/boolean_field.rbs | 2 +- sig/mindee/parsing/standard/locale_field.rbs | 2 +- sig/mindee/parsing/standard/position_field.rbs | 4 ++-- sig/mindee/parsing/standard/string_field.rbs | 2 +- .../parsing/universal/universal_list_field.rbs | 2 +- .../parsing/universal/universal_object_field.rbs | 4 ++-- sig/mindee/pdf/pdf_tools.rbs | 2 +- .../product/barcode_reader/barcode_reader_v1.rbs | 2 +- .../barcode_reader/barcode_reader_v1_document.rbs | 2 +- .../barcode_reader/barcode_reader_v1_page.rbs | 4 ++-- .../product/bill_of_lading/bill_of_lading_v1.rbs | 2 +- .../bill_of_lading/bill_of_lading_v1_carrier.rbs | 4 ++-- .../bill_of_lading_v1_carrier_item.rbs | 6 +++--- .../bill_of_lading/bill_of_lading_v1_consignee.rbs | 4 ++-- .../bill_of_lading/bill_of_lading_v1_document.rbs | 2 +- .../bill_of_lading_v1_notify_party.rbs | 4 ++-- .../bill_of_lading/bill_of_lading_v1_page.rbs | 4 ++-- .../bill_of_lading/bill_of_lading_v1_shipper.rbs | 4 ++-- .../product/business_card/business_card_v1.rbs | 2 +- .../business_card/business_card_v1_document.rbs | 2 +- .../product/business_card/business_card_v1_page.rbs | 4 ++-- sig/mindee/product/cropper/cropper_v1.rbs | 2 +- sig/mindee/product/cropper/cropper_v1_document.rbs | 2 +- sig/mindee/product/cropper/cropper_v1_page.rbs | 4 ++-- .../product/delivery_note/delivery_note_v1.rbs | 2 +- .../delivery_note/delivery_note_v1_document.rbs | 2 +- .../product/delivery_note/delivery_note_v1_page.rbs | 4 ++-- .../product/driver_license/driver_license_v1.rbs | 2 +- .../driver_license/driver_license_v1_document.rbs | 2 +- .../driver_license/driver_license_v1_page.rbs | 4 ++-- .../financial_document/financial_document_v1.rbs | 2 +- .../financial_document_v1_document.rbs | 2 +- .../financial_document_v1_line_item.rbs | 6 +++--- .../financial_document_v1_page.rbs | 4 ++-- .../bank_account_details/bank_account_details_v1.rbs | 2 +- .../bank_account_details_v1_document.rbs | 2 +- .../bank_account_details_v1_page.rbs | 4 ++-- .../bank_account_details/bank_account_details_v2.rbs | 2 +- .../bank_account_details_v2_bban.rbs | 4 ++-- .../bank_account_details_v2_document.rbs | 2 +- .../bank_account_details_v2_page.rbs | 4 ++-- .../product/fr/bank_statement/bank_statement_v2.rbs | 2 +- .../fr/bank_statement/bank_statement_v2_document.rbs | 2 +- .../fr/bank_statement/bank_statement_v2_page.rbs | 4 ++-- .../bank_statement/bank_statement_v2_transaction.rbs | 6 +++--- sig/mindee/product/fr/carte_grise/carte_grise_v1.rbs | 2 +- .../fr/carte_grise/carte_grise_v1_document.rbs | 2 +- .../product/fr/carte_grise/carte_grise_v1_page.rbs | 4 ++-- sig/mindee/product/fr/energy_bill/energy_bill_v1.rbs | 2 +- .../fr/energy_bill/energy_bill_v1_document.rbs | 2 +- .../energy_bill/energy_bill_v1_energy_consumer.rbs | 4 ++-- .../energy_bill/energy_bill_v1_energy_supplier.rbs | 4 ++-- .../fr/energy_bill/energy_bill_v1_energy_usage.rbs | 6 +++--- .../fr/energy_bill/energy_bill_v1_meter_detail.rbs | 4 ++-- .../product/fr/energy_bill/energy_bill_v1_page.rbs | 4 ++-- .../fr/energy_bill/energy_bill_v1_subscription.rbs | 6 +++--- .../energy_bill_v1_taxes_and_contribution.rbs | 6 +++--- sig/mindee/product/fr/health_card/health_card_v1.rbs | 2 +- .../fr/health_card/health_card_v1_document.rbs | 2 +- .../product/fr/health_card/health_card_v1_page.rbs | 4 ++-- sig/mindee/product/fr/id_card/id_card_v1.rbs | 2 +- .../product/fr/id_card/id_card_v1_document.rbs | 2 +- sig/mindee/product/fr/id_card/id_card_v1_page.rbs | 4 ++-- sig/mindee/product/fr/id_card/id_card_v2.rbs | 2 +- .../product/fr/id_card/id_card_v2_document.rbs | 2 +- sig/mindee/product/fr/id_card/id_card_v2_page.rbs | 4 ++-- sig/mindee/product/fr/payslip/payslip_v2.rbs | 2 +- .../fr/payslip/payslip_v2_bank_account_detail.rbs | 4 ++-- .../product/fr/payslip/payslip_v2_document.rbs | 2 +- .../product/fr/payslip/payslip_v2_employee.rbs | 4 ++-- .../product/fr/payslip/payslip_v2_employer.rbs | 4 ++-- .../product/fr/payslip/payslip_v2_employment.rbs | 4 ++-- sig/mindee/product/fr/payslip/payslip_v2_page.rbs | 4 ++-- .../product/fr/payslip/payslip_v2_pay_detail.rbs | 4 ++-- .../product/fr/payslip/payslip_v2_pay_period.rbs | 4 ++-- sig/mindee/product/fr/payslip/payslip_v2_pto.rbs | 4 ++-- .../product/fr/payslip/payslip_v2_salary_detail.rbs | 6 +++--- sig/mindee/product/fr/payslip/payslip_v3.rbs | 2 +- .../fr/payslip/payslip_v3_bank_account_detail.rbs | 4 ++-- .../product/fr/payslip/payslip_v3_document.rbs | 2 +- .../product/fr/payslip/payslip_v3_employee.rbs | 4 ++-- .../product/fr/payslip/payslip_v3_employer.rbs | 4 ++-- .../product/fr/payslip/payslip_v3_employment.rbs | 4 ++-- sig/mindee/product/fr/payslip/payslip_v3_page.rbs | 4 ++-- .../product/fr/payslip/payslip_v3_paid_time_off.rbs | 6 +++--- .../product/fr/payslip/payslip_v3_pay_detail.rbs | 4 ++-- .../product/fr/payslip/payslip_v3_pay_period.rbs | 4 ++-- .../product/fr/payslip/payslip_v3_salary_detail.rbs | 6 +++--- .../ind/indian_passport/indian_passport_v1.rbs | 2 +- .../indian_passport/indian_passport_v1_document.rbs | 2 +- .../ind/indian_passport/indian_passport_v1_page.rbs | 4 ++-- .../product/international_id/international_id_v2.rbs | 2 +- .../international_id_v2_document.rbs | 2 +- .../international_id/international_id_v2_page.rbs | 4 ++-- sig/mindee/product/invoice/invoice_v4.rbs | 2 +- sig/mindee/product/invoice/invoice_v4_document.rbs | 2 +- sig/mindee/product/invoice/invoice_v4_line_item.rbs | 6 +++--- sig/mindee/product/invoice/invoice_v4_page.rbs | 4 ++-- .../product/invoice_splitter/invoice_splitter_v1.rbs | 2 +- .../invoice_splitter_v1_document.rbs | 2 +- .../invoice_splitter_v1_invoice_page_group.rbs | 6 +++--- .../invoice_splitter/invoice_splitter_v1_page.rbs | 4 ++-- .../multi_receipts_detector_v1.rbs | 2 +- .../multi_receipts_detector_v1_document.rbs | 2 +- .../multi_receipts_detector_v1_page.rbs | 4 ++-- .../nutrition_facts_label_v1.rbs | 2 +- .../nutrition_facts_label_v1_added_sugar.rbs | 4 ++-- .../nutrition_facts_label_v1_calorie.rbs | 4 ++-- .../nutrition_facts_label_v1_cholesterol.rbs | 4 ++-- .../nutrition_facts_label_v1_dietary_fiber.rbs | 4 ++-- .../nutrition_facts_label_v1_document.rbs | 2 +- .../nutrition_facts_label_v1_nutrient.rbs | 6 +++--- .../nutrition_facts_label_v1_page.rbs | 4 ++-- .../nutrition_facts_label_v1_protein.rbs | 4 ++-- .../nutrition_facts_label_v1_saturated_fat.rbs | 4 ++-- .../nutrition_facts_label_v1_serving_size.rbs | 4 ++-- .../nutrition_facts_label_v1_sodium.rbs | 4 ++-- .../nutrition_facts_label_v1_total_carbohydrate.rbs | 4 ++-- .../nutrition_facts_label_v1_total_fat.rbs | 4 ++-- .../nutrition_facts_label_v1_total_sugar.rbs | 4 ++-- .../nutrition_facts_label_v1_trans_fat.rbs | 4 ++-- sig/mindee/product/passport/passport_v1.rbs | 2 +- sig/mindee/product/passport/passport_v1_document.rbs | 2 +- sig/mindee/product/passport/passport_v1_page.rbs | 4 ++-- sig/mindee/product/receipt/receipt_v5.rbs | 2 +- sig/mindee/product/receipt/receipt_v5_document.rbs | 2 +- sig/mindee/product/receipt/receipt_v5_line_item.rbs | 6 +++--- sig/mindee/product/receipt/receipt_v5_page.rbs | 4 ++-- sig/mindee/product/resume/resume_v1.rbs | 2 +- sig/mindee/product/resume/resume_v1_certificate.rbs | 6 +++--- sig/mindee/product/resume/resume_v1_document.rbs | 2 +- sig/mindee/product/resume/resume_v1_education.rbs | 6 +++--- sig/mindee/product/resume/resume_v1_language.rbs | 6 +++--- sig/mindee/product/resume/resume_v1_page.rbs | 4 ++-- .../resume/resume_v1_professional_experience.rbs | 6 +++--- .../product/resume/resume_v1_social_networks_url.rbs | 6 +++--- sig/mindee/product/universal/universal_document.rbs | 2 +- sig/mindee/product/universal/universal_page.rbs | 4 ++-- .../product/universal/universal_prediction.rbs | 10 +++++----- sig/mindee/product/us/bank_check/bank_check_v1.rbs | 2 +- .../product/us/bank_check/bank_check_v1_document.rbs | 2 +- .../product/us/bank_check/bank_check_v1_page.rbs | 4 ++-- .../us/healthcare_card/healthcare_card_v1.rbs | 2 +- .../us/healthcare_card/healthcare_card_v1_copay.rbs | 6 +++--- .../healthcare_card/healthcare_card_v1_document.rbs | 2 +- .../us/healthcare_card/healthcare_card_v1_page.rbs | 4 ++-- sig/mindee/product/us/us_mail/us_mail_v2.rbs | 2 +- .../product/us/us_mail/us_mail_v2_document.rbs | 2 +- sig/mindee/product/us/us_mail/us_mail_v2_page.rbs | 4 ++-- .../us/us_mail/us_mail_v2_recipient_address.rbs | 6 +++--- .../product/us/us_mail/us_mail_v2_sender_address.rbs | 4 ++-- sig/mindee/product/us/us_mail/us_mail_v3.rbs | 2 +- .../product/us/us_mail/us_mail_v3_document.rbs | 2 +- sig/mindee/product/us/us_mail/us_mail_v3_page.rbs | 4 ++-- .../us/us_mail/us_mail_v3_recipient_address.rbs | 6 +++--- .../product/us/us_mail/us_mail_v3_sender_address.rbs | 4 ++-- sig/mindee/product/us/w9/w9_v1.rbs | 2 +- sig/mindee/product/us/w9/w9_v1_document.rbs | 2 +- sig/mindee/product/us/w9/w9_v1_page.rbs | 4 ++-- sig/mindee/version.rbs | 4 ++-- 174 files changed, 302 insertions(+), 302 deletions(-) diff --git a/lib/mindee/http/endpoint.rb b/lib/mindee/http/endpoint.rb index ee4b8be67..8bb829530 100644 --- a/lib/mindee/http/endpoint.rb +++ b/lib/mindee/http/endpoint.rb @@ -114,7 +114,7 @@ def parse_async(job_id) def predict_req_post(input_source, opts) uri = URI("#{@url_root}/predict") - params = {} # : Hash[Symbol | String, untyped] + params = {} # : Hash[String | Symbol, untyped] params[:cropper] = 'true' if opts.cropper params[:full_text_ocr] = 'true' if opts.full_text uri.query = URI.encode_www_form(params) @@ -150,7 +150,7 @@ def document_queue_req_post(input_source, opts) URI("#{@url_root}/predict_async") end - params = {} # : Hash[Symbol | String, untyped] + params = {} # : Hash[String | Symbol, untyped] params[:cropper] = 'true' if opts.cropper params[:full_text_ocr] = 'true' if opts.full_text params[:rag] = 'true' if opts.rag diff --git a/lib/mindee/http/workflow_endpoint.rb b/lib/mindee/http/workflow_endpoint.rb index 4e7bab078..2175793e6 100644 --- a/lib/mindee/http/workflow_endpoint.rb +++ b/lib/mindee/http/workflow_endpoint.rb @@ -48,7 +48,7 @@ def execute_workflow(input_source, opts) # @return [Net::HTTPResponse, nil] def workflow_execution_req_post(input_source, opts) uri = URI(@url) - params = {} # : Hash[Symbol | String, untyped] + params = {} # : Hash[String | Symbol, untyped] params[:full_text_ocr] = 'true' if opts.full_text params[:rag] = 'true' if opts.rag uri.query = URI.encode_www_form(params) if params.any? diff --git a/lib/mindee/parsing/universal/universal_object_field.rb b/lib/mindee/parsing/universal/universal_object_field.rb index 33dbe0c4f..4c1740e5c 100644 --- a/lib/mindee/parsing/universal/universal_object_field.rb +++ b/lib/mindee/parsing/universal/universal_object_field.rb @@ -26,7 +26,7 @@ class UniversalObjectField # Raw unprocessed value, as it was sent by the server. def initialize(raw_prediction, page_id = nil) - @all_values = {} # : Hash[Symbol | String, untyped] + @all_values = {} # : Hash[String | Symbol, untyped] item_page_id = nil raw_prediction.each do |name, value| case name diff --git a/lib/mindee/product/universal/universal_prediction.rb b/lib/mindee/product/universal/universal_prediction.rb index 144d0a588..b933984cd 100644 --- a/lib/mindee/product/universal/universal_prediction.rb +++ b/lib/mindee/product/universal/universal_prediction.rb @@ -16,7 +16,7 @@ class UniversalPrediction < Mindee::Parsing::Common::Prediction def initialize(_ = nil) super - @fields = {} # : Hash[Symbol | String, untyped] + @fields = {} # : Hash[String | Symbol, untyped] end # String representation. @@ -81,7 +81,7 @@ 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 = {} # : Hash[Symbol | String, untyped] + single_fields = {} # : Hash[String | Symbol, untyped] @fields.each do |field_name, field_value| single_fields[field_name] = field_value if field_value.is_a?(Mindee::Parsing::Standard::StringField) end @@ -91,7 +91,7 @@ def single_fields # Returns a hash of all list-like fields # @return [Hash] def list_fields - list_fields = {} # : Hash[Symbol | String, Mindee::Parsing::Universal::UniversalListField] + list_fields = {} # : Hash[String | Symbol, Mindee::Parsing::Universal::UniversalListField] @fields.each do |field_name, field_value| list_fields[field_name] = field_value if field_value.is_a?(Mindee::Parsing::Universal::UniversalListField) end @@ -101,7 +101,7 @@ def list_fields # Returns a hash of all object-like fields # @return [Hash] def object_fields - object_fields = {} # : Hash[Symbol | String, untyped] + object_fields = {} # : Hash[String | Symbol, untyped] @fields.each do |field_name, field_value| if field_value.is_a?(Mindee::Parsing::Universal::UniversalObjectField) object_fields[field_name] = diff --git a/lib/mindee/version.rb b/lib/mindee/version.rb index 9a596b496..5ee24504b 100644 --- a/lib/mindee/version.rb +++ b/lib/mindee/version.rb @@ -6,7 +6,7 @@ module Mindee VERSION = '4.6.0' # Finds and return the current platform. - # @return [Symbol, Hash[Symbol | String, Regexp], Nil?] + # @return [Symbol, Hash[String | Symbol, Regexp], Nil?] def self.find_platform host = RbConfig::CONFIG['host_os'] platforms = { diff --git a/sig/mindee/client.rbs b/sig/mindee/client.rbs index 9d7e1f883..6c4dcd5c8 100644 --- a/sig/mindee/client.rbs +++ b/sig/mindee/client.rbs @@ -15,7 +15,7 @@ module Mindee attr_accessor delay_sec: Integer | Float attr_accessor max_retries: Integer - def initialize: (params: Hash[Symbol | String, untyped]) -> void + def initialize: (params: Hash[String | Symbol, untyped]) -> void end class WorkflowOptions @@ -27,7 +27,7 @@ module Mindee attr_accessor page_options: (PageOptions) attr_accessor close_file: bool - def initialize: (params: Hash[Symbol | String, untyped]) -> void + def initialize: (params: Hash[String | Symbol, untyped]) -> void end class Client @@ -35,12 +35,12 @@ module Mindee def initialize: (?api_key: String) -> void def logger: () -> Logging - def parse: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), ?endpoint: (HTTP::Endpoint?), options: ParseOptions | Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse + def parse: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), ?endpoint: (HTTP::Endpoint?), options: ParseOptions | Hash[String | Symbol, untyped]) -> Parsing::Common::ApiResponse def parse_sync: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), HTTP::Endpoint, ParseOptions) -> Parsing::Common::ApiResponse - def enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), ?endpoint: (HTTP::Endpoint?), options: ParseOptions|Hash[Symbol | String, untyped]) -> Parsing::Common::ApiResponse + def enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, singleton(Parsing::Common::Inference), ?endpoint: (HTTP::Endpoint?), options: ParseOptions|Hash[String | Symbol, untyped]) -> Parsing::Common::ApiResponse def parse_queued: (String, singleton(Parsing::Common::Inference), ?endpoint: HTTP::Endpoint?) -> Parsing::Common::ApiResponse def enqueue_and_parse: (Input::Source::URLInputSource|Input::Source::LocalInputSource, singleton(Parsing::Common::Inference), 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 execute_workflow: (Input::Source::URLInputSource|Input::Source::LocalInputSource, String, options: (Hash[String | Symbol, untyped] | WorkflowOptions)) -> Parsing::Common::WorkflowResponse def load_prediction: (singleton(Parsing::Common::Inference), Input::LocalResponse) -> Parsing::Common::ApiResponse def source_from_path: (String, ?repair_pdf: bool) -> Input::Source::PathInputSource def source_from_bytes: (String, String, ?repair_pdf: bool) -> Input::Source::BytesInputSource @@ -50,7 +50,7 @@ module Mindee def create_endpoint: (endpoint_name: String, account_name: String, version: String) -> HTTP::Endpoint private - def normalize_parse_options: ((Hash[Symbol | String, untyped] | ParseOptions)) -> ParseOptions + def normalize_parse_options: ((Hash[String | Symbol, untyped] | ParseOptions)) -> ParseOptions def process_pdf_if_required: (Input::Source::LocalInputSource, ParseOptions | WorkflowOptions) -> void def initialize_endpoint: (singleton(Parsing::Common::Inference), ?endpoint_name: String, ?account_name: String, ?version: String) -> HTTP::Endpoint def validate_async_params: (Integer | Float, Integer | Float, Integer) -> void diff --git a/sig/mindee/http/endpoint.rbs b/sig/mindee/http/endpoint.rbs index e4c9021cc..24adca087 100644 --- a/sig/mindee/http/endpoint.rbs +++ b/sig/mindee/http/endpoint.rbs @@ -16,9 +16,9 @@ module Mindee def logger: () -> Logger def initialize: (String, String, String | nil, ?api_key: String) -> String - def predict: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Hash[Symbol | String, untyped], String] - def predict_async: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Hash[Symbol | String, untyped], String] - def parse_async: (String) -> [Hash[Symbol | String, untyped], String] + def predict: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Hash[String | Symbol, untyped], String] + def predict_async: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Hash[String | Symbol, untyped], String] + def parse_async: (String) -> [Hash[String | Symbol, untyped], String] def predict_req_post: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> Net::HTTPResponse def document_queue_req_post: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> Net::HTTPResponse def document_queue_req_get: (String) -> Net::HTTPResponse diff --git a/sig/mindee/page_options.rbs b/sig/mindee/page_options.rbs index c212b474d..b4b58d151 100644 --- a/sig/mindee/page_options.rbs +++ b/sig/mindee/page_options.rbs @@ -6,6 +6,6 @@ module Mindee attr_accessor operation: :KEEP_ONLY | :REMOVE attr_accessor on_min_pages: Integer? - def initialize: (params: Hash[Symbol | String, untyped]) -> void + def initialize: (params: Hash[String | Symbol, untyped]) -> void end end diff --git a/sig/mindee/parsing/common/api_response.rbs b/sig/mindee/parsing/common/api_response.rbs index 6c3decc57..126363bd0 100644 --- a/sig/mindee/parsing/common/api_response.rbs +++ b/sig/mindee/parsing/common/api_response.rbs @@ -20,7 +20,7 @@ module Mindee 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] | Net::HTTPResponse, String) -> void + def initialize: (singleton(Parsing::Common::Inference), Hash[String | Symbol, untyped] | Net::HTTPResponse, String) -> void end end end diff --git a/sig/mindee/parsing/common/job.rbs b/sig/mindee/parsing/common/job.rbs index 2b7645191..2e89dc643 100644 --- a/sig/mindee/parsing/common/job.rbs +++ b/sig/mindee/parsing/common/job.rbs @@ -8,8 +8,8 @@ module Mindee def available_at: -> Time def status: () -> (:waiting | :processing | :completed | :failed) def millisecs_taken: -> Integer - def error: -> Hash[Symbol | String, untyped] - def initialize: (Hash[Symbol | String, untyped]) -> void + def error: -> Hash[String | Symbol, untyped] + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/parsing/common/workflow_response.rbs b/sig/mindee/parsing/common/workflow_response.rbs index 5719f62d8..40fa84a42 100644 --- a/sig/mindee/parsing/common/workflow_response.rbs +++ b/sig/mindee/parsing/common/workflow_response.rbs @@ -10,7 +10,7 @@ module Mindee def execution: -> Execution def api_request: -> ApiRequest def raw_http: -> String - def initialize: (singleton(Parsing::Common::Inference), Hash[Symbol | String, untyped] | Net::HTTPResponse, String) -> void + def initialize: (singleton(Parsing::Common::Inference), Hash[String | Symbol, untyped] | Net::HTTPResponse, String) -> void end end end diff --git a/sig/mindee/parsing/standard/abstract_field.rbs b/sig/mindee/parsing/standard/abstract_field.rbs index 0374fa1e7..a870301b4 100644 --- a/sig/mindee/parsing/standard/abstract_field.rbs +++ b/sig/mindee/parsing/standard/abstract_field.rbs @@ -8,7 +8,7 @@ module Mindee def page_id: -> Integer? def confidence: -> Float? def confidence=: (Float?) -> Float? - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String def self.array_confidence: (Array[untyped]) -> Float def self.array_sum: (Array[untyped]) -> Float diff --git a/sig/mindee/parsing/standard/address_field.rbs b/sig/mindee/parsing/standard/address_field.rbs index e1d9e493e..aff39e679 100644 --- a/sig/mindee/parsing/standard/address_field.rbs +++ b/sig/mindee/parsing/standard/address_field.rbs @@ -11,7 +11,7 @@ module Mindee def postal_code: -> String def state: -> String def country: -> String - def initialize: (Hash[Symbol | String, untyped], ?Integer?, ?reconstructed: bool) -> void + def initialize: (Hash[String | Symbol, untyped], ?Integer?, ?reconstructed: bool) -> void end end end diff --git a/sig/mindee/parsing/standard/base_field.rbs b/sig/mindee/parsing/standard/base_field.rbs index a92fb08f6..3db3db896 100644 --- a/sig/mindee/parsing/standard/base_field.rbs +++ b/sig/mindee/parsing/standard/base_field.rbs @@ -3,7 +3,7 @@ module Mindee module Parsing module Standard class BaseField < Parsing::Standard::AbstractField - def initialize: (Hash[Symbol | String, untyped], Integer?, ?reconstructed: bool) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?, ?reconstructed: bool) -> void def value: -> (String | Float | Integer | bool) def reconstructed: -> bool end diff --git a/sig/mindee/parsing/standard/boolean_field.rbs b/sig/mindee/parsing/standard/boolean_field.rbs index 77fdeca61..05f165438 100644 --- a/sig/mindee/parsing/standard/boolean_field.rbs +++ b/sig/mindee/parsing/standard/boolean_field.rbs @@ -4,7 +4,7 @@ module Mindee module Standard class BooleanField < BaseField def value: -> bool? - def initialize: (Hash[Symbol | String, untyped], ?Integer?, ?reconstructed: false) -> void + def initialize: (Hash[String | Symbol, untyped], ?Integer?, ?reconstructed: false) -> void def to_s: -> String end end diff --git a/sig/mindee/parsing/standard/locale_field.rbs b/sig/mindee/parsing/standard/locale_field.rbs index d806cd77b..12d07782d 100644 --- a/sig/mindee/parsing/standard/locale_field.rbs +++ b/sig/mindee/parsing/standard/locale_field.rbs @@ -8,7 +8,7 @@ module Mindee def country: -> String? def currency: -> String? def value: -> String? - def initialize: (Hash[Symbol | String, untyped], ?Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], ?Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/parsing/standard/position_field.rbs b/sig/mindee/parsing/standard/position_field.rbs index 090df5c9f..a2976c538 100644 --- a/sig/mindee/parsing/standard/position_field.rbs +++ b/sig/mindee/parsing/standard/position_field.rbs @@ -8,9 +8,9 @@ module Mindee def quadrangle: -> Geometry::Quadrilateral def rectangle: -> Geometry::Quadrilateral def bounding_box: -> Geometry::Quadrilateral - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String - def to_quadrilateral: (Hash[Symbol | String, Array[untyped]], String) -> Geometry::Quadrilateral? + def to_quadrilateral: (Hash[String | Symbol, Array[untyped]], String) -> Geometry::Quadrilateral? end end end diff --git a/sig/mindee/parsing/standard/string_field.rbs b/sig/mindee/parsing/standard/string_field.rbs index 9ff2314ac..b569e7d1f 100644 --- a/sig/mindee/parsing/standard/string_field.rbs +++ b/sig/mindee/parsing/standard/string_field.rbs @@ -5,7 +5,7 @@ module Mindee class StringField < BaseField def value: -> String def raw_value: -> String - def initialize: (Hash[Symbol | String, untyped], ?Integer?, ?reconstructed: bool) -> void + def initialize: (Hash[String | Symbol, 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 254794b29..4bccf4149 100644 --- a/sig/mindee/parsing/universal/universal_list_field.rbs +++ b/sig/mindee/parsing/universal/universal_list_field.rbs @@ -6,7 +6,7 @@ module Mindee attr_reader page_id: Integer attr_reader values: Array[UniversalObjectField | Standard::StringField] - def initialize: (Array[Hash[Symbol | String, untyped]], ?Integer?) -> void + def initialize: (Array[Hash[String | Symbol, untyped]], ?Integer?) -> void def contents_list: -> Array[String] def contents_string: (?String) -> String def to_s: -> String diff --git a/sig/mindee/parsing/universal/universal_object_field.rbs b/sig/mindee/parsing/universal/universal_object_field.rbs index 3decc1136..1be4d90e2 100644 --- a/sig/mindee/parsing/universal/universal_object_field.rbs +++ b/sig/mindee/parsing/universal/universal_object_field.rbs @@ -8,7 +8,7 @@ module Mindee attr_reader page_id: Integer attr_reader raw_value: String - def initialize: (Hash[Symbol | String, untyped], ?Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], ?Integer?) -> void def str_level: (?Integer) -> String def method_missing: (Symbol, *untyped, untyped) -> (String @@ -23,7 +23,7 @@ module Mindee def handle_position_field: (String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil, Integer?) -> void def handle_default_field: (String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil) -> void end - def self.universal_object?: (Hash[Symbol | String, untyped]) -> bool + def self.universal_object?: (Hash[String | Symbol, untyped]) -> bool end end end diff --git a/sig/mindee/pdf/pdf_tools.rbs b/sig/mindee/pdf/pdf_tools.rbs index cd0137a60..769c94239 100644 --- a/sig/mindee/pdf/pdf_tools.rbs +++ b/sig/mindee/pdf/pdf_tools.rbs @@ -18,7 +18,7 @@ module Mindee def self.stream_has_text?: (Origami::Stream) -> bool def self.source_text?: (StringIO | File) -> bool def self.create_xobject: (singleton(MiniMagick::Image) | MiniMagick::Image) -> Origami::Graphics::ImageXObject - def self.set_xobject_properties: (Origami::Graphics::ImageXObject, MiniMagick::Image | singleton(MiniMagick::Image)) -> void + def self.set_xobject_properties: (Origami::Graphics::ImageXObject, singleton(MiniMagick::Image) | MiniMagick::Image) -> void def self.determine_filter: (singleton(MiniMagick::Image) | MiniMagick::Image) -> (:DCTDecode | :FlateDecode | :LZWDecode) def self.determine_colorspace: (singleton(MiniMagick::Image) | MiniMagick::Image) -> (:DeviceCMYK | :DeviceGray | :DeviceRGB) def self.add_content_to_page: (Origami::Page, String, Integer, Integer) -> void diff --git a/sig/mindee/product/barcode_reader/barcode_reader_v1.rbs b/sig/mindee/product/barcode_reader/barcode_reader_v1.rbs index f92cb485d..f6c25f5fa 100644 --- a/sig/mindee/product/barcode_reader/barcode_reader_v1.rbs +++ b/sig/mindee/product/barcode_reader/barcode_reader_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module BarcodeReader class BarcodeReaderV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index a0c770466..1cf918b53 100644 --- a/sig/mindee/product/barcode_reader/barcode_reader_v1_document.rbs +++ b/sig/mindee/product/barcode_reader/barcode_reader_v1_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module BarcodeReader class BarcodeReaderV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def codes_1d: -> (Array[Parsing::Standard::StringField]) def codes_2d: -> (Array[Parsing::Standard::StringField]) def to_s: -> String diff --git a/sig/mindee/product/barcode_reader/barcode_reader_v1_page.rbs b/sig/mindee/product/barcode_reader/barcode_reader_v1_page.rbs index a32b8ad73..4236b483e 100644 --- a/sig/mindee/product/barcode_reader/barcode_reader_v1_page.rbs +++ b/sig/mindee/product/barcode_reader/barcode_reader_v1_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module BarcodeReader class BarcodeReaderV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class BarcodeReaderV1PagePrediction < BarcodeReaderV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index e5ec9295d..bc9546b5c 100644 --- a/sig/mindee/product/bill_of_lading/bill_of_lading_v1.rbs +++ b/sig/mindee/product/bill_of_lading/bill_of_lading_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module BillOfLading class BillOfLadingV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 53f1a0007..b51db8bbe 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module BillOfLading class BillOfLadingV1Carrier < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def name: -> String def professional_number: -> String def scac: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index d043b7f72..024021651 100644 --- 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 @@ -2,15 +2,15 @@ module Mindee module Product module BillOfLading class BillOfLadingV1CarrierItem < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index 4e5e3a9b9..5640ae6ac 100644 --- 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 @@ -2,12 +2,12 @@ module Mindee module Product module BillOfLading class BillOfLadingV1Consignee < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> String def email: -> String def name: -> String def phone: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 68e6a05b0..9b459c7c2 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 @@ -4,7 +4,7 @@ module Mindee module Product module BillOfLading class BillOfLadingV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def bill_of_lading_number: -> (Parsing::Standard::StringField) def carrier: -> (Product::BillOfLading::BillOfLadingV1Carrier) def carrier_items: -> (Product::BillOfLading::BillOfLadingV1CarrierItems) 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 index 40a0cd504..f0fb65f0c 100644 --- 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 @@ -2,12 +2,12 @@ module Mindee module Product module BillOfLading class BillOfLadingV1NotifyParty < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> String def email: -> String def name: -> String def phone: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 098c026f8..45964c572 100644 --- 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 @@ -4,10 +4,10 @@ module Mindee module Product module BillOfLading class BillOfLadingV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class BillOfLadingV1PagePrediction < BillOfLadingV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index ea7f8a9ee..67af0cc3d 100644 --- 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 @@ -2,12 +2,12 @@ module Mindee module Product module BillOfLading class BillOfLadingV1Shipper < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> String def email: -> String def name: -> String def phone: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String end end diff --git a/sig/mindee/product/business_card/business_card_v1.rbs b/sig/mindee/product/business_card/business_card_v1.rbs index 3fb7f15f3..f6eb9c1b3 100644 --- a/sig/mindee/product/business_card/business_card_v1.rbs +++ b/sig/mindee/product/business_card/business_card_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module BusinessCard class BusinessCardV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 05440b8b7..14286df57 100644 --- a/sig/mindee/product/business_card/business_card_v1_document.rbs +++ b/sig/mindee/product/business_card/business_card_v1_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module BusinessCard class BusinessCardV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> (Parsing::Standard::StringField) def company: -> (Parsing::Standard::StringField) def email: -> (Parsing::Standard::StringField) diff --git a/sig/mindee/product/business_card/business_card_v1_page.rbs b/sig/mindee/product/business_card/business_card_v1_page.rbs index 8a0c7b30f..bc636440a 100644 --- a/sig/mindee/product/business_card/business_card_v1_page.rbs +++ b/sig/mindee/product/business_card/business_card_v1_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module BusinessCard class BusinessCardV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class BusinessCardV1PagePrediction < BusinessCardV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/cropper/cropper_v1.rbs b/sig/mindee/product/cropper/cropper_v1.rbs index b045ce267..e36799d73 100644 --- a/sig/mindee/product/cropper/cropper_v1.rbs +++ b/sig/mindee/product/cropper/cropper_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module Cropper class CropperV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/product/cropper/cropper_v1_document.rbs b/sig/mindee/product/cropper/cropper_v1_document.rbs index 04c60c29d..a54ebb097 100644 --- a/sig/mindee/product/cropper/cropper_v1_document.rbs +++ b/sig/mindee/product/cropper/cropper_v1_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module Cropper class CropperV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/cropper/cropper_v1_page.rbs b/sig/mindee/product/cropper/cropper_v1_page.rbs index 14f01d1b9..b041c97d5 100644 --- a/sig/mindee/product/cropper/cropper_v1_page.rbs +++ b/sig/mindee/product/cropper/cropper_v1_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module Cropper class CropperV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class CropperV1PagePrediction < CropperV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def cropping: -> Array[Parsing::Standard::PositionField] def to_s: -> String end diff --git a/sig/mindee/product/delivery_note/delivery_note_v1.rbs b/sig/mindee/product/delivery_note/delivery_note_v1.rbs index d0417d2e9..4eccee964 100644 --- a/sig/mindee/product/delivery_note/delivery_note_v1.rbs +++ b/sig/mindee/product/delivery_note/delivery_note_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module DeliveryNote class DeliveryNoteV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 8b0fd425b..eb2059cea 100644 --- a/sig/mindee/product/delivery_note/delivery_note_v1_document.rbs +++ b/sig/mindee/product/delivery_note/delivery_note_v1_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module DeliveryNote class DeliveryNoteV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def customer_address: -> (Parsing::Standard::StringField) def customer_name: -> (Parsing::Standard::StringField) def delivery_date: -> (Parsing::Standard::DateField) diff --git a/sig/mindee/product/delivery_note/delivery_note_v1_page.rbs b/sig/mindee/product/delivery_note/delivery_note_v1_page.rbs index 0c7381006..24792b5bc 100644 --- a/sig/mindee/product/delivery_note/delivery_note_v1_page.rbs +++ b/sig/mindee/product/delivery_note/delivery_note_v1_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module DeliveryNote class DeliveryNoteV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class DeliveryNoteV1PagePrediction < DeliveryNoteV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/driver_license/driver_license_v1.rbs b/sig/mindee/product/driver_license/driver_license_v1.rbs index e2efa549d..70cf6686f 100644 --- a/sig/mindee/product/driver_license/driver_license_v1.rbs +++ b/sig/mindee/product/driver_license/driver_license_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module DriverLicense class DriverLicenseV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index be47a3b35..9946d67fc 100644 --- a/sig/mindee/product/driver_license/driver_license_v1_document.rbs +++ b/sig/mindee/product/driver_license/driver_license_v1_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module DriverLicense class DriverLicenseV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def category: -> (Parsing::Standard::StringField) def country_code: -> (Parsing::Standard::StringField) def date_of_birth: -> (Parsing::Standard::DateField) diff --git a/sig/mindee/product/driver_license/driver_license_v1_page.rbs b/sig/mindee/product/driver_license/driver_license_v1_page.rbs index 1c172f047..d59fc2de7 100644 --- a/sig/mindee/product/driver_license/driver_license_v1_page.rbs +++ b/sig/mindee/product/driver_license/driver_license_v1_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module DriverLicense class DriverLicenseV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class DriverLicenseV1PagePrediction < DriverLicenseV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/financial_document/financial_document_v1.rbs b/sig/mindee/product/financial_document/financial_document_v1.rbs index f3c23cc8d..1958f2b86 100644 --- a/sig/mindee/product/financial_document/financial_document_v1.rbs +++ b/sig/mindee/product/financial_document/financial_document_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module FinancialDocument class FinancialDocumentV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index b9fca7764..e16a6bf81 100644 --- a/sig/mindee/product/financial_document/financial_document_v1_document.rbs +++ b/sig/mindee/product/financial_document/financial_document_v1_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module FinancialDocument class FinancialDocumentV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def billing_address: -> (Parsing::Standard::AddressField) def category: -> (Parsing::Standard::ClassificationField) def customer_address: -> (Parsing::Standard::AddressField) 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 index 4cb2b923e..21994be4d 100644 --- a/sig/mindee/product/financial_document/financial_document_v1_line_item.rbs +++ b/sig/mindee/product/financial_document/financial_document_v1_line_item.rbs @@ -2,7 +2,7 @@ module Mindee module Product module FinancialDocument class FinancialDocumentV1LineItem < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def description: -> String def product_code: -> String def quantity: -> Float @@ -11,8 +11,8 @@ module Mindee 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index 88bfa9b81..b0cf7072b 100644 --- a/sig/mindee/product/financial_document/financial_document_v1_page.rbs +++ b/sig/mindee/product/financial_document/financial_document_v1_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module FinancialDocument class FinancialDocumentV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class FinancialDocumentV1PagePrediction < FinancialDocumentV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index 0226de7b5..3dbdd649b 100644 --- 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 @@ -5,7 +5,7 @@ module Mindee module FR module BankAccountDetails class BankAccountDetailsV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index eddda8305..77cc8662d 100644 --- 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 @@ -5,7 +5,7 @@ module Mindee module FR module BankAccountDetails class BankAccountDetailsV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def account_holder_name: -> (Parsing::Standard::StringField) def iban: -> (Parsing::Standard::StringField) def swift: -> (Parsing::Standard::StringField) 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 index 7852515b4..9aa88d771 100644 --- 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 @@ -5,10 +5,10 @@ module Mindee module FR module BankAccountDetails class BankAccountDetailsV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class BankAccountDetailsV1PagePrediction < BankAccountDetailsV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index 6429e2957..4104f8cac 100644 --- 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 @@ -5,7 +5,7 @@ module Mindee module FR module BankAccountDetails class BankAccountDetailsV2 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 63a1d4b01..c6db964df 100644 --- 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 @@ -3,12 +3,12 @@ module Mindee module FR module BankAccountDetails class BankAccountDetailsV2Bban < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 64225f36e..11925a9d4 100644 --- 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 @@ -5,7 +5,7 @@ module Mindee module FR module BankAccountDetails class BankAccountDetailsV2Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def account_holders_names: -> (Parsing::Standard::StringField) def bban: -> (Product::FR::BankAccountDetails::BankAccountDetailsV2Bban) def iban: -> (Parsing::Standard::StringField) 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 index 75b8fa3f2..3b5813802 100644 --- 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 @@ -5,10 +5,10 @@ module Mindee module FR module BankAccountDetails class BankAccountDetailsV2Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class BankAccountDetailsV2PagePrediction < BankAccountDetailsV2Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs index eeabf480a..9efba9b4f 100644 --- a/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs @@ -5,7 +5,7 @@ module Mindee module FR module BankStatement class BankStatementV2 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs index 9a536ff4d..22dbadc3a 100644 --- a/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs @@ -5,7 +5,7 @@ module Mindee module FR module BankStatement class BankStatementV2Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def account_number: -> (Parsing::Standard::StringField) def bank_address: -> (Parsing::Standard::StringField) def bank_name: -> (Parsing::Standard::StringField) diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs index c586ae46c..3da539654 100644 --- a/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs @@ -5,10 +5,10 @@ module Mindee module FR module BankStatement class BankStatementV2Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class BankStatementV2PagePrediction < BankStatementV2Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs b/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs index 41e4158df..aef64ec1f 100644 --- a/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs +++ b/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs @@ -3,12 +3,12 @@ module Mindee module FR module BankStatement class BankStatementV2Transaction < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index d7d43f769..eb2373bae 100644 --- a/sig/mindee/product/fr/carte_grise/carte_grise_v1.rbs +++ b/sig/mindee/product/fr/carte_grise/carte_grise_v1.rbs @@ -5,7 +5,7 @@ module Mindee module FR module CarteGrise class CarteGriseV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 41385d932..752493dc0 100644 --- a/sig/mindee/product/fr/carte_grise/carte_grise_v1_document.rbs +++ b/sig/mindee/product/fr/carte_grise/carte_grise_v1_document.rbs @@ -5,7 +5,7 @@ module Mindee module FR module CarteGrise class CarteGriseV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def a: -> (Parsing::Standard::StringField) def b: -> (Parsing::Standard::DateField) def c1: -> (Parsing::Standard::StringField) 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 index 3e9cda3a0..a17e25eb3 100644 --- a/sig/mindee/product/fr/carte_grise/carte_grise_v1_page.rbs +++ b/sig/mindee/product/fr/carte_grise/carte_grise_v1_page.rbs @@ -5,10 +5,10 @@ module Mindee module FR module CarteGrise class CarteGriseV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class CarteGriseV1PagePrediction < CarteGriseV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index 3fd863960..2e94fe391 100644 --- a/sig/mindee/product/fr/energy_bill/energy_bill_v1.rbs +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1.rbs @@ -5,7 +5,7 @@ module Mindee module FR module EnergyBill class EnergyBillV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 526d7b7e3..809ed576e 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 @@ -5,7 +5,7 @@ module Mindee module FR module EnergyBill class EnergyBillV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def contract_id: -> (Parsing::Standard::StringField) def delivery_point: -> (Parsing::Standard::StringField) def due_date: -> (Parsing::Standard::DateField) 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 index ad976177e..deb4f8194 100644 --- 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 @@ -3,10 +3,10 @@ module Mindee module FR module EnergyBill class EnergyBillV1EnergyConsumer < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> String def name: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 4b6ba5528..403898436 100644 --- 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 @@ -3,10 +3,10 @@ module Mindee module FR module EnergyBill class EnergyBillV1EnergySupplier < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> String def name: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index ba5591548..f2f2f412d 100644 --- 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 @@ -3,7 +3,7 @@ module Mindee module FR module EnergyBill class EnergyBillV1EnergyUsage < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def consumption: -> Float def description: -> String def end_date: -> String @@ -12,8 +12,8 @@ module Mindee def total: -> Float def unit: -> String def unit_price: -> Float - def printable_values: -> Hash[Symbol | String, untyped] - def table_printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index ccfa50a81..7183023c4 100644 --- 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 @@ -3,11 +3,11 @@ module Mindee module FR module EnergyBill class EnergyBillV1MeterDetail < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def meter_number: -> String def meter_type: -> String def unit: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 19b920437..6b395bacd 100644 --- a/sig/mindee/product/fr/energy_bill/energy_bill_v1_page.rbs +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_page.rbs @@ -5,10 +5,10 @@ module Mindee module FR module EnergyBill class EnergyBillV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class EnergyBillV1PagePrediction < EnergyBillV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index 0812fdd83..cd9ac17aa 100644 --- a/sig/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rbs +++ b/sig/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rbs @@ -3,15 +3,15 @@ module Mindee module FR module EnergyBill class EnergyBillV1Subscription < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index 80fba64ce..3c6ec333f 100644 --- 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 @@ -3,15 +3,15 @@ module Mindee module FR module EnergyBill class EnergyBillV1TaxesAndContribution < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index 35ac7d57c..497e22fb1 100644 --- a/sig/mindee/product/fr/health_card/health_card_v1.rbs +++ b/sig/mindee/product/fr/health_card/health_card_v1.rbs @@ -5,7 +5,7 @@ module Mindee module FR module HealthCard class HealthCardV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index ba15f3d2d..50a8ea5f6 100644 --- a/sig/mindee/product/fr/health_card/health_card_v1_document.rbs +++ b/sig/mindee/product/fr/health_card/health_card_v1_document.rbs @@ -5,7 +5,7 @@ module Mindee module FR module HealthCard class HealthCardV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def given_names: -> (Array[Parsing::Standard::StringField]) def issuance_date: -> (Parsing::Standard::DateField) def social_security: -> (Parsing::Standard::StringField) 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 index 3ff463d38..6b8858de7 100644 --- a/sig/mindee/product/fr/health_card/health_card_v1_page.rbs +++ b/sig/mindee/product/fr/health_card/health_card_v1_page.rbs @@ -5,10 +5,10 @@ module Mindee module FR module HealthCard class HealthCardV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class HealthCardV1PagePrediction < HealthCardV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index 1892193f3..42b46b187 100644 --- a/sig/mindee/product/fr/id_card/id_card_v1.rbs +++ b/sig/mindee/product/fr/id_card/id_card_v1.rbs @@ -5,7 +5,7 @@ module Mindee module FR module IdCard class IdCardV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 2e4af6125..08759aac8 100644 --- a/sig/mindee/product/fr/id_card/id_card_v1_document.rbs +++ b/sig/mindee/product/fr/id_card/id_card_v1_document.rbs @@ -5,7 +5,7 @@ module Mindee module FR module IdCard class IdCardV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def authority: -> (Parsing::Standard::StringField) def birth_date: -> (Parsing::Standard::DateField) def birth_place: -> (Parsing::Standard::StringField) 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 index 78f682d77..9cf966626 100644 --- a/sig/mindee/product/fr/id_card/id_card_v1_page.rbs +++ b/sig/mindee/product/fr/id_card/id_card_v1_page.rbs @@ -5,10 +5,10 @@ module Mindee module FR module IdCard class IdCardV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class IdCardV1PagePrediction < IdCardV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def document_side: -> Parsing::Standard::ClassificationField def to_s: -> String 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 index eb5ed7513..b64e89040 100644 --- a/sig/mindee/product/fr/id_card/id_card_v2.rbs +++ b/sig/mindee/product/fr/id_card/id_card_v2.rbs @@ -5,7 +5,7 @@ module Mindee module FR module IdCard class IdCardV2 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 22abd2970..6b6a3312f 100644 --- a/sig/mindee/product/fr/id_card/id_card_v2_document.rbs +++ b/sig/mindee/product/fr/id_card/id_card_v2_document.rbs @@ -5,7 +5,7 @@ module Mindee module FR module IdCard class IdCardV2Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def alternate_name: -> (Parsing::Standard::StringField) def authority: -> (Parsing::Standard::StringField) def birth_date: -> (Parsing::Standard::DateField) 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 index bfbeeb7a7..f9bd4c9b4 100644 --- a/sig/mindee/product/fr/id_card/id_card_v2_page.rbs +++ b/sig/mindee/product/fr/id_card/id_card_v2_page.rbs @@ -5,10 +5,10 @@ module Mindee module FR module IdCard class IdCardV2Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class IdCardV2PagePrediction < IdCardV2Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def document_side: -> Parsing::Standard::ClassificationField def document_type: -> Parsing::Standard::ClassificationField def to_s: -> String diff --git a/sig/mindee/product/fr/payslip/payslip_v2.rbs b/sig/mindee/product/fr/payslip/payslip_v2.rbs index e74b64b94..9e3660bb4 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2.rbs @@ -5,7 +5,7 @@ module Mindee module FR module Payslip class PayslipV2 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 5c30345e0..4885054ec 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rbs @@ -3,11 +3,11 @@ module Mindee module FR module Payslip class PayslipV2BankAccountDetail < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def bank_name: -> String def iban: -> String def swift: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 922974b18..fcc5273c8 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_document.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_document.rbs @@ -5,7 +5,7 @@ module Mindee module FR module Payslip class PayslipV2Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def bank_account_details: -> (Product::FR::Payslip::PayslipV2BankAccountDetail) def employee: -> (Product::FR::Payslip::PayslipV2Employee) def employer: -> (Product::FR::Payslip::PayslipV2Employer) diff --git a/sig/mindee/product/fr/payslip/payslip_v2_employee.rbs b/sig/mindee/product/fr/payslip/payslip_v2_employee.rbs index cc1cc577f..9551d0485 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_employee.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_employee.rbs @@ -3,7 +3,7 @@ module Mindee module FR module Payslip class PayslipV2Employee < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> String def date_of_birth: -> String def first_name: -> String @@ -11,7 +11,7 @@ module Mindee def phone_number: -> String def registration_number: -> String def social_security_number: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String end end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_employer.rbs b/sig/mindee/product/fr/payslip/payslip_v2_employer.rbs index 06d2dc822..da57db7fa 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_employer.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_employer.rbs @@ -3,7 +3,7 @@ module Mindee module FR module Payslip class PayslipV2Employer < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> String def company_id: -> String def company_site: -> String @@ -11,7 +11,7 @@ module Mindee def name: -> String def phone_number: -> String def urssaf_number: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String end end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_employment.rbs b/sig/mindee/product/fr/payslip/payslip_v2_employment.rbs index 774c714bc..2aa5dbb6e 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_employment.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_employment.rbs @@ -3,14 +3,14 @@ module Mindee module FR module Payslip class PayslipV2Employment < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String end end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_page.rbs b/sig/mindee/product/fr/payslip/payslip_v2_page.rbs index 8b1b29d52..4b9e3e146 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_page.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_page.rbs @@ -5,10 +5,10 @@ module Mindee module FR module Payslip class PayslipV2Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class PayslipV2PagePrediction < PayslipV2Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index 9cd65bc66..082f73113 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_pay_detail.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_pay_detail.rbs @@ -3,7 +3,7 @@ module Mindee module FR module Payslip class PayslipV2PayDetail < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def gross_salary: -> Float def gross_salary_ytd: -> Float def income_tax_rate: -> Float @@ -14,7 +14,7 @@ module Mindee def net_taxable_ytd: -> Float def total_cost_employer: -> Float def total_taxes_and_deductions: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index eb4bf8978..10097ae19 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_pay_period.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_pay_period.rbs @@ -3,13 +3,13 @@ module Mindee module FR module Payslip class PayslipV2PayPeriod < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String end end diff --git a/sig/mindee/product/fr/payslip/payslip_v2_pto.rbs b/sig/mindee/product/fr/payslip/payslip_v2_pto.rbs index a80ad0734..45aae4339 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_pto.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_pto.rbs @@ -3,11 +3,11 @@ module Mindee module FR module Payslip class PayslipV2Pto < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index a2f924101..f6deb33ac 100644 --- a/sig/mindee/product/fr/payslip/payslip_v2_salary_detail.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v2_salary_detail.rbs @@ -3,13 +3,13 @@ module Mindee module FR module Payslip class PayslipV2SalaryDetail < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String end diff --git a/sig/mindee/product/fr/payslip/payslip_v3.rbs b/sig/mindee/product/fr/payslip/payslip_v3.rbs index 193937f10..ab2dbac6e 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3.rbs @@ -5,7 +5,7 @@ module Mindee module FR module Payslip class PayslipV3 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index fbf0ebdf8..a5a161ca6 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rbs @@ -3,11 +3,11 @@ module Mindee module FR module Payslip class PayslipV3BankAccountDetail < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def bank_name: -> String def iban: -> String def swift: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 33a9dbd3c..deab66dfa 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_document.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_document.rbs @@ -5,7 +5,7 @@ module Mindee module FR module Payslip class PayslipV3Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def bank_account_details: -> (Product::FR::Payslip::PayslipV3BankAccountDetail) def employee: -> (Product::FR::Payslip::PayslipV3Employee) def employer: -> (Product::FR::Payslip::PayslipV3Employer) diff --git a/sig/mindee/product/fr/payslip/payslip_v3_employee.rbs b/sig/mindee/product/fr/payslip/payslip_v3_employee.rbs index a2d2b10c6..8935b9b86 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_employee.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_employee.rbs @@ -3,7 +3,7 @@ module Mindee module FR module Payslip class PayslipV3Employee < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> String def date_of_birth: -> String def first_name: -> String @@ -11,7 +11,7 @@ module Mindee def phone_number: -> String def registration_number: -> String def social_security_number: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String end end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_employer.rbs b/sig/mindee/product/fr/payslip/payslip_v3_employer.rbs index 54067b7ee..a05a20013 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_employer.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_employer.rbs @@ -3,7 +3,7 @@ module Mindee module FR module Payslip class PayslipV3Employer < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> String def company_id: -> String def company_site: -> String @@ -11,7 +11,7 @@ module Mindee def name: -> String def phone_number: -> String def urssaf_number: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String end end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_employment.rbs b/sig/mindee/product/fr/payslip/payslip_v3_employment.rbs index 3e6f96390..2856d1a85 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_employment.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_employment.rbs @@ -3,7 +3,7 @@ module Mindee module FR module Payslip class PayslipV3Employment < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def category: -> String def coefficient: -> String def collective_agreement: -> String @@ -11,7 +11,7 @@ module Mindee def position_level: -> String def seniority_date: -> String def start_date: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String end end diff --git a/sig/mindee/product/fr/payslip/payslip_v3_page.rbs b/sig/mindee/product/fr/payslip/payslip_v3_page.rbs index eeaf8d78b..771111d34 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_page.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_page.rbs @@ -5,10 +5,10 @@ module Mindee module FR module Payslip class PayslipV3Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class PayslipV3PagePrediction < PayslipV3Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index d5cdd7fab..5ebb28a41 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_paid_time_off.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_paid_time_off.rbs @@ -3,14 +3,14 @@ module Mindee module FR module Payslip class PayslipV3PaidTimeOff < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index 466d7423f..da6b575c6 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_pay_detail.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_pay_detail.rbs @@ -3,7 +3,7 @@ module Mindee module FR module Payslip class PayslipV3PayDetail < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def gross_salary: -> Float def gross_salary_ytd: -> Float def income_tax_rate: -> Float @@ -14,7 +14,7 @@ module Mindee def net_taxable_ytd: -> Float def total_cost_employer: -> Float def total_taxes_and_deductions: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index eba9d2e76..be74ceda7 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_pay_period.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_pay_period.rbs @@ -3,13 +3,13 @@ module Mindee module FR module Payslip class PayslipV3PayPeriod < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 5c5d417a1..e560d1c20 100644 --- a/sig/mindee/product/fr/payslip/payslip_v3_salary_detail.rbs +++ b/sig/mindee/product/fr/payslip/payslip_v3_salary_detail.rbs @@ -3,14 +3,14 @@ module Mindee module FR module Payslip class PayslipV3SalaryDetail < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index ecdcf7df1..09fa33b4f 100644 --- a/sig/mindee/product/ind/indian_passport/indian_passport_v1.rbs +++ b/sig/mindee/product/ind/indian_passport/indian_passport_v1.rbs @@ -5,7 +5,7 @@ module Mindee module IND module IndianPassport class IndianPassportV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 33a6e1f87..dab7c5f73 100644 --- a/sig/mindee/product/ind/indian_passport/indian_passport_v1_document.rbs +++ b/sig/mindee/product/ind/indian_passport/indian_passport_v1_document.rbs @@ -5,7 +5,7 @@ module Mindee module IND module IndianPassport class IndianPassportV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address1: -> (Parsing::Standard::StringField) def address2: -> (Parsing::Standard::StringField) def address3: -> (Parsing::Standard::StringField) 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 index 4d3324179..a5a04c18a 100644 --- a/sig/mindee/product/ind/indian_passport/indian_passport_v1_page.rbs +++ b/sig/mindee/product/ind/indian_passport/indian_passport_v1_page.rbs @@ -5,10 +5,10 @@ module Mindee module IND module IndianPassport class IndianPassportV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class IndianPassportV1PagePrediction < IndianPassportV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/international_id/international_id_v2.rbs b/sig/mindee/product/international_id/international_id_v2.rbs index dcd65fbbb..2d3209608 100644 --- a/sig/mindee/product/international_id/international_id_v2.rbs +++ b/sig/mindee/product/international_id/international_id_v2.rbs @@ -4,7 +4,7 @@ module Mindee module Product module InternationalId class InternationalIdV2 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 5acda5f8e..89605400a 100644 --- a/sig/mindee/product/international_id/international_id_v2_document.rbs +++ b/sig/mindee/product/international_id/international_id_v2_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module InternationalId class InternationalIdV2Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> (Parsing::Standard::StringField) def birth_date: -> (Parsing::Standard::DateField) def birth_place: -> (Parsing::Standard::StringField) diff --git a/sig/mindee/product/international_id/international_id_v2_page.rbs b/sig/mindee/product/international_id/international_id_v2_page.rbs index 154f6fec4..aff9c96ec 100644 --- a/sig/mindee/product/international_id/international_id_v2_page.rbs +++ b/sig/mindee/product/international_id/international_id_v2_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module InternationalId class InternationalIdV2Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class InternationalIdV2PagePrediction < InternationalIdV2Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/invoice/invoice_v4.rbs b/sig/mindee/product/invoice/invoice_v4.rbs index b6df6ecfb..dce951753 100644 --- a/sig/mindee/product/invoice/invoice_v4.rbs +++ b/sig/mindee/product/invoice/invoice_v4.rbs @@ -4,7 +4,7 @@ module Mindee module Product module Invoice class InvoiceV4 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/product/invoice/invoice_v4_document.rbs b/sig/mindee/product/invoice/invoice_v4_document.rbs index 78823fc07..c1ac95247 100644 --- a/sig/mindee/product/invoice/invoice_v4_document.rbs +++ b/sig/mindee/product/invoice/invoice_v4_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module Invoice class InvoiceV4Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def billing_address: -> (Parsing::Standard::AddressField) def category: -> (Parsing::Standard::ClassificationField) def customer_address: -> (Parsing::Standard::AddressField) diff --git a/sig/mindee/product/invoice/invoice_v4_line_item.rbs b/sig/mindee/product/invoice/invoice_v4_line_item.rbs index d0cd2fc29..b4217c6f1 100644 --- a/sig/mindee/product/invoice/invoice_v4_line_item.rbs +++ b/sig/mindee/product/invoice/invoice_v4_line_item.rbs @@ -2,7 +2,7 @@ module Mindee module Product module Invoice class InvoiceV4LineItem < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def description: -> String def product_code: -> String def quantity: -> Float @@ -11,8 +11,8 @@ module Mindee 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String end diff --git a/sig/mindee/product/invoice/invoice_v4_page.rbs b/sig/mindee/product/invoice/invoice_v4_page.rbs index e40b49f2c..041228d4b 100644 --- a/sig/mindee/product/invoice/invoice_v4_page.rbs +++ b/sig/mindee/product/invoice/invoice_v4_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module Invoice class InvoiceV4Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class InvoiceV4PagePrediction < InvoiceV4Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 c86051e01..e34fb52e6 100644 --- a/sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs +++ b/sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module InvoiceSplitter class InvoiceSplitterV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 ba6329436..890486052 100644 --- a/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs +++ b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module InvoiceSplitter class InvoiceSplitterV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def invoice_page_groups: -> (Product::InvoiceSplitter::InvoiceSplitterV1InvoicePageGroups) def invoice_page_groups_separator: (String) -> String def invoice_page_groups_to_s: -> String diff --git a/sig/mindee/product/invoice_splitter/invoice_splitter_v1_invoice_page_group.rbs b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_invoice_page_group.rbs index 805166b94..5782f3038 100644 --- a/sig/mindee/product/invoice_splitter/invoice_splitter_v1_invoice_page_group.rbs +++ b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_invoice_page_group.rbs @@ -2,10 +2,10 @@ module Mindee module Product module InvoiceSplitter class InvoiceSplitterV1InvoicePageGroup < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def page_indexes: -> Array[Integer] - def printable_values: -> Hash[Symbol | String, untyped] - def table_printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 689753f43..2ed881454 100644 --- a/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs +++ b/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module InvoiceSplitter class InvoiceSplitterV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class InvoiceSplitterV1PagePrediction < InvoiceSplitterV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index d433be3f2..0a6979a95 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 @@ -4,7 +4,7 @@ module Mindee module Product module MultiReceiptsDetector class MultiReceiptsDetectorV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, 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 22e75d251..eafb6b58a 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 @@ -4,7 +4,7 @@ module Mindee module Product module MultiReceiptsDetector class MultiReceiptsDetectorV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def receipts: -> (Array[Parsing::Standard::PositionField]) def to_s: -> String 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 2c677dcd3..949e77e52 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 @@ -4,10 +4,10 @@ module Mindee module Product module MultiReceiptsDetector class MultiReceiptsDetectorV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class MultiReceiptsDetectorV1PagePrediction < MultiReceiptsDetectorV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 index cfd9ef90f..dd062e7ca 100644 --- a/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rbs +++ b/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 5e1797bcc..5e68f62dc 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1AddedSugar < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def daily_value: -> Float def per_100g: -> Float def per_serving: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 892993b9f..5d7d0e157 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1Calorie < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def daily_value: -> Float def per_100g: -> Float def per_serving: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index d42a60af4..64a333512 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1Cholesterol < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def daily_value: -> Float def per_100g: -> Float def per_serving: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index feeb28ed1..4c9d93cb3 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1DietaryFiber < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def daily_value: -> Float def per_100g: -> Float def per_serving: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 7f02aba96..51cdef350 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 @@ -4,7 +4,7 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def added_sugars: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1AddedSugar) def calories: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Calorie) def cholesterol: -> (Product::NutritionFactsLabel::NutritionFactsLabelV1Cholesterol) 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 index 4e6a177d8..4f25611a3 100644 --- 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 @@ -2,14 +2,14 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1Nutrient < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index f0fa02ecb..55cb379c9 100644 --- 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 @@ -4,10 +4,10 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class NutritionFactsLabelV1PagePrediction < NutritionFactsLabelV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index c25e7ab5b..8aa82f0e1 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1Protein < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def daily_value: -> Float def per_100g: -> Float def per_serving: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 7c3bf76ff..313412d7e 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1SaturatedFat < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def daily_value: -> Float def per_100g: -> Float def per_serving: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index e31b5f9c3..62b0671cb 100644 --- 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 @@ -2,10 +2,10 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1ServingSize < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def amount: -> Float def unit: -> String - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 6221b6fbb..04114e225 100644 --- 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 @@ -2,12 +2,12 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1Sodium < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 9ec1a14cc..cfd0aa186 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1TotalCarbohydrate < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def daily_value: -> Float def per_100g: -> Float def per_serving: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 2474c5c83..9e80c01e4 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1TotalFat < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def daily_value: -> Float def per_100g: -> Float def per_serving: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 229535e42..d259e2c16 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1TotalSugar < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def daily_value: -> Float def per_100g: -> Float def per_serving: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 765d8b8c6..52084790b 100644 --- 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 @@ -2,11 +2,11 @@ module Mindee module Product module NutritionFactsLabel class NutritionFactsLabelV1TransFat < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def daily_value: -> Float def per_100g: -> Float def per_serving: -> Float - def printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String end end diff --git a/sig/mindee/product/passport/passport_v1.rbs b/sig/mindee/product/passport/passport_v1.rbs index f548ffc75..e4c84f49a 100644 --- a/sig/mindee/product/passport/passport_v1.rbs +++ b/sig/mindee/product/passport/passport_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module Passport class PassportV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/product/passport/passport_v1_document.rbs b/sig/mindee/product/passport/passport_v1_document.rbs index 6e7fd345a..1f2c6dd18 100644 --- a/sig/mindee/product/passport/passport_v1_document.rbs +++ b/sig/mindee/product/passport/passport_v1_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module Passport class PassportV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def birth_date: -> (Parsing::Standard::DateField) def birth_place: -> (Parsing::Standard::StringField) def country: -> (Parsing::Standard::StringField) diff --git a/sig/mindee/product/passport/passport_v1_page.rbs b/sig/mindee/product/passport/passport_v1_page.rbs index 5dbe3cb38..33d9a2fc8 100644 --- a/sig/mindee/product/passport/passport_v1_page.rbs +++ b/sig/mindee/product/passport/passport_v1_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module Passport class PassportV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class PassportV1PagePrediction < PassportV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/receipt/receipt_v5.rbs b/sig/mindee/product/receipt/receipt_v5.rbs index 58a33fb7a..025be2f62 100644 --- a/sig/mindee/product/receipt/receipt_v5.rbs +++ b/sig/mindee/product/receipt/receipt_v5.rbs @@ -4,7 +4,7 @@ module Mindee module Product module Receipt class ReceiptV5 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/product/receipt/receipt_v5_document.rbs b/sig/mindee/product/receipt/receipt_v5_document.rbs index 901659c10..ffe778796 100644 --- a/sig/mindee/product/receipt/receipt_v5_document.rbs +++ b/sig/mindee/product/receipt/receipt_v5_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module Receipt class ReceiptV5Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def category: -> (Parsing::Standard::ClassificationField) def date: -> (Parsing::Standard::DateField) def document_type: -> (Parsing::Standard::ClassificationField) diff --git a/sig/mindee/product/receipt/receipt_v5_line_item.rbs b/sig/mindee/product/receipt/receipt_v5_line_item.rbs index 48029f4e6..35fdcd097 100644 --- a/sig/mindee/product/receipt/receipt_v5_line_item.rbs +++ b/sig/mindee/product/receipt/receipt_v5_line_item.rbs @@ -2,13 +2,13 @@ module Mindee module Product module Receipt class ReceiptV5LineItem < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String end diff --git a/sig/mindee/product/receipt/receipt_v5_page.rbs b/sig/mindee/product/receipt/receipt_v5_page.rbs index 43f9487f9..92afc1c08 100644 --- a/sig/mindee/product/receipt/receipt_v5_page.rbs +++ b/sig/mindee/product/receipt/receipt_v5_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module Receipt class ReceiptV5Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class ReceiptV5PagePrediction < ReceiptV5Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/resume/resume_v1.rbs b/sig/mindee/product/resume/resume_v1.rbs index b6e3b3969..be7ab1f4a 100644 --- a/sig/mindee/product/resume/resume_v1.rbs +++ b/sig/mindee/product/resume/resume_v1.rbs @@ -4,7 +4,7 @@ module Mindee module Product module Resume class ResumeV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/product/resume/resume_v1_certificate.rbs b/sig/mindee/product/resume/resume_v1_certificate.rbs index 0f6fe453c..4fb5c1b53 100644 --- a/sig/mindee/product/resume/resume_v1_certificate.rbs +++ b/sig/mindee/product/resume/resume_v1_certificate.rbs @@ -2,13 +2,13 @@ module Mindee module Product module Resume class ResumeV1Certificate < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String end diff --git a/sig/mindee/product/resume/resume_v1_document.rbs b/sig/mindee/product/resume/resume_v1_document.rbs index 586f4d086..4b0b83dd2 100644 --- a/sig/mindee/product/resume/resume_v1_document.rbs +++ b/sig/mindee/product/resume/resume_v1_document.rbs @@ -4,7 +4,7 @@ module Mindee module Product module Resume class ResumeV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> (Parsing::Standard::StringField) def certificates: -> (Product::Resume::ResumeV1Certificates) def document_language: -> (Parsing::Standard::StringField) diff --git a/sig/mindee/product/resume/resume_v1_education.rbs b/sig/mindee/product/resume/resume_v1_education.rbs index bf0da62fd..8485ffaf8 100644 --- a/sig/mindee/product/resume/resume_v1_education.rbs +++ b/sig/mindee/product/resume/resume_v1_education.rbs @@ -2,7 +2,7 @@ module Mindee module Product module Resume class ResumeV1Education < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def degree_domain: -> String def degree_type: -> String def end_month: -> String @@ -10,8 +10,8 @@ module Mindee 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String end diff --git a/sig/mindee/product/resume/resume_v1_language.rbs b/sig/mindee/product/resume/resume_v1_language.rbs index efbf4658d..9b721f5b7 100644 --- a/sig/mindee/product/resume/resume_v1_language.rbs +++ b/sig/mindee/product/resume/resume_v1_language.rbs @@ -2,11 +2,11 @@ module Mindee module Product module Resume class ResumeV1Language < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String end diff --git a/sig/mindee/product/resume/resume_v1_page.rbs b/sig/mindee/product/resume/resume_v1_page.rbs index 82138774c..b4a568376 100644 --- a/sig/mindee/product/resume/resume_v1_page.rbs +++ b/sig/mindee/product/resume/resume_v1_page.rbs @@ -4,10 +4,10 @@ module Mindee module Product module Resume class ResumeV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class ResumeV1PagePrediction < ResumeV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/resume/resume_v1_professional_experience.rbs b/sig/mindee/product/resume/resume_v1_professional_experience.rbs index c42140b4e..234096979 100644 --- a/sig/mindee/product/resume/resume_v1_professional_experience.rbs +++ b/sig/mindee/product/resume/resume_v1_professional_experience.rbs @@ -2,7 +2,7 @@ module Mindee module Product module Resume class ResumeV1ProfessionalExperience < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def contract_type: -> String def department: -> String def description: -> String @@ -12,8 +12,8 @@ module Mindee 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index beca1ef28..db2204185 100644 --- a/sig/mindee/product/resume/resume_v1_social_networks_url.rbs +++ b/sig/mindee/product/resume/resume_v1_social_networks_url.rbs @@ -2,11 +2,11 @@ module Mindee module Product module Resume class ResumeV1SocialNetworksUrl < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String end diff --git a/sig/mindee/product/universal/universal_document.rbs b/sig/mindee/product/universal/universal_document.rbs index dfed539b0..a8a1d70fe 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: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/product/universal/universal_page.rbs b/sig/mindee/product/universal/universal_page.rbs index f928c8eb2..b53ebe251 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: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class UniversalPagePrediction < UniversalPrediction - def initialize: (Hash[Symbol | String, untyped], ?nil) -> void + def initialize: (Hash[String | Symbol, 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 176e49048..b3badf94f 100644 --- a/sig/mindee/product/universal/universal_prediction.rbs +++ b/sig/mindee/product/universal/universal_prediction.rbs @@ -3,15 +3,15 @@ module Mindee module Product module Universal class UniversalPrediction < Parsing::Common::Prediction - def fields: -> Hash[Symbol | String, untyped] + def fields: -> Hash[String | Symbol, untyped] def initialize: (untyped?) -> void def to_s: -> String def generate_field_string: (String, Parsing::Universal::UniversalListField, Regexp) -> String - def generate_list_field_string: (String, Hash[Symbol | String, untyped], Regexp) -> String + def generate_list_field_string: (String, Hash[String | Symbol, 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 single_fields: -> Hash[String | Symbol, untyped] + def list_fields: -> Hash[String | Symbol, Parsing::Universal::UniversalListField] + def object_fields: -> Hash[String | Symbol, untyped] def list_field_names: -> Array[untyped] end end diff --git a/sig/mindee/product/us/bank_check/bank_check_v1.rbs b/sig/mindee/product/us/bank_check/bank_check_v1.rbs index 7374d8bb0..6447d243a 100644 --- a/sig/mindee/product/us/bank_check/bank_check_v1.rbs +++ b/sig/mindee/product/us/bank_check/bank_check_v1.rbs @@ -5,7 +5,7 @@ module Mindee module US module BankCheck class BankCheckV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 5729db258..34983c309 100644 --- a/sig/mindee/product/us/bank_check/bank_check_v1_document.rbs +++ b/sig/mindee/product/us/bank_check/bank_check_v1_document.rbs @@ -5,7 +5,7 @@ module Mindee module US module BankCheck class BankCheckV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def account_number: -> (Parsing::Standard::StringField) def amount: -> (Parsing::Standard::AmountField) def check_number: -> (Parsing::Standard::StringField) 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 index baba8e1a0..624527667 100644 --- a/sig/mindee/product/us/bank_check/bank_check_v1_page.rbs +++ b/sig/mindee/product/us/bank_check/bank_check_v1_page.rbs @@ -5,10 +5,10 @@ module Mindee module US module BankCheck class BankCheckV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class BankCheckV1PagePrediction < BankCheckV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def check_position: -> Parsing::Standard::PositionField def signatures_positions: -> Array[Parsing::Standard::PositionField] def to_s: -> String diff --git a/sig/mindee/product/us/healthcare_card/healthcare_card_v1.rbs b/sig/mindee/product/us/healthcare_card/healthcare_card_v1.rbs index 8a1e32842..847b6a612 100644 --- a/sig/mindee/product/us/healthcare_card/healthcare_card_v1.rbs +++ b/sig/mindee/product/us/healthcare_card/healthcare_card_v1.rbs @@ -5,7 +5,7 @@ module Mindee module US module HealthcareCard class HealthcareCardV1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index d6fbe188a..a90161305 100644 --- a/sig/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rbs +++ b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rbs @@ -3,11 +3,11 @@ module Mindee module US module HealthcareCard class HealthcareCardV1Copay < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 c184f881e..6f6ec9b8c 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 @@ -5,7 +5,7 @@ module Mindee module US module HealthcareCard class HealthcareCardV1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def company_name: -> (Parsing::Standard::StringField) def copays: -> (Product::US::HealthcareCard::HealthcareCardV1Copays) def dependents: -> (Array[Parsing::Standard::StringField]) 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 index 50d3ea42c..cf6b9255f 100644 --- a/sig/mindee/product/us/healthcare_card/healthcare_card_v1_page.rbs +++ b/sig/mindee/product/us/healthcare_card/healthcare_card_v1_page.rbs @@ -5,10 +5,10 @@ module Mindee module US module HealthcareCard class HealthcareCardV1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class HealthcareCardV1PagePrediction < HealthcareCardV1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/us/us_mail/us_mail_v2.rbs b/sig/mindee/product/us/us_mail/us_mail_v2.rbs index 5a425db67..7a15ab2e6 100644 --- a/sig/mindee/product/us/us_mail/us_mail_v2.rbs +++ b/sig/mindee/product/us/us_mail/us_mail_v2.rbs @@ -5,7 +5,7 @@ module Mindee module US module UsMail class UsMailV2 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end end end diff --git a/sig/mindee/product/us/us_mail/us_mail_v2_document.rbs b/sig/mindee/product/us/us_mail/us_mail_v2_document.rbs index 4272c1722..9e47d1f1e 100644 --- a/sig/mindee/product/us/us_mail/us_mail_v2_document.rbs +++ b/sig/mindee/product/us/us_mail/us_mail_v2_document.rbs @@ -5,7 +5,7 @@ module Mindee module US module UsMail class UsMailV2Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def recipient_addresses: -> (Product::US::UsMail::UsMailV2RecipientAddresses) def recipient_names: -> (Array[Parsing::Standard::StringField]) def sender_address: -> (Product::US::UsMail::UsMailV2SenderAddress) diff --git a/sig/mindee/product/us/us_mail/us_mail_v2_page.rbs b/sig/mindee/product/us/us_mail/us_mail_v2_page.rbs index 90dcc4ca2..03e6f9884 100644 --- a/sig/mindee/product/us/us_mail/us_mail_v2_page.rbs +++ b/sig/mindee/product/us/us_mail/us_mail_v2_page.rbs @@ -5,10 +5,10 @@ module Mindee module US module UsMail class UsMailV2Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class UsMailV2PagePrediction < UsMailV2Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/us/us_mail/us_mail_v2_recipient_address.rbs b/sig/mindee/product/us/us_mail/us_mail_v2_recipient_address.rbs index ea801f6a2..03885a4ec 100644 --- a/sig/mindee/product/us/us_mail/us_mail_v2_recipient_address.rbs +++ b/sig/mindee/product/us/us_mail/us_mail_v2_recipient_address.rbs @@ -3,7 +3,7 @@ module Mindee module US module UsMail class UsMailV2RecipientAddress < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def city: -> String def complete: -> String def is_address_change: -> bool @@ -11,8 +11,8 @@ module Mindee def private_mailbox_number: -> String def state: -> String def street: -> String - def printable_values: -> Hash[Symbol | String, untyped] - def table_printable_values: -> Hash[Symbol | String, untyped] + def printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String end diff --git a/sig/mindee/product/us/us_mail/us_mail_v2_sender_address.rbs b/sig/mindee/product/us/us_mail/us_mail_v2_sender_address.rbs index ac8d97e0f..b6c4958fc 100644 --- a/sig/mindee/product/us/us_mail/us_mail_v2_sender_address.rbs +++ b/sig/mindee/product/us/us_mail/us_mail_v2_sender_address.rbs @@ -3,13 +3,13 @@ module Mindee module US module UsMail class UsMailV2SenderAddress < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String 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 index 9cb95c954..67efde76d 100644 --- a/sig/mindee/product/us/us_mail/us_mail_v3.rbs +++ b/sig/mindee/product/us/us_mail/us_mail_v3.rbs @@ -5,7 +5,7 @@ module Mindee module US module UsMail class UsMailV3 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index e3d271712..20b351207 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 @@ -5,7 +5,7 @@ module Mindee module US module UsMail class UsMailV3Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def is_return_to_sender: -> (Parsing::Standard::BooleanField) def recipient_addresses: -> (Product::US::UsMail::UsMailV3RecipientAddresses) def recipient_names: -> (Array[Parsing::Standard::StringField]) 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 index 78581df80..279eaa147 100644 --- a/sig/mindee/product/us/us_mail/us_mail_v3_page.rbs +++ b/sig/mindee/product/us/us_mail/us_mail_v3_page.rbs @@ -5,10 +5,10 @@ module Mindee module US module UsMail class UsMailV3Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class UsMailV3PagePrediction < UsMailV3Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String 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 index 88846fed8..b10006886 100644 --- 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 @@ -3,7 +3,7 @@ module Mindee module US module UsMail class UsMailV3RecipientAddress < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def city: -> String def complete: -> String def is_address_change: -> bool @@ -12,8 +12,8 @@ module Mindee 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 printable_values: -> Hash[String | Symbol, untyped] + def table_printable_values: -> Hash[String | Symbol, untyped] def to_table_line: -> String def to_s: -> String 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 index e70c60c4b..2928e024e 100644 --- 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 @@ -3,13 +3,13 @@ module Mindee module US module UsMail class UsMailV3SenderAddress < Parsing::Standard::FeatureField - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, 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 printable_values: -> Hash[String | Symbol, untyped] def to_s: -> String end end diff --git a/sig/mindee/product/us/w9/w9_v1.rbs b/sig/mindee/product/us/w9/w9_v1.rbs index e70c580bc..a7e8bd007 100644 --- a/sig/mindee/product/us/w9/w9_v1.rbs +++ b/sig/mindee/product/us/w9/w9_v1.rbs @@ -5,7 +5,7 @@ module Mindee module US module W9 class W9V1 < Parsing::Common::Inference - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void 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 index 73c197331..67fd37879 100644 --- a/sig/mindee/product/us/w9/w9_v1_document.rbs +++ b/sig/mindee/product/us/w9/w9_v1_document.rbs @@ -5,7 +5,7 @@ module Mindee module US module W9 class W9V1Document < Parsing::Common::Prediction - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def to_s: -> String end end diff --git a/sig/mindee/product/us/w9/w9_v1_page.rbs b/sig/mindee/product/us/w9/w9_v1_page.rbs index b007d99d2..1c49ec761 100644 --- a/sig/mindee/product/us/w9/w9_v1_page.rbs +++ b/sig/mindee/product/us/w9/w9_v1_page.rbs @@ -5,10 +5,10 @@ module Mindee module US module W9 class W9V1Page < Parsing::Common::Page - def initialize: (Hash[Symbol | String, untyped]) -> void + def initialize: (Hash[String | Symbol, untyped]) -> void end class W9V1PagePrediction < W9V1Document - def initialize: (Hash[Symbol | String, untyped], Integer?) -> void + def initialize: (Hash[String | Symbol, untyped], Integer?) -> void def address: -> Parsing::Standard::StringField def business_name: -> Parsing::Standard::StringField def city_state_zip: -> Parsing::Standard::StringField diff --git a/sig/mindee/version.rbs b/sig/mindee/version.rbs index cf67f15db..3ecc31574 100644 --- a/sig/mindee/version.rbs +++ b/sig/mindee/version.rbs @@ -1,6 +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) + def self.find_platform: -> (Symbol | Hash[String | Symbol, Regexp])? + PLATFORM: (Hash[String | Symbol, Regexp] | Symbol) end From 8f8641dfe7d4f1505f48478ba9a8d30679527040 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Mon, 11 Aug 2025 15:34:15 +0200 Subject: [PATCH 13/19] remove invalid old Origami signature --- sig/mindee/image/image_compressor.rbs | 2 +- sig/mindee/image/image_utils.rbs | 18 +++++++++--------- sig/mindee/pdf/pdf_tools.rbs | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sig/mindee/image/image_compressor.rbs b/sig/mindee/image/image_compressor.rbs index c3b7a5829..1129a0fcd 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: (singleton(MiniMagick::Image) | MiniMagick::Image | StringIO | File, ?quality: Integer | Float | nil, ?max_width: Integer | Float | nil, ?max_height: Integer | Float | nil) -> StringIO + def self.compress_image: (MiniMagick::Image | StringIO | File, ?quality: Integer | Float | nil, ?max_width: Integer | Float | nil, ?max_height: Integer | Float | nil) -> StringIO end end end diff --git a/sig/mindee/image/image_utils.rbs b/sig/mindee/image/image_utils.rbs index 955371a07..d4d853d5c 100644 --- a/sig/mindee/image/image_utils.rbs +++ b/sig/mindee/image/image_utils.rbs @@ -2,17 +2,17 @@ module Mindee module Image module ImageUtils - def self.resize_image: (singleton(MiniMagick::Image) | MiniMagick::Image, Integer, Integer) -> void - def self.compress_image_quality: (singleton(MiniMagick::Image) | MiniMagick::Image, untyped) -> void - 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.resize_image: (MiniMagick::Image, Integer, Integer) -> void + def self.compress_image_quality: (MiniMagick::Image, untyped) -> void + def self.to_image: (MiniMagick::Image | StringIO | IO | File | Tempfile?) -> (MiniMagick::Image) + def self.image_to_stringio: (MiniMagick::Image, ?String) -> StringIO + def self.calculate_new_dimensions: (MiniMagick::Image, ?max_width: Integer | Float?, ?max_height: Integer | Float?) -> [Integer, Integer] + def self.calculate_dimensions_from_media_box: (MiniMagick::Image, Array[Integer]?) -> [Integer, Integer] def self.pdf_to_magick_image: (StringIO | File, Integer) -> MiniMagick::Image def self.normalize_polygon: (Geometry::Quadrilateral | Geometry::Polygon | Array[Geometry::Point]) -> Geometry::Quadrilateral - def self.read_page_content: (StringIO | File) -> (singleton(MiniMagick::Image) | MiniMagick::Image) - def self.crop_image: (singleton(MiniMagick::Image) | MiniMagick::Image, Geometry::MinMax, Geometry::MinMax) -> (singleton(MiniMagick::Image) | MiniMagick::Image) - def self.write_image_to_buffer: (singleton(MiniMagick::Image) | MiniMagick::Image, StringIO) -> void + def self.read_page_content: (StringIO | File) -> (MiniMagick::Image) + def self.crop_image: (MiniMagick::Image, Geometry::MinMax, Geometry::MinMax) -> (MiniMagick::Image) + def self.write_image_to_buffer: (MiniMagick::Image, StringIO) -> void def self.determine_file_extension: (Input::Source::LocalInputSource) -> String? end end diff --git a/sig/mindee/pdf/pdf_tools.rbs b/sig/mindee/pdf/pdf_tools.rbs index 769c94239..dc8ae8e9d 100644 --- a/sig/mindee/pdf/pdf_tools.rbs +++ b/sig/mindee/pdf/pdf_tools.rbs @@ -17,13 +17,13 @@ module Mindee def load_all_objects: () -> void def self.stream_has_text?: (Origami::Stream) -> bool def self.source_text?: (StringIO | File) -> bool - def self.create_xobject: (singleton(MiniMagick::Image) | MiniMagick::Image) -> Origami::Graphics::ImageXObject - def self.set_xobject_properties: (Origami::Graphics::ImageXObject, singleton(MiniMagick::Image) | MiniMagick::Image) -> void - def self.determine_filter: (singleton(MiniMagick::Image) | MiniMagick::Image) -> (:DCTDecode | :FlateDecode | :LZWDecode) - def self.determine_colorspace: (singleton(MiniMagick::Image) | MiniMagick::Image) -> (:DeviceCMYK | :DeviceGray | :DeviceRGB) + def self.create_xobject: (MiniMagick::Image) -> Origami::Graphics::ImageXObject + def self.set_xobject_properties: (Origami::Graphics::ImageXObject, MiniMagick::Image) -> void + def self.determine_filter: (MiniMagick::Image) -> (:DCTDecode | :FlateDecode | :LZWDecode) + def self.determine_colorspace: (MiniMagick::Image) -> (:DeviceCMYK | :DeviceGray | :DeviceRGB) def self.add_content_to_page: (Origami::Page, String, Integer, Integer) -> void def self.set_page_dimensions: (Origami::Page, Integer | Float, Integer | Float) -> void - def self.process_image_xobject: (singleton(MiniMagick::Image) | MiniMagick::Image | StringIO, Integer, Integer | Float, Integer | Float) -> Origami::Graphics::ImageXObject + def self.process_image_xobject: (MiniMagick::Image | StringIO, Integer, Integer | Float, Integer | Float) -> Origami::Graphics::ImageXObject end end end From 865acdb2744dcf1123c47cddb62384cb5e34b603 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Mon, 11 Aug 2025 15:36:24 +0200 Subject: [PATCH 14/19] simplify nil typing --- sig/custom/origami.rbs | 2 +- sig/mindee/client.rbs | 2 +- sig/mindee/http/endpoint.rbs | 4 ++-- sig/mindee/image/image_compressor.rbs | 2 +- sig/mindee/parsing/universal/universal_object_field.rbs | 8 ++++---- sig/mindee/parsing/v2/field/inference_fields.rbs | 6 +++--- sig/mindee/parsing/v2/field/object_field.rbs | 2 +- sig/mindee/parsing/v2/field/simple_field.rbs | 2 +- sig/mindee/parsing/v2/job.rbs | 6 +++--- sig/mindee/parsing/v2/job_webhook.rbs | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sig/custom/origami.rbs b/sig/custom/origami.rbs index 070fbf74d..f203f39bb 100644 --- a/sig/custom/origami.rbs +++ b/sig/custom/origami.rbs @@ -16,7 +16,7 @@ module Origami class LinearParser def initialize: (Hash[Symbol, untyped]) -> void def new: (Hash[Symbol, untyped]) -> void - def parse: (StringIO | File | nil) -> PDF + def parse: (StringIO | File?) -> PDF end end diff --git a/sig/mindee/client.rbs b/sig/mindee/client.rbs index 6c4dcd5c8..f4311337b 100644 --- a/sig/mindee/client.rbs +++ b/sig/mindee/client.rbs @@ -10,7 +10,7 @@ module Mindee attr_accessor page_options: PageOptions attr_accessor cropper: bool attr_accessor rag: bool - attr_accessor workflow_id: String | nil + attr_accessor workflow_id: String? attr_accessor initial_delay_sec: Integer | Float attr_accessor delay_sec: Integer | Float attr_accessor max_retries: Integer diff --git a/sig/mindee/http/endpoint.rbs b/sig/mindee/http/endpoint.rbs index 24adca087..960b59cdf 100644 --- a/sig/mindee/http/endpoint.rbs +++ b/sig/mindee/http/endpoint.rbs @@ -2,7 +2,7 @@ module Mindee module HTTP API_KEY_ENV_NAME: String - API_KEY_DEFAULT: String | nil + API_KEY_DEFAULT: String? BASE_URL_ENV_NAME: String BASE_URL_DEFAULT: String REQUEST_TIMEOUT_ENV_NAME: String @@ -15,7 +15,7 @@ module Mindee attr_reader url_root: String def logger: () -> Logger - def initialize: (String, String, String | nil, ?api_key: String) -> String + def initialize: (String, String, String?, ?api_key: String) -> String def predict: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Hash[String | Symbol, untyped], String] def predict_async: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> [Hash[String | Symbol, untyped], String] def parse_async: (String) -> [Hash[String | Symbol, untyped], String] diff --git a/sig/mindee/image/image_compressor.rbs b/sig/mindee/image/image_compressor.rbs index 1129a0fcd..d40e4078e 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: (MiniMagick::Image | StringIO | File, ?quality: Integer | Float | nil, ?max_width: Integer | Float | nil, ?max_height: Integer | Float | nil) -> StringIO + def self.compress_image: (MiniMagick::Image | StringIO | File, ?quality: Integer | Float?, ?max_width: Integer | Float?, ?max_height: Integer | Float?) -> StringIO end end end diff --git a/sig/mindee/parsing/universal/universal_object_field.rbs b/sig/mindee/parsing/universal/universal_object_field.rbs index 1be4d90e2..54f641d41 100644 --- a/sig/mindee/parsing/universal/universal_object_field.rbs +++ b/sig/mindee/parsing/universal/universal_object_field.rbs @@ -3,7 +3,7 @@ module Mindee module Parsing module Universal class UniversalObjectField - attr_reader all_values: Hash[String | Symbol, String | Standard::PositionField | nil] + attr_reader all_values: Hash[String | Symbol, String | Standard::PositionField?] attr_reader confidence: Float attr_reader page_id: Integer attr_reader raw_value: String @@ -17,11 +17,11 @@ module Mindee | bool | Standard::PositionField | Hash[String | Symbol, untyped] - | nil) + ?) def respond_to_missing?: (Symbol, ?bool) -> bool def to_s: -> String - def handle_position_field: (String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil, Integer?) -> void - def handle_default_field: (String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool | nil) -> void + def handle_position_field: (String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool?, Integer?) -> void + def handle_default_field: (String | Symbol, Hash[String | Symbol, untyped] | Integer | String | Float | bool?) -> void end def self.universal_object?: (Hash[String | Symbol, untyped]) -> bool end diff --git a/sig/mindee/parsing/v2/field/inference_fields.rbs b/sig/mindee/parsing/v2/field/inference_fields.rbs index ec936eda0..1774a5b11 100644 --- a/sig/mindee/parsing/v2/field/inference_fields.rbs +++ b/sig/mindee/parsing/v2/field/inference_fields.rbs @@ -3,13 +3,13 @@ module Mindee module Parsing module V2 module Field - class InferenceFields < Hash[String, ListField | ObjectField | SimpleField | nil] + class InferenceFields < Hash[String, ListField | ObjectField | SimpleField?] attr_reader indent_level: Integer def logger: () -> Logger def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void - def get: (String) -> (ListField | ObjectField | SimpleField | nil) - def method_missing: (Symbol, *untyped) -> (ListField | ObjectField | SimpleField | nil) + def get: (String) -> (ListField | ObjectField | SimpleField?) + def method_missing: (Symbol, *untyped) -> (ListField | ObjectField | SimpleField?) def respond_to_missing?: (Symbol, ?bool) -> bool def to_s: (?Integer) -> String end diff --git a/sig/mindee/parsing/v2/field/object_field.rbs b/sig/mindee/parsing/v2/field/object_field.rbs index 52c159ea4..ab1d84529 100644 --- a/sig/mindee/parsing/v2/field/object_field.rbs +++ b/sig/mindee/parsing/v2/field/object_field.rbs @@ -13,7 +13,7 @@ module Mindee def single_str: -> String def to_s: -> String def to_s_from_list: -> String - def method_missing: (Symbol, *untyped, untyped) -> (ObjectField | nil) + def method_missing: (Symbol, *untyped, untyped) -> (ObjectField?) end end end diff --git a/sig/mindee/parsing/v2/field/simple_field.rbs b/sig/mindee/parsing/v2/field/simple_field.rbs index facf0b121..c5ac46a7b 100644 --- a/sig/mindee/parsing/v2/field/simple_field.rbs +++ b/sig/mindee/parsing/v2/field/simple_field.rbs @@ -4,7 +4,7 @@ module Mindee module V2 module Field class SimpleField < BaseField - attr_reader value: String | Integer | Float | bool | nil + attr_reader value: String | Integer | Float | bool? def initialize: (Hash[String | Symbol, untyped], ?Integer) -> void def to_s: -> String diff --git a/sig/mindee/parsing/v2/job.rbs b/sig/mindee/parsing/v2/job.rbs index 2a211e89f..7f4afbe00 100644 --- a/sig/mindee/parsing/v2/job.rbs +++ b/sig/mindee/parsing/v2/job.rbs @@ -4,13 +4,13 @@ module Mindee module V2 class Job attr_reader alias: String - attr_reader created_at: DateTime | nil - attr_reader error: ErrorResponse | nil + attr_reader created_at: DateTime? + attr_reader error: ErrorResponse? attr_reader filename: String attr_reader id: String attr_reader model_id: String attr_reader polling_url: String - attr_reader result_url: String | nil + attr_reader result_url: String? attr_reader status: String attr_reader webhooks: Array[JobWebhook] diff --git a/sig/mindee/parsing/v2/job_webhook.rbs b/sig/mindee/parsing/v2/job_webhook.rbs index 452dab2ff..e2869ad98 100644 --- a/sig/mindee/parsing/v2/job_webhook.rbs +++ b/sig/mindee/parsing/v2/job_webhook.rbs @@ -3,7 +3,7 @@ module Mindee module Parsing module V2 class JobWebhook - attr_reader created_at: DateTime | nil + attr_reader created_at: DateTime? attr_reader error: ErrorResponse attr_reader id: String attr_reader status: String From 776cc3afd0728606232788d26ac445d0f3f37f40 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Mon, 11 Aug 2025 15:42:28 +0200 Subject: [PATCH 15/19] fix one typo --- sig/mindee/input/sources/local_input_source.rbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sig/mindee/input/sources/local_input_source.rbs b/sig/mindee/input/sources/local_input_source.rbs index d70a2c9c5..c51e9553b 100644 --- a/sig/mindee/input/sources/local_input_source.rbs +++ b/sig/mindee/input/sources/local_input_source.rbs @@ -6,12 +6,12 @@ module Mindee class LocalInputSource attr_reader file_mimetype: String attr_reader filename: String - attr_reader io_stream: StringIO|File + attr_reader io_stream: StringIO | File def initialize: (StringIO | File, String, ?repair_pdf: bool) -> void def logger: () -> Logger - def rescue_broken_pdf: (StringIO|File) -> (StringIO | File) + def rescue_broken_pdf: (StringIO | File) -> (StringIO | File) def pdf?: -> bool def apply_page_options: (PageOptions) -> StringIO? def process_pdf: (PageOptions) -> StringIO? From 25d8745f1f8faa9761e484d8236e796d7ef38e18 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Mon, 11 Aug 2025 16:09:35 +0200 Subject: [PATCH 16/19] add integration test + fix lingering issues --- lib/mindee/input/inference_parameters.rb | 2 +- spec/client_v2_integration.rb | 105 +++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 spec/client_v2_integration.rb diff --git a/lib/mindee/input/inference_parameters.rb b/lib/mindee/input/inference_parameters.rb index 55d1c6e18..069e3a2d0 100644 --- a/lib/mindee/input/inference_parameters.rb +++ b/lib/mindee/input/inference_parameters.rb @@ -24,7 +24,7 @@ class InferenceParameters # @param params [Hash] def initialize(params: {}) - params = params.transform_keys(&:to_sym) + params.transform_keys!(&:to_sym) if params.empty? || params[:model_id].nil? || params[:model_id].empty? raise Errors::MindeeInputError, 'Model ID is required.' diff --git a/spec/client_v2_integration.rb b/spec/client_v2_integration.rb new file mode 100644 index 000000000..4653ea0ba --- /dev/null +++ b/spec/client_v2_integration.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +RSpec.describe 'Mindee::ClientV2 – integration tests (V2)', :integration, order: :defined do + let(:api_key) { ENV.fetch('MINDEE_V2_API_KEY') } + let(:model_id) { ENV.fetch('MINDEE_V2_FINDOC_MODEL_ID') } + let(:blank_pdf_url) { ENV.fetch('MINDEE_V2_SE_TESTS_BLANK_PDF_URL') } + + let(:client) { Mindee::ClientV2.new(api_key: api_key) } + + it 'parses an empty multi-page PDF successfully' do + src_path = File.join(__dir__ || './', 'data', 'file_types', 'pdf', 'multipage_cut-2.pdf') + input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'multipage_cut-2.pdf') + + polling = Mindee::Input::PollingOptions.new( + initial_delay_sec: 3.0, + delay_sec: 1.5, + max_retries: 80 + ) + + params = Mindee::Input::InferenceParameters.new(params: { + model_id: model_id, + rag: false, + alias: 'ruby-integration-test', + polling_options: polling, + }) + + resp = client.enqueue_and_get_inference(input, params) + + expect(resp).not_to be_nil + expect(resp.inference).not_to be_nil + + expect(resp.inference.file).not_to be_nil + expect(resp.inference.file.name).to eq('multipage_cut-2.pdf') + + expect(resp.inference.model).not_to be_nil + expect(resp.inference.model.id).to eq(model_id) + + expect(resp.inference.result).not_to be_nil + expect(resp.inference.result.options).to be_nil + end + + it 'parses a filled single-page image successfully' do + src_path = File.join(__dir__ || './', 'data', 'products', 'financial_document', 'default_sample.jpg') + input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'default_sample.jpg') + + params = Mindee::Input::InferenceParameters.new(params: { + model_id: model_id, + rag: false, + alias: 'ruby-integration-test', + }) + + resp = client.enqueue_and_get_inference(input, params) + + expect(resp).not_to be_nil + expect(resp.inference.file.name).to eq('default_sample.jpg') + expect(resp.inference.model.id).to eq(model_id) + + fields = resp.inference.result.fields + expect(fields).not_to be_nil + expect(fields['supplier_name']).not_to be_nil + expect(fields['supplier_name'].value).to eq('John Smith') + end + + it 'raises MindeeHTTPErrorV2 (422) on invalid model id' do + src_path = File.join(__dir__ || './', 'data', 'file_types', 'pdf', 'blank_1.pdf') + input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'blank_1.pdf') + + params = Mindee::Input::InferenceParameters.new(params: { model_id: 'INVALID_MODEL_ID' }) + + expect do + client.enqueue_inference(input, params) + end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(422) } + end + + it 'raises MindeeHTTPErrorV2 (422) on invalid webhook id' do + src_path = File.join(__dir__ || './', 'data', 'file_types', 'pdf', 'blank_1.pdf') + input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'blank_1.pdf') + + params = Mindee::Input::InferenceParameters.new(params: { + model_id: model_id, + webhook_ids: ['INVALID_WEBHOOK_ID'], + }) + + expect do + client.enqueue_inference(input, params) + end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(422) } + end + + it 'raises MindeeHTTPErrorV2 on invalid job id' do + expect do + client.get_inference('INVALID_JOB_ID') + end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(422) } + end + + it 'parses an URL input source without errors' do + url_input = Mindee::Input::Source::URLInputSource.new(blank_pdf_url) + + params = Mindee::Input::InferenceParameters.new(params: { model_id: model_id }) + + resp = client.enqueue_and_get_inference(url_input, params) + + expect(resp).not_to be_nil + expect(resp.inference).not_to be_nil + end +end From 1237236b7dff4b67cefcefbfea00547816d37d2e Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 12 Aug 2025 17:30:36 +0200 Subject: [PATCH 17/19] simplify inference parameters syntax --- docs/code_samples/default_v2.txt | 10 ++- lib/mindee/client_v2.rb | 2 +- lib/mindee/input/inference_parameters.rb | 85 +++++++++++++++++------ sig/mindee/input/inference_parameters.rbs | 15 +++- 4 files changed, 81 insertions(+), 31 deletions(-) diff --git a/docs/code_samples/default_v2.txt b/docs/code_samples/default_v2.txt index 73dfcc3d9..d9471ecb7 100644 --- a/docs/code_samples/default_v2.txt +++ b/docs/code_samples/default_v2.txt @@ -9,12 +9,10 @@ mindee_client = Mindee::ClientV2.new(api_key: api_key) # Set inference parameters params = Mindee::Input::InferenceParameters.new( - params: { - # ID of the model, required. - model_id: model_id, - # If set to `True`, will enable Retrieval-Augmented Generation. - rag: false, - } + # ID of the model, required. + model_id, + # If set to `True`, will enable Retrieval-Augmented Generation. + rag: false, ) # Load a file from disk diff --git a/lib/mindee/client_v2.rb b/lib/mindee/client_v2.rb index de751b2ef..4736c489f 100644 --- a/lib/mindee/client_v2.rb +++ b/lib/mindee/client_v2.rb @@ -106,7 +106,7 @@ def enqueue_and_get_inference(input_source, params) def normalize_inference_parameters(params) return params if params.is_a?(Input::InferenceParameters) - Input::InferenceParameters.new(params: params) + Input::InferenceParameters.from_hash(params: params) end end end diff --git a/lib/mindee/input/inference_parameters.rb b/lib/mindee/input/inference_parameters.rb index 069e3a2d0..f83f73046 100644 --- a/lib/mindee/input/inference_parameters.rb +++ b/lib/mindee/input/inference_parameters.rb @@ -13,7 +13,7 @@ class InferenceParameters # @return [String, nil] Optional alias for the file. attr_reader :file_alias - # @return [Array, nil] Optional list of webhooks IDs to propagate the API response to. + # @return [Array, nil] Optional list of Webhooks IDs to propagate the API response to. attr_reader :webhook_ids # @return [PollingOptions] Options for polling. Set only if having timeout issues. @@ -22,29 +22,21 @@ class InferenceParameters # @return [Boolean, nil] Whether to close the file after parsing. attr_reader :close_file - # @param params [Hash] - def initialize(params: {}) - params.transform_keys!(&:to_sym) - - if params.empty? || params[:model_id].nil? || params[:model_id].empty? - raise Errors::MindeeInputError, 'Model ID is required.' - end + # @param [String] model_id ID of the model + # @param [FalseClass] rag Whether to enable rag. + # @param [nil] file_alias File alias, if applicable. + # @param [nil] webhook_ids + # @param [nil] polling_options + # @param [TrueClass] close_file + def initialize(model_id, rag: false, file_alias: nil, webhook_ids: nil, polling_options: nil, close_file: true) + raise Errors::MindeeInputError, 'Model ID is required.' if model_id.empty? || model_id.nil? - @model_id = params.fetch(:model_id) - @rag = params.fetch(:rag, false) - @file_alias = params.fetch(:file_alias, nil) - @webhook_ids = params.fetch(:webhook_ids, []) - polling_options = params.fetch(:page_options, PollingOptions.new) - if polling_options.is_a?(Hash) - polling_options = polling_options.transform_keys(&:to_sym) - @polling_options = PollingOptions.new( - initial_delay_sec: polling_options.fetch(:initial_delay_sec, 2.0), - delay_sec: polling_options.fetch(:delay_sec, 1.5), - max_retries: polling_options.fetch(:max_retries, 80) - ) - end - @polling_options = polling_options - @close_file = params.fetch(:close_file, true) + @model_id = model_id + @rag = rag || false + @file_alias = file_alias + @webhook_ids = webhook_ids || [] + @polling_options = get_clean_polling_options(polling_options) + @close_file = close_file.nil? || close_file end # Validates the parameters for async auto-polling @@ -66,6 +58,53 @@ def validate_async_params raise ArgumentError, "Cannot set auto-poll retries to less than #{min_retries}" end + + def self.from_hash(params: {}) + params.transform_keys!(&:to_sym) + + if params.empty? || params[:model_id].nil? || params[:model_id].empty? + raise Errors::MindeeInputError, 'Model ID is required.' + end + + model_id = params.fetch(:model_id) + rag = params.fetch(:rag, false) + file_alias = params.fetch(:file_alias, nil) + webhook_ids = params.fetch(:webhook_ids, []) + polling_options_input = params.fetch(:page_options, PollingOptions.new) + if polling_options_input.is_a?(Hash) + polling_options_input = polling_options_input.transform_keys(&:to_sym) + PollingOptions.new( + initial_delay_sec: polling_options_input.fetch(:initial_delay_sec, 2.0), + delay_sec: polling_options_input.fetch(:delay_sec, 1.5), + max_retries: polling_options_input.fetch(:max_retries, 80) + ) + end + close_file = params.fetch(:close_file, true) + InferenceParameters.new(model_id, rag: rag, file_alias: file_alias, webhook_ids: webhook_ids, + close_file: close_file) + end + + private + + def get_clean_polling_options(polling_options) + return PollingOptions.new if polling_options.is_a?(PollingOptions) + + if polling_options.is_a?(Hash) + polling_options = polling_options.transform_keys(&:to_sym) + output_polling_options = PollingOptions.new( + initial_delay_sec: polling_options.fetch(:initial_delay_sec, 2.0), + delay_sec: polling_options.fetch(:delay_sec, 1.5), + max_retries: polling_options.fetch(:max_retries, 80) + ) + else + output_polling_options = if polling_options.is_a?(PollingOptions) + polling_options || PollingOptions.new + else + PollingOptions.new + end + end + output_polling_options + end end end end diff --git a/sig/mindee/input/inference_parameters.rbs b/sig/mindee/input/inference_parameters.rbs index 7b166b79a..84ae52012 100644 --- a/sig/mindee/input/inference_parameters.rbs +++ b/sig/mindee/input/inference_parameters.rbs @@ -9,9 +9,22 @@ module Mindee attr_reader rag: bool? attr_reader webhook_ids: Array[String]? - def initialize: (params: Hash[String | Symbol, untyped]) -> void + def initialize: ( + String, + ?rag: bool?, + ?file_alias: String?, + ?webhook_ids: Array[String]?, + ?polling_options: Hash[Symbol | String, untyped] | PollingOptions?, + ?close_file: bool? + ) -> void + + def self.from_hash: (params: Hash[String | Symbol, untyped]) -> InferenceParameters def validate_async_params: -> void + + private + + def get_clean_polling_options: (Hash[String | Symbol, untyped] | PollingOptions?) -> PollingOptions end end end From b4495b49ff1ca18b494d99f52b3ccc4e9fc76464 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 12 Aug 2025 17:56:55 +0200 Subject: [PATCH 18/19] fix integration tests --- spec/client_v2_integration.rb | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/spec/client_v2_integration.rb b/spec/client_v2_integration.rb index 4653ea0ba..33846bcfd 100644 --- a/spec/client_v2_integration.rb +++ b/spec/client_v2_integration.rb @@ -17,12 +17,10 @@ max_retries: 80 ) - params = Mindee::Input::InferenceParameters.new(params: { - model_id: model_id, - rag: false, - alias: 'ruby-integration-test', - polling_options: polling, - }) + params = Mindee::Input::InferenceParameters.new(model_id, + rag: false, + file_alias: 'ruby-integration-test', + polling_options: polling) resp = client.enqueue_and_get_inference(input, params) @@ -43,11 +41,9 @@ src_path = File.join(__dir__ || './', 'data', 'products', 'financial_document', 'default_sample.jpg') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'default_sample.jpg') - params = Mindee::Input::InferenceParameters.new(params: { - model_id: model_id, - rag: false, - alias: 'ruby-integration-test', - }) + params = Mindee::Input::InferenceParameters.new(model_id, + rag: false, + file_alias: 'ruby-integration-test') resp = client.enqueue_and_get_inference(input, params) @@ -65,7 +61,7 @@ src_path = File.join(__dir__ || './', 'data', 'file_types', 'pdf', 'blank_1.pdf') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'blank_1.pdf') - params = Mindee::Input::InferenceParameters.new(params: { model_id: 'INVALID_MODEL_ID' }) + params = Mindee::Input::InferenceParameters.new('INVALID_MODEL_ID') expect do client.enqueue_inference(input, params) @@ -76,10 +72,8 @@ src_path = File.join(__dir__ || './', 'data', 'file_types', 'pdf', 'blank_1.pdf') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'blank_1.pdf') - params = Mindee::Input::InferenceParameters.new(params: { - model_id: model_id, - webhook_ids: ['INVALID_WEBHOOK_ID'], - }) + params = Mindee::Input::InferenceParameters.new(model_id, + webhook_ids: ['INVALID_WEBHOOK_ID']) expect do client.enqueue_inference(input, params) @@ -95,7 +89,7 @@ it 'parses an URL input source without errors' do url_input = Mindee::Input::Source::URLInputSource.new(blank_pdf_url) - params = Mindee::Input::InferenceParameters.new(params: { model_id: model_id }) + params = Mindee::Input::InferenceParameters.new(model_id) resp = client.enqueue_and_get_inference(url_input, params) From cbe64b0ac5e5af1300b7994f3a390295e025a368 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Wed, 13 Aug 2025 11:21:14 +0200 Subject: [PATCH 19/19] fix typos & lingering issues --- docs/code_samples/default_v2.txt | 3 ++- lib/mindee/client_v2.rb | 9 +++------ lib/mindee/input/inference_parameters.rb | 6 ++++++ lib/mindee/page_options.rb | 1 - lib/mindee/parsing/common/api_response.rb | 4 ++++ lib/mindee/parsing/common/ocr/ocr.rb | 2 +- lib/mindee/parsing/v2/common_response.rb | 2 +- lib/mindee/parsing/v2/error_response.rb | 2 +- lib/mindee/parsing/v2/field/list_field.rb | 5 +---- lib/mindee/parsing/v2/field/simple_field.rb | 4 +--- lib/mindee/parsing/v2/inference.rb | 8 ++------ lib/mindee/parsing/v2/inference_file.rb | 2 +- lib/mindee/parsing/v2/inference_response.rb | 3 +-- lib/mindee/parsing/v2/inference_result.rb | 3 +-- lib/mindee/parsing/v2/job.rb | 3 +-- lib/mindee/parsing/v2/job_response.rb | 3 +-- sig/custom/mini_magick.rbs | 2 +- sig/mindee/parsing/v2/field/object_field.rbs | 2 +- 18 files changed, 29 insertions(+), 35 deletions(-) diff --git a/docs/code_samples/default_v2.txt b/docs/code_samples/default_v2.txt index d9471ecb7..b5cd31515 100644 --- a/docs/code_samples/default_v2.txt +++ b/docs/code_samples/default_v2.txt @@ -20,7 +20,8 @@ input_source = Mindee::Input::Source::PathInputSource.new(input_path) # Send for processing response = mindee_client.enqueue_and_get_inference( - input_source, params + input_source, + params # Note: this parameter can also be provided as a Hash. ) # Print a brief summary of the parsed data diff --git a/lib/mindee/client_v2.rb b/lib/mindee/client_v2.rb index 4736c489f..f70be6a40 100644 --- a/lib/mindee/client_v2.rb +++ b/lib/mindee/client_v2.rb @@ -9,8 +9,7 @@ require_relative 'logging' module Mindee - # Mindee API Client. - # See: https://developers.mindee.com/docs + # Mindee V2 API Client. class ClientV2 # @return [HTTP::MindeeApiV2] private attr_reader :mindee_api @@ -34,8 +33,7 @@ def get_job(job_id) @mindee_api.req_get_job(job_id) end - # Enqueue a document for async parsing - # + # Enqueue a document for async parsing. # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # The source of the input document (local file or URL). # @param params [Hash, InferenceParameters] @@ -47,8 +45,7 @@ def enqueue_inference(input_source, params) @mindee_api.req_post_inference_enqueue(input_source, normalized_params) end - # Enqueue a document for async parsing and automatically try to retrieve it - # + # Enqueue a document for async parsing and automatically try to retrieve it. # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # The source of the input document (local file or URL). # @param params [Hash, InferenceParameters] Parameters for the inference. diff --git a/lib/mindee/input/inference_parameters.rb b/lib/mindee/input/inference_parameters.rb index f83f73046..011838856 100644 --- a/lib/mindee/input/inference_parameters.rb +++ b/lib/mindee/input/inference_parameters.rb @@ -59,6 +59,9 @@ def validate_async_params "Cannot set auto-poll retries to less than #{min_retries}" end + # Loads a prediction from a Hash. + # @param [Hash] params Parameters to provide as a hash. + # @return [InferenceParameters] def self.from_hash(params: {}) params.transform_keys!(&:to_sym) @@ -86,6 +89,9 @@ def self.from_hash(params: {}) private + # Cleans a proper polling options object potentially from a hash. + # @param [Hash, PollingOptions, nil] polling_options Polling options. + # @return [PollingOptions] Valid polling options object. def get_clean_polling_options(polling_options) return PollingOptions.new if polling_options.is_a?(PollingOptions) diff --git a/lib/mindee/page_options.rb b/lib/mindee/page_options.rb index eed3f1c2f..ad8f93aec 100644 --- a/lib/mindee/page_options.rb +++ b/lib/mindee/page_options.rb @@ -2,7 +2,6 @@ module Mindee # Class for page options in parse calls. - # # @!attribute page_indexes [Array[Integer]] Zero-based list of page indexes. # @!attribute operation [:KEEP_ONLY, :REMOVE] Operation to apply on the document, given the specified page indexes: # * `:KEEP_ONLY` - keep only the specified pages, and remove all others. diff --git a/lib/mindee/parsing/common/api_response.rb b/lib/mindee/parsing/common/api_response.rb index 056d391b3..7e9f47349 100644 --- a/lib/mindee/parsing/common/api_response.rb +++ b/lib/mindee/parsing/common/api_response.rb @@ -8,9 +8,13 @@ module Parsing module Common # Potential values for queue in asynchronous calls. module JobStatus + # Job is waiting. WAITING = :waiting + # Job is processing. PROCESSING = :processing + # Job is done. COMPLETED = :completed + # Job failed. FAILURE = :failed end diff --git a/lib/mindee/parsing/common/ocr/ocr.rb b/lib/mindee/parsing/common/ocr/ocr.rb index 4bc195ffc..95c3cfb96 100644 --- a/lib/mindee/parsing/common/ocr/ocr.rb +++ b/lib/mindee/parsing/common/ocr/ocr.rb @@ -36,7 +36,7 @@ def to_s # A list of words which are on the same line. 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) }) diff --git a/lib/mindee/parsing/v2/common_response.rb b/lib/mindee/parsing/v2/common_response.rb index 6a30e799a..b28938042 100644 --- a/lib/mindee/parsing/v2/common_response.rb +++ b/lib/mindee/parsing/v2/common_response.rb @@ -5,7 +5,7 @@ module Parsing module V2 # Base class for inference and job responses on the V2 API. class CommonResponse - # @return [Hash] + # @return [Hash] attr_reader :raw_http # @param http_response [Hash] diff --git a/lib/mindee/parsing/v2/error_response.rb b/lib/mindee/parsing/v2/error_response.rb index a9280e765..91c7d8912 100644 --- a/lib/mindee/parsing/v2/error_response.rb +++ b/lib/mindee/parsing/v2/error_response.rb @@ -16,7 +16,7 @@ def initialize(server_response) @detail = server_response['detail'] end - # String representation, useful when embedding in larger objects. + # String representation. # @return [String] def to_s "Error\n=====\n:Status: #{@status}\n:Detail: #{@detail}" diff --git a/lib/mindee/parsing/v2/field/list_field.rb b/lib/mindee/parsing/v2/field/list_field.rb index aec4a8612..8e8dcb8b4 100644 --- a/lib/mindee/parsing/v2/field/list_field.rb +++ b/lib/mindee/parsing/v2/field/list_field.rb @@ -7,9 +7,6 @@ module Parsing module V2 module Field # Represents a field that contains a list of items. - # The list can include various field types such as ListField, ObjectField, - # or SimpleField. Implements the Enumerable module for traversal and - # manipulation. class ListField < BaseField include Enumerable # @return [Array] Items contained in the list. @@ -77,7 +74,7 @@ def [](index) end # Iterator for Enumerator inheritance. - # Untyped due to incomplete support in steep. + # NOTE: Untyped due to incomplete support in steep. def each(&block) return to_enum(:each) unless block_given? diff --git a/lib/mindee/parsing/v2/field/simple_field.rb b/lib/mindee/parsing/v2/field/simple_field.rb index d3d3b0457..aee80f638 100644 --- a/lib/mindee/parsing/v2/field/simple_field.rb +++ b/lib/mindee/parsing/v2/field/simple_field.rb @@ -36,17 +36,15 @@ def to_s private - # Format numeric values according to the PHP implementation logic. + # Format numeric values to display '.0' in string reps. # @param value [Numeric] The numeric value to format. # @return [String] Formatted numeric string. def format_numeric_value(value) float_value = value.to_f - # If it's effectively an integer, show with .0 if float_value == float_value.to_i format('%.1f', float_value) else - # Format with up to 5 decimal places, removing trailing zeros formatted = format('%.5f', float_value) formatted.sub(%r{\.?0+$}, '') end diff --git a/lib/mindee/parsing/v2/inference.rb b/lib/mindee/parsing/v2/inference.rb index c111c7a45..c843196c8 100644 --- a/lib/mindee/parsing/v2/inference.rb +++ b/lib/mindee/parsing/v2/inference.rb @@ -7,10 +7,7 @@ module Mindee module Parsing module V2 - # Complete data returned by an inference request: - # • model information - # • file information - # • inference result (fields, options, …) + # Complete data returned by an inference request. class Inference # @return [InferenceModel] Information about the model used. attr_reader :model @@ -32,8 +29,7 @@ def initialize(server_response) @id = server_response['id'] end - # RST-style string representation (keeps parity with TS implementation). - # + # String representation. # @return [String] def to_s [ diff --git a/lib/mindee/parsing/v2/inference_file.rb b/lib/mindee/parsing/v2/inference_file.rb index 7dc7f29f4..78dda706b 100644 --- a/lib/mindee/parsing/v2/inference_file.rb +++ b/lib/mindee/parsing/v2/inference_file.rb @@ -22,7 +22,7 @@ def initialize(server_response) @mime_type = server_response['mime_type'] end - # RST-style string representation. + # String representation. # @return [String] def to_s "File\n" \ diff --git a/lib/mindee/parsing/v2/inference_response.rb b/lib/mindee/parsing/v2/inference_response.rb index 70ee98554..1aac55a88 100644 --- a/lib/mindee/parsing/v2/inference_response.rb +++ b/lib/mindee/parsing/v2/inference_response.rb @@ -19,8 +19,7 @@ def initialize(server_response) @inference = Inference.new(server_response['inference']) end - # Delegates to CommonResponse's string representation and appends the inference details. - # + # String representation. # @return [String] def to_s @inference.to_s diff --git a/lib/mindee/parsing/v2/inference_result.rb b/lib/mindee/parsing/v2/inference_result.rb index 500f97c95..857dd1077 100644 --- a/lib/mindee/parsing/v2/inference_result.rb +++ b/lib/mindee/parsing/v2/inference_result.rb @@ -24,8 +24,7 @@ def initialize(server_response) @options = InferenceResultOptions.new(server_response['options']) end - # RST-style string representation. - # + # String representation. # @return [String] def to_s parts = [ diff --git a/lib/mindee/parsing/v2/job.rb b/lib/mindee/parsing/v2/job.rb index 67e7e8501..5e6d9aab6 100644 --- a/lib/mindee/parsing/v2/job.rb +++ b/lib/mindee/parsing/v2/job.rb @@ -51,8 +51,7 @@ def initialize(server_response) end end - # RST-style string representation, useful for debugging or logs. - # + # String representation. # @return [String] def to_s lines = [ diff --git a/lib/mindee/parsing/v2/job_response.rb b/lib/mindee/parsing/v2/job_response.rb index 16ed070ee..70aab84ac 100644 --- a/lib/mindee/parsing/v2/job_response.rb +++ b/lib/mindee/parsing/v2/job_response.rb @@ -19,8 +19,7 @@ def initialize(server_response) @job = Job.new(server_response['job']) end - # Delegates to CommonResponse's string representation and appends the job details. - # + # String representation. # @return [String] def to_s @job.to_s diff --git a/sig/custom/mini_magick.rbs b/sig/custom/mini_magick.rbs index 842bfbe59..78111ac23 100644 --- a/sig/custom/mini_magick.rbs +++ b/sig/custom/mini_magick.rbs @@ -28,4 +28,4 @@ module MiniMagick def self.[]: (*untyped) -> untyped def []: (*untyped) -> untyped end -end \ No newline at end of file +end diff --git a/sig/mindee/parsing/v2/field/object_field.rbs b/sig/mindee/parsing/v2/field/object_field.rbs index ab1d84529..fe66d4ed0 100644 --- a/sig/mindee/parsing/v2/field/object_field.rbs +++ b/sig/mindee/parsing/v2/field/object_field.rbs @@ -18,4 +18,4 @@ module Mindee end end end -end \ No newline at end of file +end