Skip to content

Instantly share code, notes, and snippets.

@cswalina
Created June 13, 2016 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cswalina/b53060150e94e7d642c4935988304c92 to your computer and use it in GitHub Desktop.
Save cswalina/b53060150e94e7d642c4935988304c92 to your computer and use it in GitHub Desktop.
How we might generate work sessions
class Rotation
has_many :shift_cycles
def template
# given some shift_cycles:
#-------------------------------+
# days_on | days_off | shift_id |
#-------------------------------+
# 3 | 1 | 5
# 2 | 1 | 6
#
# This method should return:
# [
# [T,5],
# [T,5],
# [T,5],
# [F,5],
# [T,6],
# [T,6],
# [F,6]
# ]
end
def template_index(date)
( self.starts_on - date ).to_i.abs % template.length
end
# Given a date:
# working? => template[template_index(date)][0] (T or F)
# shift_id => template[template_index(date)][1] ( 5 or 6 )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment