Class: Mindee::V1::Parsing::Universal::UniversalListField
- Inherits:
-
Object
- Object
- Mindee::V1::Parsing::Universal::UniversalListField
- 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
-
#page_id ⇒ Integer
readonly
ID of the page (as given by the API).
-
#values ⇒ Array<UniversalObjectField, StringField>
readonly
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) ⇒ UniversalListField
constructor
ID of the page the object was found on.
-
#to_s ⇒ Object
String representation.
Methods included from Mindee::V1::Parsing::Universal
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_id ⇒ Integer (readonly)
ID of the page (as given by the API).
16 17 18 |
# File 'lib/mindee/v1/parsing/universal/universal_list_field.rb', line 16 def page_id @page_id end |
#values ⇒ Array<UniversalObjectField, StringField> (readonly)
List of word values
20 21 22 |
# File 'lib/mindee/v1/parsing/universal/universal_list_field.rb', line 20 def values @values end |
Instance Method Details
#contents_list ⇒ Array<String>
Return an Array of the contents of all values.
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_s ⇒ Object
String representation
53 54 55 |
# File 'lib/mindee/v1/parsing/universal/universal_list_field.rb', line 53 def to_s contents_string end |