Class: Mindee::V1::Parsing::Universal::UniversalListField

Inherits:
Object
  • Object
show all
Includes:
Standard, Mindee::V1::Parsing::Universal
Defined in:
lib/mindee/v1/parsing/universal/universal_list_field.rb

Overview

A list of values or objects, used in universal APIs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mindee::V1::Parsing::Universal

universal_object?

Constructor Details

#initialize(raw_prediction, page_id = nil) ⇒ UniversalListField

ID of the page the object was found on. List of word values.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mindee/v1/parsing/universal/universal_list_field.rb', line 25

def initialize(raw_prediction, page_id = nil)
  @values = [] # : Array[UniversalObjectField | Parsing::Standard::StringField]

  raw_prediction.each do |value|
    page_id = value['page_id'] if value.key?('page_id') && !value['page_id'].nil?

    if Universal.universal_object?(value)
      @values.push(Mindee::V1::Parsing::Universal::UniversalObjectField.new(value, page_id))
    else
      value_str = value.dup
      value_str['value'] = value_str['value'].to_s if value_str.key?('value') && !value_str['value'].nil?
      @values.push(Mindee::V1::Parsing::Standard::StringField.new(value_str, page_id))
    end
  end
end

Instance Attribute Details

#page_idInteger (readonly)

ID of the page (as given by the API).

Returns:

  • (Integer)


16
17
18
# File 'lib/mindee/v1/parsing/universal/universal_list_field.rb', line 16

def page_id
  @page_id
end

#valuesArray<UniversalObjectField, StringField> (readonly)

List of word values

Returns:



20
21
22
# File 'lib/mindee/v1/parsing/universal/universal_list_field.rb', line 20

def values
  @values
end

Instance Method Details

#contents_listArray<String>

Return an Array of the contents of all values.

Returns:

  • (Array<String>)


43
44
45
# File 'lib/mindee/v1/parsing/universal/universal_list_field.rb', line 43

def contents_list
  @values.map(&:to_s)
end

#contents_string(separator = ' ') ⇒ Object

Return a string representation of all values.



48
49
50
# File 'lib/mindee/v1/parsing/universal/universal_list_field.rb', line 48

def contents_string(separator = ' ')
  @values.join(separator)
end

#to_sObject

String representation



53
54
55
# File 'lib/mindee/v1/parsing/universal/universal_list_field.rb', line 53

def to_s
  contents_string
end