Class: Mindee::V1::Parsing::Common::Document
- Inherits:
-
Object
- Object
- Mindee::V1::Parsing::Common::Document
- Defined in:
- lib/mindee/v1/parsing/common/document.rb
Overview
Stores all response attributes.
Instance Attribute Summary collapse
-
#extras ⇒ Mindee::V1::Parsing::Common::Extras::Extras
readonly
Potential Extras fields sent back along the prediction.
-
#id ⇒ String
readonly
Mindee ID of the document.
- #inference ⇒ Mindee::Inference readonly
-
#n_pages ⇒ Integer
readonly
Amount of pages of the document.
-
#name ⇒ String
readonly
Filename sent to the API.
-
#ocr ⇒ Mindee::V1::Parsing::Common::OCR::OCR?
readonly
OCR text results (limited availability).
Class Method Summary collapse
-
.extract_extras(http_response) ⇒ Mindee::V1::Parsing::Common::OCR::OCR
Loads extras into the document prediction.
-
.load_ocr(http_response) ⇒ Mindee::V1::Parsing::Common::OCR::OCR
Loads the MVision OCR response.
Instance Method Summary collapse
-
#initialize(product_class, http_response) ⇒ Document
constructor
A new instance of Document.
- #to_s ⇒ String
Constructor Details
#initialize(product_class, http_response) ⇒ Document
Returns a new instance of Document.
47 48 49 50 51 52 53 54 55 |
# File 'lib/mindee/v1/parsing/common/document.rb', line 47 def initialize(product_class, http_response) @id = http_response['id'] @name = http_response['name'] @inference = product_class.new(http_response['inference']) @ocr = self.class.load_ocr(http_response) @extras = self.class.extract_extras(http_response) inject_full_text_ocr(http_response) @n_pages = http_response['n_pages'] end |
Instance Attribute Details
#extras ⇒ Mindee::V1::Parsing::Common::Extras::Extras (readonly)
Returns Potential Extras fields sent back along the prediction.
19 20 21 |
# File 'lib/mindee/v1/parsing/common/document.rb', line 19 def extras @extras end |
#id ⇒ String (readonly)
Returns Mindee ID of the document.
17 18 19 |
# File 'lib/mindee/v1/parsing/common/document.rb', line 17 def id @id end |
#inference ⇒ Mindee::Inference (readonly)
13 14 15 |
# File 'lib/mindee/v1/parsing/common/document.rb', line 13 def inference @inference end |
#n_pages ⇒ Integer (readonly)
Returns Amount of pages of the document.
23 24 25 |
# File 'lib/mindee/v1/parsing/common/document.rb', line 23 def n_pages @n_pages end |
#name ⇒ String (readonly)
Returns Filename sent to the API.
15 16 17 |
# File 'lib/mindee/v1/parsing/common/document.rb', line 15 def name @name end |
#ocr ⇒ Mindee::V1::Parsing::Common::OCR::OCR? (readonly)
Returns OCR text results (limited availability).
21 22 23 |
# File 'lib/mindee/v1/parsing/common/document.rb', line 21 def ocr @ocr end |
Class Method Details
.extract_extras(http_response) ⇒ Mindee::V1::Parsing::Common::OCR::OCR
Loads extras into the document prediction.
38 39 40 41 42 43 |
# File 'lib/mindee/v1/parsing/common/document.rb', line 38 def self.extract_extras(http_response) extras_prediction = http_response['inference'].fetch('extras', nil) return nil if extras_prediction.nil? || extras_prediction.fetch('mvision-v1', nil).nil? Mindee::V1::Parsing::Common::Extras::Extras.new(extras_prediction) end |
.load_ocr(http_response) ⇒ Mindee::V1::Parsing::Common::OCR::OCR
Loads the MVision OCR response.
28 29 30 31 32 33 |
# File 'lib/mindee/v1/parsing/common/document.rb', line 28 def self.load_ocr(http_response) ocr_prediction = http_response.fetch('ocr', nil) return nil if ocr_prediction.nil? || ocr_prediction.fetch('mvision-v1', nil).nil? OCR::OCR.new(ocr_prediction) end |
Instance Method Details
#to_s ⇒ String
58 59 60 61 62 63 64 |
# File 'lib/mindee/v1/parsing/common/document.rb', line 58 def to_s out_str = String.new out_str << "########\nDocument\n########" out_str << "\n:Mindee ID: #{@id}" out_str << "\n:Filename: #{@name}" out_str << "\n\n#{@inference}" end |