Class: Mindee::Product::Universal::UniversalDocument

Inherits:
UniversalPrediction show all
Includes:
Mindee::Parsing::Standard
Defined in:
lib/mindee/product/universal/universal_document.rb

Overview

Universal Document V1 prediction

Instance Attribute Summary

Attributes inherited from UniversalPrediction

#fields

Instance Method Summary collapse

Methods inherited from UniversalPrediction

#to_s

Methods included from Mindee::Parsing::Universal

universal_object?

Methods inherited from Mindee::Parsing::Common::Prediction

#to_s

Constructor Details

#initialize(raw_prediction) ⇒ UniversalDocument

Returns a new instance of UniversalDocument.

Parameters:

  • raw_prediction (Hash)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mindee/product/universal/universal_document.rb', line 13

def initialize(raw_prediction)
  super
  raw_prediction.each do |field_name, field_contents|
    if field_contents.is_a?(Array)
      @fields[field_name] = Parsing::Universal::UniversalListField.new(field_contents)
    elsif field_contents.is_a?(Hash) && Parsing::Universal.universal_object?(field_contents)
      @fields[field_name] = Parsing::Universal::UniversalObjectField.new(field_contents)
    else
      field_contents_str = field_contents.dup
      if field_contents_str.key?('value') && field_contents_str['value'].nil? == false
        field_contents_str['value'] = field_contents_str['value'].to_s
      end
      @fields[field_name] = Mindee::Parsing::Standard::StringField.new(field_contents_str)
    end
  end
end