Class: Geocodio::AddressSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/geocodio/address_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, *addresses, input: nil) ⇒ AddressSet

Returns a new instance of AddressSet.


14
15
16
17
18
# File 'lib/geocodio/address_set.rb', line 14

def initialize(query, *addresses, input: nil)
  @query           = query
  @addresses       = addresses
  @formatted_input = input
end

Instance Attribute Details

#queryString (readonly)

Returns the query that retrieved this result set.

Returns:

  • (String)

    the original query


12
13
14
# File 'lib/geocodio/address_set.rb', line 12

def query
  @query
end

Instance Method Details

#bestGeocodio::Address

Returns the result that geocod.io deemed the most accurate for the query.

Returns:


27
28
29
30
31
32
# File 'lib/geocodio/address_set.rb', line 27

def best
  best = @addresses.find { |address| address.to_s == @formatted_input }
  return best if best

  max_by(&:accuracy)
end

#each(&block) ⇒ Object


20
21
22
# File 'lib/geocodio/address_set.rb', line 20

def each(&block)
  @addresses.each(&block)
end

#empty?Boolean

Returns whether or not there are any addresses in this result set.

Returns:

  • (Boolean)

    if there were any results returned by Geocodio


44
45
46
# File 'lib/geocodio/address_set.rb', line 44

def empty?
  @addresses.empty?
end

#sizeInteger

Returns the number of addresses contained in this result set.

Returns:

  • (Integer)

    the number of addresses


37
38
39
# File 'lib/geocodio/address_set.rb', line 37

def size
  @addresses.size
end