Module: Uphold::Helpers
- Defined in:
- lib/uphold/helpers.rb
Class Method Summary collapse
- .camelized_hash(hash) ⇒ Object
- .camelized_key(key) ⇒ Object
- .underscored_hash(hash) ⇒ Object
- .underscored_key(key) ⇒ Object
Class Method Details
.camelized_hash(hash) ⇒ Object
9 10 11 12 13 |
# 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) ⇒ Object
19 20 21 |
# 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) ⇒ Object
3 4 5 6 7 |
# 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) ⇒ Object
15 16 17 |
# 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 |