Class: Underpass::Matcher

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

Overview

Extracts matching elements from an Overpass API response.

A “match” is a response element that has a tags key, indicating it is a tagged OSM element rather than a bare geometry node. Each match is converted into a Feature with the appropriate RGeo geometry.

Instance Method Summary collapse

Constructor Details

#initialize(response, requested_types = nil) ⇒ Matcher

Creates a new matcher for the given response.

Parameters:

  • response (QL::Response)

    a parsed API response

  • requested_types (Array<String>, nil) (defaults to: nil)

    element types to include (e.g. +[“node”, “way”]+). Defaults to all types when nil.



15
16
17
18
19
20
# File 'lib/underpass/matcher.rb', line 15

def initialize(response, requested_types = nil)
  @nodes     = response.nodes
  @ways      = response.ways
  @relations = response.relations
  @requested_types = requested_types || %w[node way relation]
end

Instance Method Details

#lazy_matchesEnumerator::Lazy<Feature>

Returns a lazy enumerator of matched features.

Returns:

  • (Enumerator::Lazy<Feature>)

    lazy enumerator of features



32
33
34
# File 'lib/underpass/matcher.rb', line 32

def lazy_matches
  tagged_elements.lazy.flat_map { |element| features_for(element) }
end

#matchesArray<Feature>

Returns all matched features as an array.

Returns:

  • (Array<Feature>)

    the matched features



25
26
27
# File 'lib/underpass/matcher.rb', line 25

def matches
  @matches ||= lazy_matches.to_a
end