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.
- #ip? ⇒ Boolean
- #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
28 29 30 |
# File 'lib/simple_geolocation/geocoder.rb', line 28 def address? !ip? && !zip? end |
#attributes ⇒ Object
42 43 44 |
# File 'lib/simple_geolocation/geocoder.rb', line 42 def attributes @attributes ||= Hash[self.class.keys.map { |k| [k, send(k)] }] end |
#geocode! ⇒ Object
32 33 34 35 36 |
# File 'lib/simple_geolocation/geocoder.rb', line 32 def geocode! @geoworker = Geoworkers::Base.instantiate_geoworker_based_on(self) @geoworker.process! @location = @geoworker.location end |
#ip? ⇒ Boolean
17 18 19 |
# File 'lib/simple_geolocation/geocoder.rb', line 17 def ip? !!/^(\d+\.){3}\d+$/.match(@raw_location) end |
#success! ⇒ Object
38 39 40 |
# File 'lib/simple_geolocation/geocoder.rb', line 38 def success! @success = true end |
#zip? ⇒ Boolean
Only brazilian zipcode is supported.
22 23 24 25 26 |
# File 'lib/simple_geolocation/geocoder.rb', line 22 def zip? return false if ip? number = @raw_location.to_s.gsub(/(\.|\D|\-|\s)/, '') number.size == 8 end |