Skip to content

Commit

Permalink
modified Geocoder class to have some more intuitive methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ddd1600 committed Mar 14, 2016
1 parent d722437 commit 922d7de
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/geocoder/results/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def city
return nil # no appropriate components found
end

def state
def state_name
if state = address_components_of_type(:administrative_area_level_1).first
state['long_name']
end
Expand All @@ -40,12 +40,20 @@ def state_code
state['short_name']
end
end

def state
state_code
end

def sub_state
if state = address_components_of_type(:administrative_area_level_2).first
state['long_name']
end
end

def county
sub_state.gsub(" County")
end

def sub_state_code
if state = address_components_of_type(:administrative_area_level_2).first
Expand All @@ -70,6 +78,10 @@ def postal_code
postal['long_name']
end
end

def zip
postal_code
end

def route
if route = address_components_of_type(:route).first
Expand Down Expand Up @@ -120,5 +132,20 @@ def geometry
def precision
geometry['location_type'] if geometry
end

def partial_match
@data['partial_match']
end

def place_id
@data['place_id']
end

def viewport
viewport = geometry['viewport'] || fail
south, west = %w(lat lng).map { |c| viewport['southwest'][c] }
north, east = %w(lat lng).map { |c| viewport['northeast'][c] }
[south, west, north, east]
end
end
end

0 comments on commit 922d7de

Please sign in to comment.