Class: Responsys::Api::Object::RecordData

Inherits:
Object
  • Object
show all
Includes:
Responsys::Api::Object, Exceptions
Defined in:
lib/responsys/api/object/record_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ RecordData

Returns a new instance of RecordData.

Raises:



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.get_message("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_namesObject

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

#recordsObject

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_apiObject



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