Module: BosClient::Helper
- Included in:
- Request
- Defined in:
- lib/bos_client/helper.rb
Instance Method Summary collapse
- #snake_hash(value) ⇒ Object
- #snake_hash_keys(value) ⇒ Object
- #underscore(string) ⇒ Object
- #underscore_key(k) ⇒ Object
Instance Method Details
#snake_hash(value) ⇒ Object
16 17 18 |
# File 'lib/bos_client/helper.rb', line 16 def snake_hash(value) Hash[value.map { |k, v| [underscore_key(k), snake_hash_keys(v)] }] end |
#snake_hash_keys(value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/bos_client/helper.rb', line 5 def snake_hash_keys value case value when Array value.map { |v| snake_hash_keys(v) } when Hash snake_hash(value) else value end end |
#underscore(string) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/bos_client/helper.rb', line 30 def underscore(string) string.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end |
#underscore_key(k) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/bos_client/helper.rb', line 20 def underscore_key(k) if k.is_a? Symbol underscore(k.to_s).to_sym elsif k.is_a? String underscore(k) else k end end |