Class: Datalab::OcrResult

Inherits:
Object
  • Object
show all
Defined in:
lib/datalab/ocr_result.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ OcrResult

Returns a new instance of OcrResult.



4
5
6
7
8
9
# File 'lib/datalab/ocr_result.rb', line 4

def initialize( attributes )
  @success = 
    attributes[ :success ] || 
    [ :processing, :complete ].include?( attributes[ :status ]&.to_sym )
  @attributes = attributes || {}
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/datalab/ocr_result.rb', line 34

def complete?
  status == :complete
end

#failure_messageObject

If success? returns false this method will return a message explaining the reason for the failure.



42
43
44
# File 'lib/datalab/ocr_result.rb', line 42

def failure_message
  @attributes[ :error ]
end

#idObject



11
12
13
# File 'lib/datalab/ocr_result.rb', line 11

def id 
  @attributes[ :request_id ]
end

#merge(attributes) ⇒ Object



59
60
61
# File 'lib/datalab/ocr_result.rb', line 59

def merge( attributes )
  self.class.new( ( @attributes || {} ).merge( attributes ) )
end

#page_countObject



55
56
57
# File 'lib/datalab/ocr_result.rb', line 55

def page_count
  @attributes[ :page_count ]
end

#pagesObject

The pages method returns the pages extracted from the given document. If the given document was an image the result is an array with a single page. If no pages were recognized the result is an empty array.



51
52
53
# File 'lib/datalab/ocr_result.rb', line 51

def pages
  ( @attributes[ :pages ] || [] ).map( &OcrPage.method( :new ) ) 
end

#processing?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/datalab/ocr_result.rb', line 30

def processing?
  status == :processing 
end

#statusObject



26
27
28
# File 'lib/datalab/ocr_result.rb', line 26

def status 
  @attributes[ :status ]&.to_sym || :processing 
end

#success?Boolean

The success? method returns true if the converstion was successful.

Note that the response success? tells you if the call to the Datalab API was successful while this success? method tells you if the actual conversaion operation began successfully.

Returns:

  • (Boolean)


22
23
24
# File 'lib/datalab/ocr_result.rb', line 22

def success?  
  @success || false 
end