Module: TokyoWrapper::HelperMethods::ArrayConverter

Included in:
Table
Defined in:
lib/tokyo_wrapper/helper_methods/array_converter.rb

Instance Method Summary collapse

Instance Method Details

#convert_comma_separated_values_string_to_array(comman_separated_values_string) ⇒ Object



20
21
22
# File 'lib/tokyo_wrapper/helper_methods/array_converter.rb', line 20

def convert_comma_separated_values_string_to_array(comman_separated_values_string)
  comman_separated_values_string.split(',').compact
end

#convert_params(params) ⇒ Object

rufus-tokyo converts array to string without a delimiter e.g. It converts [1,2,3,4] to “1234”. So the array needs to be converted to the comma separated string before being added. e.g. “1,2,3,4”



11
12
13
14
15
16
17
18
# File 'lib/tokyo_wrapper/helper_methods/array_converter.rb', line 11

def convert_params(params)
  params.each do |key, value|
    if value.instance_of?(Array)
      params[key] = value.join(",")
    end
  end
  params
end

#convert_values_to_array_for_keys(key_value_hash, keys) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/tokyo_wrapper/helper_methods/array_converter.rb', line 24

def convert_values_to_array_for_keys(key_value_hash, keys)
  if !keys.nil? && !keys.empty?
    keys.each do |key|
      if key_value_hash.has_key?(key)
        key_value_hash[key] = convert_comma_separated_values_string_to_array(key_value_hash[key])
      end
    end
  end
  key_value_hash
end

#convert_values_to_array_for_keys_for_multiple_key_value_hashes(key_value_hashes, keys) ⇒ Object



35
36
37
38
39
40
# File 'lib/tokyo_wrapper/helper_methods/array_converter.rb', line 35

def convert_values_to_array_for_keys_for_multiple_key_value_hashes(key_value_hashes, keys)
  key_value_hashes.each do |key_value_hash|
    convert_values_to_array_for_keys(key_value_hash, keys)
  end
  key_value_hashes
end