Class: SimpleGeolocation::Geocoder

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_geolocation/geocoder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#locationObject (readonly)

Returns the value of attribute location.



4
5
6
# File 'lib/simple_geolocation/geocoder.rb', line 4

def location
  @location
end

#raw_locationObject (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

#successObject (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

.keysObject



7
8
9
# File 'lib/simple_geolocation/geocoder.rb', line 7

def self.keys
  Location::ATTRIBUTES + [:completeness]
end

Instance Method Details

#address?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/simple_geolocation/geocoder.rb', line 23

def address?
  !zip?
end

#attributesObject



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.

Returns:

  • (Boolean)


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