Class: Geocodio::AddressSet
- Inherits:
-
Object
- Object
- Geocodio::AddressSet
- Includes:
- Enumerable
- Defined in:
- lib/geocodio/address_set.rb
Instance Attribute Summary collapse
-
#query ⇒ String
readonly
Returns the query that retrieved this result set.
Instance Method Summary collapse
-
#best ⇒ Geocodio::Address
Returns the result that geocod.io deemed the most accurate for the query.
- #each(&block) ⇒ Object
-
#empty? ⇒ Boolean
Returns whether or not there are any addresses in this result set.
-
#initialize(query, *addresses, input: nil) ⇒ AddressSet
constructor
A new instance of AddressSet.
-
#size ⇒ Integer
Returns the number of addresses contained in this result set.
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
#query ⇒ String (readonly)
Returns the query that retrieved this result set.
12 13 14 |
# File 'lib/geocodio/address_set.rb', line 12 def query @query end |
Instance Method Details
#best ⇒ Geocodio::Address
Returns the result that geocod.io deemed the most accurate for the query.
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.
44 45 46 |
# File 'lib/geocodio/address_set.rb', line 44 def empty? @addresses.empty? end |
#size ⇒ Integer
Returns the number of addresses contained in this result set.
37 38 39 |
# File 'lib/geocodio/address_set.rb', line 37 def size @addresses.size end |