Class: Lotr::Response
- Inherits:
-
Object
- Object
- Lotr::Response
- Defined in:
- lib/lotr/response.rb
Class Method Summary collapse
-
.parse_to_object!(hash) ⇒ Object
Parse the hash, convert the keys to snake_case and define a method dynamically for each key.
Class Method Details
.parse_to_object!(hash) ⇒ Object
Parse the hash, convert the keys to snake_case and define a method dynamically for each key
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/lotr/response.rb', line 4 def self.parse_to_object!(hash) hash.transform_keys! do |k| # convert the key to string k = k.to_s # remove the leading underscore from the key e.g _id => id k = k.gsub(/^_/, "") # convert the key to snake case k.underscore! k end # define a method for every key to access their respective value OpenStruct.new(hash) end |