Class: Mindee::Parsing::Generated::GeneratedListField

Inherits:
Object
  • Object
show all
Includes:
Mindee::Parsing::Generated, Standard
Defined in:
lib/mindee/parsing/generated/generated_list_field.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mindee::Parsing::Generated

generated_object?

Constructor Details

#initialize(raw_prediction, page_id = nil) ⇒ GeneratedListField

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mindee/parsing/generated/generated_list_field.rb', line 24

def initialize(raw_prediction, page_id = nil)
  @values = []

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

    if Generated.generated_object?(value)
      @values.push(GeneratedObjectField.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(StringField.new(value_str, page_id))
    end
  end
end

Instance Attribute Details

#page_idInteger

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

Returns:

  • (Integer)


15
16
17
# File 'lib/mindee/parsing/generated/generated_list_field.rb', line 15

def page_id
  @page_id
end

#valuesArray<GeneratedObjectField, StringField>

List of word values

Returns:



19
20
21
# File 'lib/mindee/parsing/generated/generated_list_field.rb', line 19

def values
  @values
end

Instance Method Details

#contents_listArray<String>

Return an Array of the contents of all values.

Returns:

  • (Array<String>)


42
43
44
# File 'lib/mindee/parsing/generated/generated_list_field.rb', line 42

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

#contents_string(separator = ' ') ⇒ Object

Return a string representation of all values.



47
48
49
# File 'lib/mindee/parsing/generated/generated_list_field.rb', line 47

def contents_string(separator = ' ')
  @values.map(&:to_s).join(separator)
end

#to_sObject

String representation



52
53
54
# File 'lib/mindee/parsing/generated/generated_list_field.rb', line 52

def to_s
  contents_string
end