Class: ExactTargetRest::DataExtParams

Inherits:
Object
  • Object
show all
Defined in:
lib/exact_target_rest/support/data_ext_params.rb

Instance Method Summary collapse

Constructor Details

#initialize(*key_fields, snake_to_camel: true) ⇒ DataExtParams

Returns a new instance of DataExtParams.



3
4
5
6
# File 'lib/exact_target_rest/support/data_ext_params.rb', line 3

def initialize(*key_fields, snake_to_camel: true)
  @key_fields = key_fields.map(&:to_sym)
  @snake_to_camel = snake_to_camel
end

Instance Method Details

#transform(params) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/exact_target_rest/support/data_ext_params.rb', line 8

def transform(params)
  (Hash === params ? [params] : params).lazy
      .map { |h| h.partition { |k, _| @key_fields.include?(k.to_sym) } }
      .map { |a, b| {keys: @snake_to_camel ? a.to_h.snake_to_camel : a.to_h,
                     values: @snake_to_camel ? b.to_h.snake_to_camel : b.to_h} }
      .to_a
end