Package butler :: Module user
[hide private]
[frames] | no frames]

Source Code for Module butler.user

 1  ''' 
 2  Created on Jul 19, 2011 
 3   
 4  @author: santtu 
 5  ''' 
 6   
7 -class User(object):
8 ''' 9 The class C{User} represents users of the Butler wine 10 diary program. Each user has a number of wines that they have 11 tasted and rated. 12 ''' 13 14
15 - def __init__(self):
16 ''' 17 Constructor. Creates a new user who has tasted no wines yet. 18 ''' 19 self.tasted_wines = []
20 21
22 - def add_wine(self, new_wine):
23 ''' 24 Adds a new wine to the user's list of tasted wines. 25 26 @param new_wine: the new wine diary item to add 27 ''' 28 if len(self.tasted_wines) == 0 or new_wine.isbetter_than(self.favorite): 29 self.favorite = new_wine; 30 31 self.tasted_wines.append(new_wine)
32 33
34 - def get_favorite(self):
35 ''' 36 Returns the wine that the user rated the highest, i.e., 37 the wine which has the highest rating of the ones added 38 with method C{add_wine}. If there is a tie for 39 first place, the wine tasted first is returned. 40 41 @return: the user's favorite wine 42 ''' 43 return self.favorite
44 45 46
47 - def get_tasted_wines(self):
48 ''' 49 Returns a list of all the wines the user has tasted. 50 51 @return: the wines tasted by the user 52 ''' 53 return self.tasted_wines; # Though this works, it is not the best possible implementation for
54 # this method, for reasons which will be covered later in the course. 55