22
33require_relative 'input'
44require_relative 'http'
5- require_relative 'product'
5+ require_relative 'logging'
6+ require_relative 'page_options'
67require_relative 'parsing/common/api_response'
78require_relative 'parsing/common/job'
89require_relative 'parsing/common/workflow_response'
9- require_relative 'logging '
10+ require_relative 'product '
1011
1112# Default owner for products.
1213OTS_OWNER = 'mindee'
1314
1415module Mindee
15- # Class for page options in parse calls.
16- #
17- # @!attribute page_indexes [Array[Integer]] Zero-based list of page indexes.
18- # @!attribute operation [:KEEP_ONLY, :REMOVE] Operation to apply on the document, given the specified page indexes:
19- # * `:KEEP_ONLY` - keep only the specified pages, and remove all others.
20- # * `:REMOVE` - remove the specified pages, and keep all others.
21- # @!attribute on_min_pages [Integer, nil] Apply the operation only if the document has at least this many pages.
22- class PageOptions
23- attr_accessor :page_indexes , :operation , :on_min_pages
24-
25- def initialize ( params : { } )
26- params ||= { }
27- params = params . transform_keys ( &:to_sym )
28- @page_indexes = params . fetch (
29- :page_indexes ,
30- [ ] # : Array[Integer]
31- )
32- @operation = params . fetch ( :operation , :KEEP_ONLY )
33- @on_min_pages = params . fetch ( :on_min_pages , nil )
34- end
35- end
36-
3716 # Class for configuration options in parse calls.
3817 #
3918 # @!attribute all_words [bool] Whether to include the full text for each page.
@@ -89,8 +68,9 @@ def initialize(params: {})
8968 # * `:KEEP_ONLY` - keep only the specified pages, and remove all others.
9069 # * `:REMOVE` - remove the specified pages, and keep all others.
9170 # * `:on_min_pages` Apply the operation only if the document has at least this many pages.
71+ # @!attribute close_file [bool, nil] Whether to close the file after sending it. Defaults to true.
9272 class WorkflowOptions
93- attr_accessor :document_alias , :priority , :full_text , :public_url , :page_options , :rag
73+ attr_accessor :document_alias , :priority , :full_text , :public_url , :page_options , :rag , :close_file
9474
9575 def initialize ( params : { } )
9676 params = params . transform_keys ( &:to_sym )
@@ -102,6 +82,7 @@ def initialize(params: {})
10282 raw_page_options = params . fetch ( :page_options , nil )
10383 raw_page_options = PageOptions . new ( params : raw_page_options ) unless raw_page_options . is_a? ( PageOptions )
10484 @page_options = raw_page_options
85+ @close_file = params . fetch ( :close_file , true )
10586 end
10687 end
10788
@@ -326,7 +307,7 @@ def execute_workflow(input_source, workflow_id, options: {})
326307 process_pdf_if_required ( input_source , opts )
327308 end
328309
329- workflow_endpoint = Mindee ::HTTP ::WorkflowEndpoint . new ( workflow_id , api_key : @api_key )
310+ workflow_endpoint = Mindee ::HTTP ::WorkflowEndpoint . new ( workflow_id , api_key : @api_key . to_s )
330311 logger . debug ( "Sending document to workflow '#{ workflow_id } '" )
331312
332313 prediction , raw_http = workflow_endpoint . execute_workflow (
@@ -455,11 +436,11 @@ def initialize_endpoint(product_class, endpoint_name: '', account_name: '', vers
455436 account_name = fix_account_name ( account_name )
456437 version = fix_version ( product_class , version )
457438
458- HTTP ::Endpoint . new ( account_name , endpoint_name , version , api_key : @api_key )
439+ HTTP ::Endpoint . new ( account_name , endpoint_name , version , api_key : @api_key . to_s )
459440 end
460441
461442 def fix_endpoint_name ( product_class , endpoint_name )
462- endpoint_name . nil? || endpoint_name . empty? ? product_class . endpoint_name : endpoint_name
443+ endpoint_name . nil? || endpoint_name . empty? ? product_class . endpoint_name . to_s : endpoint_name . to_s
463444 end
464445
465446 def fix_account_name ( account_name )
@@ -474,11 +455,11 @@ def fix_account_name(account_name)
474455 def fix_version ( product_class , version )
475456 return version unless version . nil? || version . empty?
476457
477- if product_class . endpoint_version . nil? || product_class . endpoint_version . empty?
458+ if product_class . endpoint_version . nil? || product_class . endpoint_version . to_s . empty?
478459 logger . debug ( 'No version provided for a custom build, will attempt to poll version 1 by default.' )
479460 return '1'
480461 end
481- product_class . endpoint_version
462+ product_class . endpoint_version || ''
482463 end
483464
484465 # If needed, converts the parsing options provided as a hash into a proper ParseOptions object.
0 commit comments