class Emarsys::ParamsConverter

Attributes

params[RW]

Public Class Methods

new(params={}) click to toggle source
# File lib/emarsys/params_converter.rb, line 7
def initialize(params={})
  self.params = params
end

Public Instance Methods

convert_to_identifiers() click to toggle source
# 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_ids() click to toggle source
# 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

Private Instance Methods

convert_array_to_ids() click to toggle source
# File lib/emarsys/params_converter.rb, line 35
def convert_array_to_ids
  new_array = []
  params.each do |key|
    matching_attributes = Emarsys::FieldMapping.attributes.find{|elem| elem[:identifier] == key.to_s}
    new_array << (matching_attributes.nil? ? key : matching_attributes[:id])
  end
  new_array
end
convert_hash_to_ids() click to toggle source
# File lib/emarsys/params_converter.rb, line 26
def convert_hash_to_ids
  new_hash = {}
  params.each do |key, value|
    matching_attributes = Emarsys::FieldMapping.attributes.find{|elem| elem[:identifier] == key.to_s}
    new_hash.merge!({ (matching_attributes.nil? ? key : matching_attributes[:id]) => value })
  end
  new_hash
end