Class: Underpass::QL::Response
- Inherits:
-
Object
- Object
- Underpass::QL::Response
- Defined in:
- lib/underpass/ql/response.rb
Overview
Parses the JSON body of an Overpass API response into node, way, and relation lookup hashes keyed by element ID.
Instance Method Summary collapse
-
#initialize(api_response) ⇒ Response
constructor
Creates a new response by parsing the API response body.
-
#nodes ⇒ Hash{Integer => Hash}
Returns all node elements as a hash keyed by ID.
-
#relations ⇒ Hash{Integer => Hash}
Returns all relation elements as a hash keyed by ID.
-
#ways ⇒ Hash{Integer => Hash}
Returns all way elements as a hash keyed by ID.
Constructor Details
#initialize(api_response) ⇒ Response
Creates a new response by parsing the API response body.
11 12 13 14 |
# File 'lib/underpass/ql/response.rb', line 11 def initialize(api_response) parsed_json = JSON.parse(api_response.body, symbolize_names: true) @elements = parsed_json[:elements] end |
Instance Method Details
#nodes ⇒ Hash{Integer => Hash}
Returns all node elements as a hash keyed by ID.
19 20 21 |
# File 'lib/underpass/ql/response.rb', line 19 def nodes mapped_hash('node') end |
#relations ⇒ Hash{Integer => Hash}
Returns all relation elements as a hash keyed by ID.
33 34 35 |
# File 'lib/underpass/ql/response.rb', line 33 def relations mapped_hash('relation') end |
#ways ⇒ Hash{Integer => Hash}
Returns all way elements as a hash keyed by ID.
26 27 28 |
# File 'lib/underpass/ql/response.rb', line 26 def ways mapped_hash('way') end |