Class: Elmas::Parser
- Inherits:
-
Object
- Object
- Elmas::Parser
- Defined in:
- lib/elmas/parser.rb
Instance Attribute Summary collapse
-
#parsed_json ⇒ Object
Returns the value of attribute parsed_json.
Instance Method Summary collapse
- #error_message ⇒ Object
- #first_result ⇒ Object
-
#initialize(json) ⇒ Parser
constructor
A new instance of Parser.
- #metadata ⇒ Object
- #next_page_url ⇒ Object
- #result ⇒ Object
- #results ⇒ Object
Constructor Details
#initialize(json) ⇒ Parser
Returns a new instance of Parser.
7 8 9 10 11 12 13 |
# File 'lib/elmas/parser.rb', line 7 def initialize(json) @parsed_json = JSON.parse(json) rescue JSON::ParserError => e Elmas.error "There was an error parsing the response" Elmas.error "#{e.class}: #{e.}" @error_message = "#{e.class}: #{e.}" end |
Instance Attribute Details
#parsed_json ⇒ Object
Returns the value of attribute parsed_json.
5 6 7 |
# File 'lib/elmas/parser.rb', line 5 def parsed_json @parsed_json end |
Instance Method Details
#error_message ⇒ Object
31 32 33 34 35 |
# File 'lib/elmas/parser.rb', line 31 def @error_message ||= begin parsed_json["error"]["message"]["value"] if parsed_json["error"] end end |
#first_result ⇒ Object
37 38 39 |
# File 'lib/elmas/parser.rb', line 37 def first_result results[0] end |
#metadata ⇒ Object
19 20 21 |
# File 'lib/elmas/parser.rb', line 19 def result["__metadata"] if result && result["__metadata"] end |
#next_page_url ⇒ Object
27 28 29 |
# File 'lib/elmas/parser.rb', line 27 def next_page_url result && result["__next"] end |
#result ⇒ Object
23 24 25 |
# File 'lib/elmas/parser.rb', line 23 def result parsed_json["d"] end |
#results ⇒ Object
15 16 17 |
# File 'lib/elmas/parser.rb', line 15 def results result["results"] if result && result["results"] end |