Class: Mindee::Parsing::Common::Document
- Inherits:
-
Object
- Object
- Mindee::Parsing::Common::Document
- Defined in:
- lib/mindee/parsing/common/document.rb
Overview
Stores all response attributes.
Instance Attribute Summary collapse
-
#extras ⇒ Mindee::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::Parsing::Common::Ocr::Ocr?
readonly
OCR text results (limited availability).
Class Method Summary collapse
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.
42 43 44 45 46 47 48 49 50 |
# File 'lib/mindee/parsing/common/document.rb', line 42 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.load_extras(http_response) inject_full_text_ocr(http_response) @n_pages = http_response['n_pages'] end |
Instance Attribute Details
#extras ⇒ Mindee::Parsing::Common::Extras::Extras (readonly)
Returns Potential Extras fields sent back along the prediction.
18 19 20 |
# File 'lib/mindee/parsing/common/document.rb', line 18 def extras @extras end |
#id ⇒ String (readonly)
Returns Mindee ID of the document.
16 17 18 |
# File 'lib/mindee/parsing/common/document.rb', line 16 def id @id end |
#inference ⇒ Mindee::Inference (readonly)
12 13 14 |
# File 'lib/mindee/parsing/common/document.rb', line 12 def inference @inference end |
#n_pages ⇒ Integer (readonly)
Returns Amount of pages of the document.
22 23 24 |
# File 'lib/mindee/parsing/common/document.rb', line 22 def n_pages @n_pages end |
#name ⇒ String (readonly)
Returns Filename sent to the API.
14 15 16 |
# File 'lib/mindee/parsing/common/document.rb', line 14 def name @name end |
#ocr ⇒ Mindee::Parsing::Common::Ocr::Ocr? (readonly)
Returns OCR text results (limited availability).
20 21 22 |
# File 'lib/mindee/parsing/common/document.rb', line 20 def ocr @ocr end |
Class Method Details
.load_extras(http_response) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/mindee/parsing/common/document.rb', line 33 def self.load_extras(http_response) extras_prediction = http_response['inference'].fetch('extras', nil) return nil if extras_prediction.nil? || extras_prediction.fetch('mvision-v1', nil).nil? Extras::Extras::Extras.new(extras_prediction) end |
.load_ocr(http_response) ⇒ Mindee::Parsing::Common::Ocr::Ocr
26 27 28 29 30 31 |
# File 'lib/mindee/parsing/common/document.rb', line 26 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
53 54 55 56 57 58 59 |
# File 'lib/mindee/parsing/common/document.rb', line 53 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 |