module Uphold::Helpers

Public Class Methods

camelized_hash(hash) click to toggle source
# File lib/uphold/helpers.rb, line 9
def self.camelized_hash(hash)
  Hash[hash.map do |key, val|
    [camelized_key(key), val]
  end]
end
camelized_key(key) click to toggle source
# File lib/uphold/helpers.rb, line 19
def self.camelized_key(key)
  key.to_s.gsub(/(?:_)([a-z\d]*)/i) { Regexp.last_match[1].capitalize  }.to_sym
end
underscored_hash(hash) click to toggle source
# File lib/uphold/helpers.rb, line 3
def self.underscored_hash(hash)
  Hash[hash.map do |key, val|
    [underscored_key(key), val]
  end]
end
underscored_key(key) click to toggle source
# File lib/uphold/helpers.rb, line 15
def self.underscored_key(key)
  key.to_s.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase.to_sym
end