def trackables(self, trackables): if type(trackables) is Trackable: self._trackables = [trackables] elif type(trackables) is not list: raise ValueError("Passed object is not list") else: self._trackables = trackables
def location(self, location): if type(location) is str: location = Point.from_string(location) elif type(location) is not Point: raise ValueError( "Passed object is not Point instance nor string containing coordinates." ) self._location = location
def hidden(self, hidden): if type(hidden) is str: hidden = Util.parse_date(hidden) elif type(hidden) is not datetime.date: raise ValueError( "Passed object is not datetime.date instance nor string containing a date." ) self._hidden = hidden
def size(self, size): size = size.strip().lower() if size in self._possible_sizes.values(): # try to search in values self._size = size elif size in self._possible_sizes.keys( ): # not in values => it must be a key self._size = self._possible_sizes[size] else: raise ValueError("Size '{}' is not possible.".format(size))
def attributes(self, attributes): if type(attributes) is not dict: raise ValueError("Attribues is not dict.") self._attributes = {} for name, allowed in attributes.items(): name = name.strip().lower() if name in self._possible_attributes: self._attributes[name] = allowed else: logging.warning("Unknown attribute '%s', ignoring.", name)
def cache_type(self, cache_type): cache_type = cache_type.replace(" Geocache", "") # with space! cache_type = cache_type.replace(" Cache", "") # with space! cache_type = cache_type.strip() # walk trough each type and its synonyms for key, value in self._possible_types.items(): for synonym in value: if cache_type.lower() == synonym.lower(): self._cache_type = self._possible_types[key][0] return raise ValueError("Cache type '{}' is not possible.".format(cache_type))
def terrain(self, terrain): terrain = float(terrain) if terrain < 1 or terrain > 5 or terrain * 10 % 5 != 0: # X.0 or X.5 raise ValueError( "Terrain must be from 1 to 5 and divisible by 0.5.") self._terrain = terrain
def difficulty(self, difficulty): difficulty = float(difficulty) if difficulty < 1 or difficulty > 5 or difficulty * 10 % 5 != 0: # X.0 or X.5 raise ValueError( "Difficulty must be from 1 to 5 and divisible by 0.5.") self._difficulty = difficulty
def geocaching(self, geocaching): if not hasattr(geocaching, "load_cache"): raise ValueError( "Passed object (type: '{}') doesn't contain 'load_cache' method." .format(type(geocaching))) self._geocaching = geocaching
def wp(self, wp): wp = str(wp).upper().strip() if not wp.startswith("GC"): raise ValueError( "Waypoint '{}' doesn't start with 'GC'.".format(wp)) self._wp = wp
def size(self, size): size = size.strip().lower() if size not in self._possible_sizes: raise ValueError("Size '{}' is not possible.".format(size)) self._size = size
def cache_type(self, cache_type): cache_type = cache_type.strip().title() cache_type = cache_type.replace("Geocache", "Cache") if cache_type not in self._possible_types: raise ValueError("Cache type '{}' is not possible.".format(cache_type)) self._cache_type = cache_type
def tid(self, tid): tid = str(tid).upper().strip() if not tid.startswith("TB"): raise ValueError( "Trackable ID '{}' doesn't start with 'TB'.".format(tid)) self._tid = tid