Class: Mindee::Product::Generated::GeneratedV1Document

Inherits:
GeneratedV1Prediction show all
Includes:
Mindee::Parsing::Standard
Defined in:
lib/mindee/product/generated/generated_v1_document.rb

Overview

Generated Document V1 prediction

Instance Attribute Summary

Attributes inherited from GeneratedV1Prediction

#fields

Instance Method Summary collapse

Methods inherited from GeneratedV1Prediction

#to_s

Methods included from Mindee::Parsing::Generated

generated_object?

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

#to_s

Constructor Details

#initialize(raw_prediction) ⇒ GeneratedV1Document

Returns a new instance of GeneratedV1Document.

Parameters:

  • raw_prediction (Hash)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mindee/product/generated/generated_v1_document.rb', line 13

def initialize(raw_prediction)
  # Generated document.

  # raw_prediction: Dictionary containing the JSON document response
  super()
  raw_prediction.each do |field_name, field_contents|
    if field_contents.is_a?(Array)
      @fields[field_name] = Parsing::Generated::GeneratedListField.new(field_contents)
    elsif field_contents.is_a?(Hash) && Parsing::Generated.generated_object?(field_contents)
      @fields[field_name] = Parsing::Generated::GeneratedObjectField.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] = StringField.new(field_contents_str)
    end
  end
end