Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Scheduling
- attr_reader :sticky_user
- def initialize(tasks, users)
- @users = users
- @assigments = order_tasks(tasks).map do |task|
- users = select_users_for_task(task)
- Assignment.new(task, users, self)
- end
- end
- private
- def order_tasks(tasks)
- #here we order tasks by priority
- end
- def select_users_for_task(task)
- #here we get all the users that could perform that task, from our @users array.
- end
- end
- class Assignment
- def initialize(task, users, scheduling)
- @scheduling = scheduling
- @task = task
- @scheduling.sticky_user = @user = order_users(users).first
- @events = @user.add_to_bucket(self)
- end
- private
- def order_users(users)
- #here we find the best user to do the job.
- #rule 1 - the 'sticky user' gets priority
- if @scheduling.sticky_user && users.include?(@scheduling.sticky_user)
- ( [@scheduling.sticky_user] + users ).uniq
- else
- users
- end
- end
- end
Add Comment
Please, Sign In to add comment