Advertisement
Guest User

feedback needed

a guest
Dec 24th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.87 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.     @updated = @events.any?{|e| e.get_time; e.updated?}
  25.   end
  26.  
  27.   def updated?
  28.     @updated
  29.   end
  30. end
  31.  
  32. # holds info about a event
  33. class Event
  34.   attr_accessor :name, :url, :base_time
  35.  
  36.   def initialize name, url, base_time
  37.     @name = name
  38.     @url = url
  39.     @base_time = base_time
  40.     @current_time = nil
  41.     @updated = false
  42.   end
  43.  
  44.   # scrape event from the website and mark it
  45.   # as 'updated' if it's time was modified
  46.   def get_time
  47.     current_time = fetch_current_time
  48.     @current_current_time = current_time if current_time
  49.     if current_time != @base_time
  50.       @updated = true
  51.     end
  52.   end
  53.  
  54.   def updated?
  55.     @updated
  56.   end
  57.  
  58.   private
  59.  
  60.   # get current event time from the website
  61.   def fetch_current_time
  62.  
  63.     123124234324
  64.   end
  65. end
  66.  
  67. # send email to a user
  68. module Email
  69.   module_function
  70.  
  71.   def send user
  72.     # if it's Monday send email with all events
  73.     # else send email with only the updated events
  74.     puts "sending email to #{user.name}"
  75.   end
  76. end
  77.  
  78. user = User.new('josh')
  79. party = Event.new('party', 'http://events.com/events/123', 1234234)
  80. movie = Event.new('movie', 'http://events/events/564', 1243133)
  81. user.events = [party, movie]
  82.  
  83. user.get_time
  84.  
  85. if user.updated? or Date.now.monday?
  86.   Email.send(user)
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement