Class: Underpass::QL::QueryAnalyzer

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

Overview

Analyzes an Overpass QL query string to determine which element types (node, way, relation) are requested.

Used internally by Query to pass type hints to Matcher.

Constant Summary collapse

MATCH_TYPES =

Returns the recognized OSM element types.

Returns:

  • (Array<String>)

    the recognized OSM element types

%w[node way relation].freeze

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ QueryAnalyzer

Creates a new analyzer for the given query string.

Parameters:

  • query (String, nil)

    an Overpass QL query string



16
17
18
# File 'lib/underpass/ql/query_analyzer.rb', line 16

def initialize(query)
  @query = query
end

Instance Method Details

#requested_typesArray<String>

Returns the element types requested in the query.

Falls back to all types when the query is empty or contains no recognized type keywords.

Returns:

  • (Array<String>)

    requested types (e.g. +[“node”, “way”]+)



26
27
28
29
30
31
# File 'lib/underpass/ql/query_analyzer.rb', line 26

def requested_types
  return MATCH_TYPES if empty_query?

  types = parse_types_from_query
  types.empty? ? MATCH_TYPES : types
end