Class: Emarsys::ParamsConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/emarsys/params_converter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ ParamsConverter

Returns a new instance of ParamsConverter.



7
8
9
# File 'lib/emarsys/params_converter.rb', line 7

def initialize(params={})
  self.params = params
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/emarsys/params_converter.rb', line 5

def params
  @params
end

Instance Method Details

#convert_to_identifiersObject



15
16
17
18
19
20
21
22
# File 'lib/emarsys/params_converter.rb', line 15

def convert_to_identifiers
  new_hash = {}
  params.each do |key, value|
    matching_attributes = Emarsys::FieldMapping.attributes.find{|elem| elem[:id] == key.to_i && key.to_i != 0}
    new_hash.merge!({ (matching_attributes.nil? ? key : matching_attributes[:identifier]) => value })
  end
  new_hash
end

#convert_to_idsObject



11
12
13
# File 'lib/emarsys/params_converter.rb', line 11

def convert_to_ids
  params.is_a?(Hash) ? convert_hash_to_ids : convert_array_to_ids
end