Class: Mindee::Product::Custom::CustomV1Document

Inherits:
Mindee::Parsing::Common::Prediction show all
Defined in:
lib/mindee/product/custom/custom_v1_document.rb

Overview

Custom Document V1 prediction

Direct Known Subclasses

CustomV1PagePrediction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prediction, page_id) ⇒ CustomV1Document

Returns a new instance of CustomV1Document.

Parameters:

  • prediction (Hash)
  • page_id (Integer, nil)


19
20
21
22
23
24
25
26
27
# File 'lib/mindee/product/custom/custom_v1_document.rb', line 19

def initialize(prediction, page_id)
  super()
  @fields = {}
  @classifications = {}
  prediction.each do |field_name, field_prediction|
    field_sym = field_name.to_sym
    set_field(field_sym, field_prediction, page_id)
  end
end

Instance Attribute Details

#classificationsHash<Symbol, Mindee::Parsing::Custom::ClassificationField> (readonly)

All classifications in the document



15
16
17
# File 'lib/mindee/product/custom/custom_v1_document.rb', line 15

def classifications
  @classifications
end

#fieldsHash<Symbol, Mindee::Parsing::Custom::ListField> (readonly)

All value fields in the document

Returns:



12
13
14
# File 'lib/mindee/product/custom/custom_v1_document.rb', line 12

def fields
  @fields
end

Instance Method Details

#to_sString

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
39
# File 'lib/mindee/product/custom/custom_v1_document.rb', line 30

def to_s
  out_str = String.new
  @classifications.each do |name, info|
    out_str << "\n:#{name}: #{info}".rstrip
  end
  @fields.each do |name, info|
    out_str << "\n:#{name}: #{info}".rstrip
  end
  out_str[1..].to_s
end