Class: SimpleGeolocation::Geocoder
- Inherits:
-
Object
- Object
- SimpleGeolocation::Geocoder
- Defined in:
- lib/simple_geolocation/geocoder.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#raw_location ⇒ Object
readonly
Returns the value of attribute raw_location.
-
#success ⇒ Object
(also: #success?)
readonly
Returns the value of attribute success.
Class Method Summary collapse
Instance Method Summary collapse
- #address? ⇒ Boolean
- #attributes ⇒ Object
- #geocode! ⇒ Object
-
#initialize(raw_location) ⇒ Geocoder
constructor
A new instance of Geocoder.
- #success! ⇒ Object
-
#zip? ⇒ Boolean
Only brazilian zipcode is supported.
Constructor Details
#initialize(raw_location) ⇒ Geocoder
Returns a new instance of Geocoder.
13 14 15 |
# File 'lib/simple_geolocation/geocoder.rb', line 13 def initialize(raw_location) @raw_location = raw_location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
4 5 6 |
# File 'lib/simple_geolocation/geocoder.rb', line 4 def location @location end |
#raw_location ⇒ Object (readonly)
Returns the value of attribute raw_location.
4 5 6 |
# File 'lib/simple_geolocation/geocoder.rb', line 4 def raw_location @raw_location end |
#success ⇒ Object (readonly) Also known as: success?
Returns the value of attribute success.
4 5 6 |
# File 'lib/simple_geolocation/geocoder.rb', line 4 def success @success end |
Class Method Details
.keys ⇒ Object
7 8 9 |
# File 'lib/simple_geolocation/geocoder.rb', line 7 def self.keys Location::ATTRIBUTES + [:completeness] end |
Instance Method Details
#address? ⇒ Boolean
23 24 25 |
# File 'lib/simple_geolocation/geocoder.rb', line 23 def address? !zip? end |
#attributes ⇒ Object
37 38 39 |
# File 'lib/simple_geolocation/geocoder.rb', line 37 def attributes @attributes ||= Hash[self.class.keys.map { |k| [k, send(k)] }] end |
#geocode! ⇒ Object
27 28 29 30 31 |
# File 'lib/simple_geolocation/geocoder.rb', line 27 def geocode! @geoworker = Geoworkers::Base.instantiate_geoworker_based_on(self) @geoworker.process! @location = @geoworker.location end |
#success! ⇒ Object
33 34 35 |
# File 'lib/simple_geolocation/geocoder.rb', line 33 def success! @success = true end |
#zip? ⇒ Boolean
Only brazilian zipcode is supported.
18 19 20 21 |
# File 'lib/simple_geolocation/geocoder.rb', line 18 def zip? number = @raw_location.to_s.gsub(/(\.|\D|\-|\s)/, '') number.size == 8 end |