Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # email a user when an event's time was changed.
- #
- # features
- # 1. user can add events (each event has a known url).
- # 2. every morning if any event's time was changed,
- # the user gets email with the changed events.
- # 3. on Monday morning, user gets email of all his events
- # regardless of changes in times.
- # holds a user and it's events
- class User
- attr_accessor :events, :name
- def initialize name
- @name = name
- @events = nil
- @updated = false
- end
- # ask each event to get it's current time and
- # mark the user as 'updated' so later on we
- # will email him/her
- def get_time
- @updated = @events.any?{|e| e.get_time; e.updated?}
- end
- def updated?
- @updated
- end
- end
- # holds info about a event
- class Event
- attr_accessor :name, :url, :base_time
- def initialize name, url, base_time
- @name = name
- @url = url
- @base_time = base_time
- @current_time = nil
- @updated = false
- end
- # scrape event from the website and mark it
- # as 'updated' if it's time was modified
- def get_time
- current_time = fetch_current_time
- @current_current_time = current_time if current_time
- if current_time != @base_time
- @updated = true
- end
- end
- def updated?
- @updated
- end
- private
- # get current event time from the website
- def fetch_current_time
- 123124234324
- end
- end
- # send email to a user
- module Email
- module_function
- def send user
- # if it's Monday send email with all events
- # else send email with only the updated events
- puts "sending email to #{user.name}"
- end
- end
- user = User.new('josh')
- party = Event.new('party', 'http://events.com/events/123', 1234234)
- movie = Event.new('movie', 'http://events/events/564', 1243133)
- user.events = [party, movie]
- user.get_time
- if user.updated? or Date.now.monday?
- Email.send(user)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement