Module: EVEApi::Util
- Defined in:
- lib/eveapi/util.rb
Overview
Utility methods
Instance Method Summary collapse
-
#convert_hash_keys(value) ⇒ Array, Hash
Symbolize and underscore all
Hash
keys. -
#json_get(url, args = {}) ⇒ Hash
Make a GET request, parse JSON if present, and process the result.
-
#underscore_key(k) ⇒ Symbol
Make a symbolized and underscored version of a
Symbol
orString
.
Instance Method Details
#convert_hash_keys(value) ⇒ Array, Hash
Symbolize and underscore all Hash
keys
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/eveapi/util.rb', line 116 def convert_hash_keys(value) case value when Array value.map { |v| convert_hash_keys(v) } when Hash Hash[value.map { |k, v| [underscore_key(k), convert_hash_keys(v)] }] else value end end |
#json_get(url, args = {}) ⇒ Hash
Make a GET request, parse JSON if present, and process the result
99 100 101 102 |
# File 'lib/eveapi/util.rb', line 99 def json_get(url, args = {}) http = Excon.get(url, args).body convert_hash_keys(Crack::JSON.parse http) end |
#underscore_key(k) ⇒ Symbol
Make a symbolized and underscored version of a Symbol
or String
108 109 110 |
# File 'lib/eveapi/util.rb', line 108 def underscore_key(k) k.to_s.underscore.to_sym end |