2020-05-20 14:08:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class DataList
|
2021-11-09 07:12:15 -05:00
|
|
|
def initialize(batch, data_fields_hash, data_fields_klass)
|
2020-09-29 11:10:08 -04:00
|
|
|
@batch = batch
|
2020-05-20 14:08:00 -04:00
|
|
|
@data_fields_hash = data_fields_hash
|
2021-11-09 07:12:15 -05:00
|
|
|
@data_fields_klass = data_fields_klass
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_array
|
2021-11-09 07:12:15 -05:00
|
|
|
[data_fields_klass, columns, values]
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-11-09 07:12:15 -05:00
|
|
|
attr_reader :batch, :data_fields_hash, :data_fields_klass
|
2020-05-20 14:08:00 -04:00
|
|
|
|
|
|
|
def columns
|
2021-11-09 07:12:15 -05:00
|
|
|
data_fields_hash.keys << data_fields_foreign_key
|
|
|
|
end
|
|
|
|
|
|
|
|
def data_fields_foreign_key
|
|
|
|
data_fields_klass.reflections['integration'].foreign_key
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def values
|
2020-09-29 11:10:08 -04:00
|
|
|
batch.map do |record|
|
|
|
|
data_fields_hash.values << record['id']
|
2020-09-15 11:10:08 -04:00
|
|
|
end
|
2020-05-20 14:08:00 -04:00
|
|
|
end
|
|
|
|
end
|