Class: Underpass::QL::Request
- Inherits:
-
Object
- Object
- Underpass::QL::Request
- Defined in:
- lib/underpass/ql/request.rb
Overview
Prepares the full Overpass QL query string from a user query, bounding box, and configuration options.
Supports both bounding-box and named-area query templates.
Constant Summary collapse
- QUERY_TEMPLATE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
<<-TEMPLATE [out:json][timeout:TIMEOUT]BBOX; ( QUERY ); out body; RECURSE out skel qt; TEMPLATE
- AREA_QUERY_TEMPLATE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
<<-TEMPLATE [out:json][timeout:TIMEOUT]; area["name"="AREA_NAME"]->.searchArea; ( QUERY(area.searchArea); ); out body; RECURSE out skel qt; TEMPLATE
Instance Method Summary collapse
-
#initialize(query, bbox = nil, recurse: '>', area_name: nil) ⇒ Request
constructor
Creates a new request.
-
#to_query ⇒ String
Converts the request into a complete Overpass QL query string.
Constructor Details
#initialize(query, bbox = nil, recurse: '>', area_name: nil) ⇒ Request
Creates a new request.
39 40 41 42 43 44 |
# File 'lib/underpass/ql/request.rb', line 39 def initialize(query, bbox = nil, recurse: '>', area_name: nil) @overpass_query = query @global_bbox = bbox ? "[#{bbox}]" : '' @recurse = recurse @area_name = area_name end |
Instance Method Details
#to_query ⇒ String
Converts the request into a complete Overpass QL query string.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/underpass/ql/request.rb', line 49 def to_query template = @area_name ? AREA_QUERY_TEMPLATE : QUERY_TEMPLATE timeout = Underpass.configuration.timeout.to_s result = template.sub('TIMEOUT', timeout) result = result.sub('AREA_NAME', @area_name) if @area_name result = result.sub('BBOX', @global_bbox) unless @area_name result.sub('QUERY', @overpass_query) .sub('RECURSE', recurse_statement) end |