Module: IGMarkets::ResponseParser
- Defined in:
- lib/ig_markets/response_parser.rb
Overview
Contains methods for parsing responses received from the IG Markets API.
Class Method Summary collapse
-
.camel_case_to_snake_case(camel_case) ⇒ String
Converts a camel case string to a snake case string.
-
.parse(response) ⇒ Hash, ...
Parses the specified value that was returned from a call to the IG Markets API.
Class Method Details
.camel_case_to_snake_case(camel_case) ⇒ String
Converts a camel case string to a snake case string.
34 35 36 |
# File 'lib/ig_markets/response_parser.rb', line 34 def camel_case_to_snake_case(camel_case) camel_case.to_s.gsub(/([a-z])([A-Z])/, '\1_\2').gsub(/([A-Z])([A-Z])([a-z])/, '\1_\2\3').downcase end |
.parse(response) ⇒ Hash, ...
Parses the specified value that was returned from a call to the IG Markets API.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ig_markets/response_parser.rb', line 16 def parse(response) case response when Hash response.each_with_object({}) do |(key, value), new_hash| new_hash[camel_case_to_snake_case(key).to_sym] = parse(value) end when Array response.map { |item| parse item } else response end end |