Advertisement
Guest User

feedback on my design

a guest
Dec 24th, 2011
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.91 KB | None | 0 0
  1. # email a user when an event's time was changed.
  2. #
  3. # features
  4. # 1. user can add events (each event has a known url).
  5. # 2. every morning if any event's time was changed,
  6. # the user gets email with the changed events.
  7. # 3. on Monday morning, user gets email of all his events
  8. # regardless of changes in times.
  9.  
  10. # holds a user and it's events
  11. class User
  12.   attr_accessor :events, :name
  13.  
  14.   def initialize name
  15.     @name = name
  16.     @events = nil
  17.     @updated = false
  18.   end
  19.  
  20.   # ask each event to get it's current time and
  21.   # mark the user as 'updated' so later on we
  22.   # will email him/her
  23.   def get_time
  24.     @events.each do |event|
  25.       event.get_time
  26.       @updated = true if event.updated?
  27.     end
  28.   end
  29.  
  30.   def updated?
  31.     @updated
  32.   end
  33. end
  34.  
  35. # holds info about a event
  36. class Event
  37.   attr_accessor :name, :url, :base_time
  38.  
  39.   def initialize name, url, base_time
  40.     @name = name
  41.     @url = url
  42.     @base_time = base_time
  43.     @current_time = nil
  44.     @updated = false
  45.   end
  46.  
  47.   # scrape event from the website and mark it
  48.   # as 'updated' if it's time was modified
  49.   def get_time
  50.     current_time = fetch_current_time
  51.     @current_current_time = current_time if current_time
  52.     if current_time != @base_time
  53.       @updated = true
  54.     end
  55.   end
  56.  
  57.   def updated?
  58.     @updated
  59.   end
  60.  
  61.   private
  62.  
  63.   # get current event time from the website
  64.   def fetch_current_time
  65.  
  66.     123124234324
  67.   end
  68. end
  69.  
  70. # send email to a user
  71. module Email
  72.   module_function
  73.  
  74.   def send user
  75.     # if it's Monday send email with all events
  76.     # else send email with only the updated events
  77.     puts "sending email to #{user.name}"
  78.   end
  79. end
  80.  
  81. user = User.new('josh')
  82. wine = Event.new('wine', 'http://events.com/events/123', 1234234)
  83. shampoo = Event.new('shampoo', 'http://events/events/564', 1243133)
  84. user.events = [wine, shampoo]
  85.  
  86. user.get_time
  87.  
  88. if user.updated? or Date.now.monday?
  89.   Email.send(user)
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement