module ConvertValue

Public Class Methods

convert_to_string(value, type) click to toggle source

rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength

# File lib/helpers/convert_value.rb, line 26
def convert_to_string(value, type)
  case type
  when 'Hash', 'Hashie::Mash'
    value.to_json
  when 'Array'
    value.join('|||')
  else
    value.to_s
  end
end
convert_to_type(value, type) click to toggle source

rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength

# File lib/helpers/convert_value.rb, line 4
def convert_to_type(value, type)
  case type
  when 'String'
    value.to_s
  when 'TrueClass'
    true
  when 'NilClass', 'FalseClass'
    false
  when 'Fixnum', 'Integer'
    value.to_i
  when 'Float'
    value.to_f
  when 'Symbol'
    value.to_sym
  when 'Array'
    value.split('|||')
  when 'Hash'
    Hashie::Mash.new(JSON.parse(value))
  end
end