Class: GeocoderGoogleResult

Inherits:
Object
  • Object
show all
Defined in:
app/models/geocoder_google_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(google_result) ⇒ GeocoderGoogleResult

Returns a GeocoderGoogleResult initialized with the specified Google geocoding results.

Attributes

  • google_result - a hash of Google geocoding results

Examples

white_house = GoogleMapsGeocoder.new '1600 Pennsylvania Washington'
white_house.formatted_address
 => "1600 Pennsylvania Ave NW, Washington D.C., DC 20500, USA"


27
28
29
30
# File 'app/models/geocoder_google_result.rb', line 27

def initialize google_result
  @json = google_result
  @city, @country_short_name, @country_long_name, @county, @formatted_address, @formatted_street_address, @lat, @lng, @postal_code, @state_long_name, @state_short_name = parse_city, parse_country_short_name, parse_country_long_name, parse_county, parse_formatted_address, parse_formatted_street_address, parse_lat, parse_lng, parse_postal_code, parse_state_long_name, parse_state_short_name
end

Instance Attribute Details

#cityObject (readonly)

Self-explanatory



12
13
14
# File 'app/models/geocoder_google_result.rb', line 12

def city
  @city
end

#country_long_nameObject (readonly)

Self-explanatory



12
13
14
# File 'app/models/geocoder_google_result.rb', line 12

def country_long_name
  @country_long_name
end

#country_short_nameObject (readonly)

Self-explanatory



12
13
14
# File 'app/models/geocoder_google_result.rb', line 12

def country_short_name
  @country_short_name
end

#countyObject (readonly)

Self-explanatory



12
13
14
# File 'app/models/geocoder_google_result.rb', line 12

def county
  @county
end

#formatted_addressObject (readonly)

Returns the complete formatted address with standardized abbreviations.



8
9
10
# File 'app/models/geocoder_google_result.rb', line 8

def formatted_address
  @formatted_address
end

#formatted_street_addressObject (readonly)

Returns the formatted street address with standardized abbreviations.



10
11
12
# File 'app/models/geocoder_google_result.rb', line 10

def formatted_street_address
  @formatted_street_address
end

#latObject (readonly)

Self-explanatory



12
13
14
# File 'app/models/geocoder_google_result.rb', line 12

def lat
  @lat
end

#lngObject (readonly)

Self-explanatory



12
13
14
# File 'app/models/geocoder_google_result.rb', line 12

def lng
  @lng
end

#postal_codeObject (readonly)

Self-explanatory



12
13
14
# File 'app/models/geocoder_google_result.rb', line 12

def postal_code
  @postal_code
end

#state_long_nameObject (readonly)

Self-explanatory



12
13
14
# File 'app/models/geocoder_google_result.rb', line 12

def state_long_name
  @state_long_name
end

#state_short_nameObject (readonly)

Self-explanatory



12
13
14
# File 'app/models/geocoder_google_result.rb', line 12

def state_short_name
  @state_short_name
end

Instance Method Details

#exact_match?Boolean

Returns true if the address Google returns is an exact match.

Examples

white_house = GoogleMapsGeocoder.new('1600 Pennsylvania Ave')
white_house.exact_match?
 => true

Returns:

  • (Boolean)


41
42
43
# File 'app/models/geocoder_google_result.rb', line 41

def exact_match?
  ! self.partial_match?
end

#partial_match?Boolean

Returns true if the address Google returns isn’t an exact match.

Examples

white_house = GoogleMapsGeocoder.new('1600 Pennsylvania Washington')
white_house.exact_match?
 => false

Returns:

  • (Boolean)


52
53
54
# File 'app/models/geocoder_google_result.rb', line 52

def partial_match?
  @json['partial_match'] == true
end