Class: Underpass::QL::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/underpass/ql/parser.rb

Overview

Deals with parsing the API request response into easily digestable objects which are then returned as matches

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Parser

Returns a new instance of Parser.



8
9
10
11
# File 'lib/underpass/ql/parser.rb', line 8

def initialize(response)
  @response = response
  @matches = []
end

Instance Method Details

#matchesObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/underpass/ql/parser.rb', line 23

def matches
  @nodes.each_value do |node|
    @matches << point_from_node(node) if node.key?(:tags)
  end

  @ways.each_value do |way|
    @matches << way_matches(way) if way.key?(:tags)
  end

  @matches
end

#parseObject



13
14
15
16
17
18
19
20
21
# File 'lib/underpass/ql/parser.rb', line 13

def parse
  parsed_json = JSON.parse(@response.body, symbolize_names: true)
  elements = parsed_json[:elements]

  @nodes = extract_indexed_nodes(elements)
  @ways = extract_indexed_ways(elements)

  self
end