Class: Mindee::Product::Universal::UniversalPrediction

Inherits:
Mindee::Parsing::Common::Prediction show all
Includes:
Mindee::Parsing::Common, Mindee::Parsing::Standard, Mindee::Parsing::Universal
Defined in:
lib/mindee/product/universal/universal_prediction.rb

Overview

Universal Document V1 page.

Direct Known Subclasses

UniversalDocument, UniversalPagePrediction

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mindee::Parsing::Universal

universal_object?

Constructor Details

#initialize(_ = nil) ⇒ UniversalPrediction

Returns a new instance of UniversalPrediction.



17
18
19
20
# File 'lib/mindee/product/universal/universal_prediction.rb', line 17

def initialize(_ = nil)
  super
  @fields = {} # : Hash[Symbol | String, untyped]
end

Instance Attribute Details

#fieldsHash<Symbol, Mindee::Parsing::Universal::UniversalListField> (readonly)

All value fields in the document



15
16
17
# File 'lib/mindee/product/universal/universal_prediction.rb', line 15

def fields
  @fields
end

Instance Method Details

#to_sObject

String representation.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mindee/product/universal/universal_prediction.rb', line 23

def to_s
  out_str = ''
  pattern = %r{^(\n* *)( {2}):}
  @fields.each do |field_name, field_value|
    str_value = if field_value.is_a?(
      Mindee::Parsing::Universal::UniversalListField
    ) && field_value.values.length.positive?
                  generate_field_string(field_name, field_value, pattern)
                else
                  field_value.to_s
                end
    out_str += "\n:#{field_name}:"

    out_str += " #{str_value}".sub(%r{^\s+\n}, "\n") if str_value.length.positive?
  end
  out_str.sub("\n", '')
end