Class: Responsys::Api::Object::RecordData
- Inherits:
-
Object
- Object
- Responsys::Api::Object::RecordData
- Includes:
- Responsys::Api::Object, Exceptions
- Defined in:
- lib/responsys/api/object/record_data.rb
Instance Attribute Summary collapse
-
#field_names ⇒ Object
Returns the value of attribute field_names.
-
#records ⇒ Object
Returns the value of attribute records.
Instance Method Summary collapse
-
#initialize(data) ⇒ RecordData
constructor
A new instance of RecordData.
- #to_api ⇒ Object
Constructor Details
#initialize(data) ⇒ RecordData
Returns a new instance of RecordData.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/responsys/api/object/record_data.rb', line 9 def initialize(data) raise ParameterException, Responsys::Helper.("api.object.record_data.incorrect_record_data_type") unless data.is_a? Array self.field_names = data.map { |record| record.keys }.flatten.uniq new_data = [] field_names.each { |field_name| data.each_with_index { |entity, index| new_data[index] ||= Record.new([]) new_data[index].field_values << (entity.has_key?(field_name) ? entity[field_name.to_sym] : "") } } self.records = new_data end |
Instance Attribute Details
#field_names ⇒ Object
Returns the value of attribute field_names.
7 8 9 |
# File 'lib/responsys/api/object/record_data.rb', line 7 def field_names @field_names end |
#records ⇒ Object
Returns the value of attribute records.
7 8 9 |
# File 'lib/responsys/api/object/record_data.rb', line 7 def records @records end |
Instance Method Details
#to_api ⇒ Object
25 26 27 |
# File 'lib/responsys/api/object/record_data.rb', line 25 def to_api { fieldNames: field_names, records: records.map(&:to_api) } end |