Class: Mindee::Parsing::Common::Extras::Extras

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

Overview

Extra information added to the prediction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_prediction) ⇒ Extras

Returns a new instance of Extras.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mindee/parsing/common/extras/extras.rb', line 17

def initialize(raw_prediction)
  if raw_prediction['cropper']
    @cropper = Mindee::Parsing::Common::Extras::CropperExtra.new(raw_prediction['cropper'])
  end
  if raw_prediction['full_text_ocr']
    @full_text_ocr = Mindee::Parsing::Common::Extras::FullTextOCRExtra.new(raw_prediction['full_text_ocr'])
  end

  raw_prediction.each do |key, value|
    instance_variable_set("@#{key}", value) unless ['cropper', 'full_text_ocr'].include?(key)
  end
end

Instance Attribute Details

#cropperCropperExtra? (readonly)

Returns:



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

def cropper
  @cropper
end

#full_text_ocrMindee::Parsing::Common::Extras::FullTextOCRExtra? (readonly)



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

def full_text_ocr
  @full_text_ocr
end

Instance Method Details

#add_artificial_extra(raw_prediction) ⇒ Object

Adds artificial extra data for reconstructed extras. Currently only used for full_text_ocr.

Parameters:

  • raw_prediction (Hash)

    Raw prediction used by the document.



42
43
44
45
46
# File 'lib/mindee/parsing/common/extras/extras.rb', line 42

def add_artificial_extra(raw_prediction)
  return unless raw_prediction['full_text_ocr']

  @full_text_ocr << Mindee::Parsing::Common::Extras::FullTextOCRExtra.new(raw_prediction)
end

#to_sString

Returns:

  • (String)


31
32
33
34
35
36
37
# File 'lib/mindee/parsing/common/extras/extras.rb', line 31

def to_s
  out_str = String.new
  instance_variables.each do |var|
    out_str << "#{var}: #{instance_variable_get(var)}"
  end
  out_str
end