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
15 16 17 |
# File 'lib/bos_client/helper.rb', line 15 def snake_hash(value) Hash[value.map { |k, v| [underscore_key(k), snake_hash_keys(v)] }] end |
#snake_hash_keys(value) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/bos_client/helper.rb', line 4 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
29 30 31 32 33 34 35 |
# File 'lib/bos_client/helper.rb', line 29 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
19 20 21 22 23 24 25 26 27 |
# File 'lib/bos_client/helper.rb', line 19 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 |