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

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/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)


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

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

Returns Potential Extras fields sent back along the prediction.

Returns:



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

def extras
  @extras
end

#idString (readonly)

Returns Mindee ID of the document.

Returns:

  • (String)

    Mindee ID of the document



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

def id
  @id
end

#inferenceMindee::Inference (readonly)

Returns:

  • (Mindee::Inference)


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

def inference
  @inference
end

#n_pagesInteger (readonly)

Returns Amount of pages of the document.

Returns:

  • (Integer)

    Amount of pages of the document



22
23
24
# File 'lib/mindee/parsing/common/document.rb', line 22

def n_pages
  @n_pages
end

#nameString (readonly)

Returns Filename sent to the API.

Returns:

  • (String)

    Filename sent to the API



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

def name
  @name
end

#ocrMindee::Parsing::Common::Ocr::Ocr? (readonly)

Returns OCR text results (limited availability).

Returns:



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

Parameters:

  • http_response (Hash)

Returns:



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_sString

Returns:

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