Class: Mindee::V1::Parsing::Common::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/v1/parsing/common/document.rb

Overview

Stores all response attributes.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_class, http_response) ⇒ Document

Returns a new instance of Document.

Parameters:

  • product_class (Mindee::Inference)
  • http_response (Hash)


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

#extrasMindee::V1::Parsing::Common::Extras::Extras (readonly)

Returns Potential Extras fields sent back along the prediction.

Returns:



19
20
21
# File 'lib/mindee/v1/parsing/common/document.rb', line 19

def extras
  @extras
end

#idString (readonly)

Returns Mindee ID of the document.

Returns:

  • (String)

    Mindee ID of the document



17
18
19
# File 'lib/mindee/v1/parsing/common/document.rb', line 17

def id
  @id
end

#inferenceMindee::Inference (readonly)

Returns:

  • (Mindee::Inference)


13
14
15
# File 'lib/mindee/v1/parsing/common/document.rb', line 13

def inference
  @inference
end

#n_pagesInteger (readonly)

Returns Amount of pages of the document.

Returns:

  • (Integer)

    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

#nameString (readonly)

Returns Filename sent to the API.

Returns:

  • (String)

    Filename sent to the API



15
16
17
# File 'lib/mindee/v1/parsing/common/document.rb', line 15

def name
  @name
end

#ocrMindee::V1::Parsing::Common::OCR::OCR? (readonly)

Returns OCR text results (limited availability).

Returns:



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.

Parameters:

  • http_response (Hash)

    Full HTTP contents of the response.

Returns:



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.

Parameters:

  • http_response (Hash)

    Full HTTP contents of the response.

Returns:



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_sString

Returns:

  • (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