Class: Underpass::Matcher
- Inherits:
-
Object
- Object
- Underpass::Matcher
- 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
-
#initialize(response, requested_types = nil) ⇒ Matcher
constructor
Creates a new matcher for the given response.
-
#lazy_matches ⇒ Enumerator::Lazy<Feature>
Returns a lazy enumerator of matched features.
-
#matches ⇒ Array<Feature>
Returns all matched features as an array.
Constructor Details
#initialize(response, requested_types = nil) ⇒ Matcher
Creates a new matcher for the given response.
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_matches ⇒ Enumerator::Lazy<Feature>
Returns a lazy enumerator of matched features.
32 33 34 |
# File 'lib/underpass/matcher.rb', line 32 def lazy_matches tagged_elements.lazy.flat_map { |element| features_for(element) } end |
#matches ⇒ Array<Feature>
Returns all matched features as an array.
25 26 27 |
# File 'lib/underpass/matcher.rb', line 25 def matches @matches ||= lazy_matches.to_a end |