Class: Location::Finder
- Inherits:
-
Object
- Object
- Location::Finder
- Defined in:
- lib/location/finder.rb
Defined Under Namespace
Classes: Address
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#postal_code ⇒ Object
Returns the value of attribute postal_code.
-
#service ⇒ Object
Returns the value of attribute service.
Class Method Summary collapse
Instance Method Summary collapse
- #find ⇒ Object
-
#initialize(postal_code, service) ⇒ Finder
constructor
A new instance of Finder.
- #successful? ⇒ Boolean
Constructor Details
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
4 5 6 |
# File 'lib/location/finder.rb', line 4 def address @address end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
4 5 6 |
# File 'lib/location/finder.rb', line 4 def error @error end |
#postal_code ⇒ Object
Returns the value of attribute postal_code.
3 4 5 |
# File 'lib/location/finder.rb', line 3 def postal_code @postal_code end |
#service ⇒ Object
Returns the value of attribute service.
3 4 5 |
# File 'lib/location/finder.rb', line 3 def service @service end |
Class Method Details
.build(postal_code) ⇒ Object
6 7 8 |
# File 'lib/location/finder.rb', line 6 def self.build(postal_code) new(postal_code, Location.configuration.default_service.new) end |
.find(postal_code, &block) ⇒ Object
10 11 12 |
# File 'lib/location/finder.rb', line 10 def self.find(postal_code, &block) build(postal_code).find(&block) end |
Instance Method Details
#find ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/location/finder.rb', line 20 def find service.fetch(postal_code, address) @success = true rescue Services::Error => error @error = error. @success = false ensure @address.freeze yield self if block_given? end |
#successful? ⇒ Boolean
31 32 33 |
# File 'lib/location/finder.rb', line 31 def successful? @success end |