Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
slawek87 committed Nov 25, 2014
1 parent dd5be76 commit 478da83
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions geolocation/google_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

class GoogleMaps(object):
"""To find address use: GoogleMaps.search(location=full_address)."""
_geocode_parser = GeocodeParser()
_data = set()
geocode = GeocodeParser()
data = set()

log = logging.Logger('google_maps')

Expand All @@ -22,53 +22,50 @@ def __repr__(self):
return '<GoogleMaps %s >' % self.all()

def clear(self):
self._data = set()
self.data = set()

@staticmethod
def validate(data):
"""Method should always returns false when data doesn't have city value."""
if not data.city:
def validate(location):
"""Method should always returns false when location doesn't have city value."""
if not location.city:
return False

return True

def _to_python(self, json_results):
"""Method should converts json_results to python object."""
for item in json_results:
self._geocode_parser.json_data = item
self.geocode.json_data = item

location = LocationModel()

location.city = self._geocode_parser.get_city()
location.route = self._geocode_parser.get_route()
location.street_number = self._geocode_parser.get_street_number()
location.postal_code = self._geocode_parser.get_postal_code()
location.city = self.geocode.get_city()
location.route = self.geocode.get_route()
location.street_number = self.geocode.get_street_number()
location.postal_code = self.geocode.get_postal_code()

location.country = self._geocode_parser.get_country()
location.country_shortcut =\
self._geocode_parser.get_country_shortcut()
location.country = self.geocode.get_country()
location.country_shortcut = self.geocode.get_country_shortcut()

location.administrative_area =\
self._geocode_parser.get_administrative_area()
location.administrative_area = self.geocode.get_administrative_area()

location.lat = self._geocode_parser.get_lat()
location.lng = self._geocode_parser.get_lng()
location.lat = self.geocode.get_lat()
location.lng = self.geocode.get_lng()

location.formatted_address =\
self._geocode_parser.get_formatted_address()
location.formatted_address = self.geocode.get_formatted_address()

if self.validate(location):
self._data.add(location)
self.data.add(location)

return self.all()

def all(self):
"""Method returns location list."""
return list(self._data)
return list(self.data)

def first(self):
if self._data:
return list(self._data)[0]
if self.data:
return list(self.data)[0]

return None

Expand Down

0 comments on commit 478da83

Please sign in to comment.