Class: Mindee::Parsing::Generated::GeneratedListField
- Inherits:
-
Object
- Object
- Mindee::Parsing::Generated::GeneratedListField
- 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
-
#page_id ⇒ Integer
Id of the page (as given by the API).
-
#values ⇒ Array<GeneratedObjectField, StringField>
List of word values.
Instance Method Summary collapse
-
#contents_list ⇒ Array<String>
Return an Array of the contents of all values.
-
#contents_string(separator = ' ') ⇒ Object
Return a string representation of all values.
-
#initialize(raw_prediction, page_id = nil) ⇒ GeneratedListField
constructor
Id of the page the object was found on.
-
#to_s ⇒ Object
String representation.
Methods included from Mindee::Parsing::Generated
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_id ⇒ Integer
Id of the page (as given by the API).
15 16 17 |
# File 'lib/mindee/parsing/generated/generated_list_field.rb', line 15 def page_id @page_id end |
#values ⇒ Array<GeneratedObjectField, StringField>
List of word values
19 20 21 |
# File 'lib/mindee/parsing/generated/generated_list_field.rb', line 19 def values @values end |
Instance Method Details
#contents_list ⇒ Array<String>
Return an Array of the contents of all values.
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_s ⇒ Object
String representation
52 53 54 |
# File 'lib/mindee/parsing/generated/generated_list_field.rb', line 52 def to_s contents_string end |