Module: Talkgh::Keys
Instance Method Summary collapse
- #attribute_key(k) ⇒ Object
- #camelcase(hash) ⇒ Object
- #camelcase_key(k) ⇒ Object
- #hyphenate(hash) ⇒ Object
- #hyphenate_key(k) ⇒ Object
Instance Method Details
#attribute_key(k) ⇒ Object
38 39 40 41 42 |
# File 'lib/talkgh/keys.rb', line 38 def attribute_key(k) return k if k.is_a?(Symbol) ATTRIBUTE_KEYS[k] end |
#camelcase(hash) ⇒ Object
9 10 11 |
# File 'lib/talkgh/keys.rb', line 9 def camelcase(hash) hash.transform_keys { |k| camelcase_key(k) } end |
#camelcase_key(k) ⇒ Object
26 27 28 |
# File 'lib/talkgh/keys.rb', line 26 def camelcase_key(k) k.to_s.gsub(/_(\w)/) { $1.upcase } end |
#hyphenate(hash) ⇒ Object
5 6 7 |
# File 'lib/talkgh/keys.rb', line 5 def hyphenate(hash) hash.transform_keys { |k| hyphenate_key(k) } end |
#hyphenate_key(k) ⇒ Object
22 23 24 |
# File 'lib/talkgh/keys.rb', line 22 def hyphenate_key(k) k.to_s.tr('_', '-') end |