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:



125
126
127
128
# File 'lib/nominatim/search.rb', line 125

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:



107
108
109
110
# File 'lib/nominatim/search.rb', line 107

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

#city(city) ⇒ Nominatim::Search

City string to search for.

Parameters:

  • city (String)

    city string

Returns:



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

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

#country(country) ⇒ Nominatim::Search

Country string to search for.

Parameters:

  • country (String)

    country string

Returns:



65
66
67
68
# File 'lib/nominatim/search.rb', line 65

def country(country)
  @criteria[:country] = country
  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:



84
85
86
87
88
89
90
91
# File 'lib/nominatim/search.rb', line 84

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

#county(county) ⇒ Nominatim::Search

County string to search for.

Parameters:

  • county (String)

    county string

Returns:



47
48
49
50
# File 'lib/nominatim/search.rb', line 47

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

#each(&block) ⇒ Object

Iterates over the search results.



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

def each(&block)
  @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:



134
135
136
137
138
139
140
141
# File 'lib/nominatim/search.rb', line 134

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

#featuretype(type) ⇒ Nominatim::Search

Limit results to certain type, instead of trying to match all possible matches.

Possible values:

  • settlement

  • country

  • city

  • state

This feature is not in official Nominatim documentation.

Parameters:

  • type

    Type to restrict to

Returns:



165
166
167
168
# File 'lib/nominatim/search.rb', line 165

def featuretype(type)
  @criteria[:featuretype] = type
  self
end

#limit(limit) ⇒ Nominatim::Search

Limit the number of returned results.

Parameters:

  • limit (Integer)

Returns:



147
148
149
150
# File 'lib/nominatim/search.rb', line 147

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

#polygon(bool) ⇒ Nominatim::Search

Output polygon outlines for items found.

Parameters:

  • bool (true, false)

Returns:



116
117
118
119
# File 'lib/nominatim/search.rb', line 116

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

#postalcode(postalcode) ⇒ Nominatim::Search

Postal code string to search for.

Parameters:

  • postalcode (String)

    postalcode string

Returns:



74
75
76
77
# File 'lib/nominatim/search.rb', line 74

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

#query(q) ⇒ Nominatim::Search

Query string to search for.

Parameters:

  • q (String)

    Query string

Returns:



20
21
22
23
# File 'lib/nominatim/search.rb', line 20

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

#state(state) ⇒ Nominatim::Search

State string to search for.

Parameters:

  • state (String)

    state string

Returns:



56
57
58
59
# File 'lib/nominatim/search.rb', line 56

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

#street(street) ⇒ Nominatim::Search

Street string to search for.

Parameters:

  • street (String)

    Street string

Returns:



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

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

#viewbox(viewbox) ⇒ Nominatim::Search

The preferred area to find search results.

Parameters:

  • viewbox (Array<String>)

Returns:



97
98
99
100
# File 'lib/nominatim/search.rb', line 97

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