Class: Datalab::OcrResult
- Inherits:
-
Object
- Object
- Datalab::OcrResult
- Defined in:
- lib/datalab/ocr_result.rb
Instance Method Summary collapse
- #complete? ⇒ Boolean
-
#failure_message ⇒ Object
If
success?
returnsfalse
this method will return a message explaining the reason for the failure. - #id ⇒ Object
-
#initialize(attributes) ⇒ OcrResult
constructor
A new instance of OcrResult.
- #merge(attributes) ⇒ Object
- #page_count ⇒ Object
-
#pages ⇒ Object
The
pages
method returns the pages extracted from the given document. - #processing? ⇒ Boolean
- #status ⇒ Object
-
#success? ⇒ Boolean
The
success?
method returnstrue
if the converstion was successful.
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
34 35 36 |
# File 'lib/datalab/ocr_result.rb', line 34 def complete? status == :complete end |
#failure_message ⇒ Object
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 @attributes[ :error ] end |
#id ⇒ Object
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_count ⇒ Object
55 56 57 |
# File 'lib/datalab/ocr_result.rb', line 55 def page_count @attributes[ :page_count ] end |
#pages ⇒ Object
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
30 31 32 |
# File 'lib/datalab/ocr_result.rb', line 30 def processing? status == :processing end |
#status ⇒ Object
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.
22 23 24 |
# File 'lib/datalab/ocr_result.rb', line 22 def success? @success || false end |