Class: Nominatim::Search

Inherits:
Client
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nominatim/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#get

Constructor Details

#initializeSearch

Returns a new instance of Search.



6
7
8
# File 'lib/nominatim/search.rb', line 6

def initialize
  @criteria = {}
end

Instance Attribute Details

#criteriaObject (readonly)

Returns the value of attribute criteria.



4
5
6
# File 'lib/nominatim/search.rb', line 4

def criteria
  @criteria
end

Instance Method Details

#address_details(bool) ⇒ Nominatim::Search

Include a breakdown of the address into elements.

Parameters:

  • bool (true, false)

Returns:



89
90
91
92
# File 'lib/nominatim/search.rb', line 89

def address_details(bool)
  @criteria[:addressdetails] = bool ? 1 : 0
  self
end

#bounded(bool) ⇒ Nominatim::Search

Restrict the results to only items contained with the bounding box.

Parameters:

  • bool (true, false)

Returns:

See Also:



71
72
73
74
# File 'lib/nominatim/search.rb', line 71

def bounded(bool)
  @criteria[:bounded] = bool ? 1 : 0
  self
end

#country_codes(codes) ⇒ Nominatim::Search

Limit search results to a specific country (or a list of countries).

Parameters:

  • codes (Array<String>, String)

Returns:

See Also:



48
49
50
51
52
53
54
55
# File 'lib/nominatim/search.rb', line 48

def country_codes(codes)
  if codes.instance_of? Array
    @criteria[:countrycodes] = codes.join(',')
  else
    @criteria[:countrycodes] = codes
  end
  self
end

#each(&block) ⇒ Object

Iterates over the search results.



11
12
13
14
15
# File 'lib/nominatim/search.rb', line 11

def each(&block)
  @criteria.delete(:q) if (@criteria.keys & [:street, :city, :county, :state, :country, :postalcode]).count > 0
  @results ||= get(Nominatim.config.search_url, @criteria).body.map! { |attrs| Nominatim::Place.new(attrs) }
  @results.each(&block)
end

#exclude_place_ids(ids) ⇒ Nominatim::Search

Exclude given place ids from the search result.

Parameters:

  • ids (Array<String>, String)

    Place ids

Returns:



98
99
100
101
102
103
104
105
# File 'lib/nominatim/search.rb', line 98

def exclude_place_ids(ids)
  if ids.instance_of? Array
    @criteria[:exclude_place_ids] = ids.join(',')
  else
    @criteria[:exclude_place_ids] = ids
  end
  self
end

#limit(limit) ⇒ Nominatim::Search

Limit the number of returned results.

Parameters:

  • limit (Integer)

Returns:



111
112
113
114
# File 'lib/nominatim/search.rb', line 111

def limit(limit)
  @criteria[:limit] = limit
  self
end

#polygon(bool) ⇒ Nominatim::Search

Output polygon outlines for items found.

Parameters:

  • bool (true, false)

Returns:



80
81
82
83
# File 'lib/nominatim/search.rb', line 80

def polygon(bool)
  @criteria[:polygon] = bool ? 1 : 0
  self
end

#query(q) ⇒ Nominatim::Search

Query string to search for.

Parameters:

  • q (String)

    Query string

Returns:



38
39
40
41
# File 'lib/nominatim/search.rb', line 38

def query(q)
  @criteria[:q] = q
  self
end

#street(housenumber, streetname) ⇒ Object

Structured street search request



29
30
31
32
# File 'lib/nominatim/search.rb', line 29

def street housenumber, streetname
  @criteria[:street] = "#{housenumber} #{streetname}"
  self
end

#viewbox(viewbox) ⇒ Nominatim::Search

The preferred area to find search results.

Parameters:

  • viewbox (Array<String>)

Returns:



61
62
63
64
# File 'lib/nominatim/search.rb', line 61

def viewbox(viewbox)
  @criteria[:viewbox] = viewbox.join(',')
  self
end