Class: Underpass::QL::Response

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(api_response) ⇒ Response

Creates a new response by parsing the API response body.

Parameters:

  • api_response (Net::HTTPResponse)

    the raw HTTP response



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

#nodesHash{Integer => Hash}

Returns all node elements as a hash keyed by ID.

Returns:

  • (Hash{Integer => Hash})

    node elements



19
20
21
# File 'lib/underpass/ql/response.rb', line 19

def nodes
  mapped_hash('node')
end

#relationsHash{Integer => Hash}

Returns all relation elements as a hash keyed by ID.

Returns:

  • (Hash{Integer => Hash})

    relation elements



33
34
35
# File 'lib/underpass/ql/response.rb', line 33

def relations
  mapped_hash('relation')
end

#waysHash{Integer => Hash}

Returns all way elements as a hash keyed by ID.

Returns:

  • (Hash{Integer => Hash})

    way elements



26
27
28
# File 'lib/underpass/ql/response.rb', line 26

def ways
  mapped_hash('way')
end