Class: Workpattern::WeekPattern
- Inherits:
-
Object
- Object
- Workpattern::WeekPattern
- Defined in:
- lib/workpattern/week_pattern.rb
Instance Method Summary collapse
- #from ⇒ Object
-
#initialize(work_pattern) ⇒ WeekPattern
constructor
A new instance of WeekPattern.
- #to ⇒ Object
- #weeks ⇒ Object
- #work_pattern ⇒ Object
-
#workpattern(opts = {}, persist = nil) ⇒ Object
Applys a working or resting pattern to the
Workpattern
object.
Constructor Details
#initialize(work_pattern) ⇒ WeekPattern
Returns a new instance of WeekPattern.
3 4 5 |
# File 'lib/workpattern/week_pattern.rb', line 3 def initialize(work_pattern) @work_pattern = work_pattern end |
Instance Method Details
#from ⇒ Object
15 16 17 |
# File 'lib/workpattern/week_pattern.rb', line 15 def from work_pattern.from end |
#to ⇒ Object
19 20 21 |
# File 'lib/workpattern/week_pattern.rb', line 19 def to work_pattern.to end |
#weeks ⇒ Object
11 12 13 |
# File 'lib/workpattern/week_pattern.rb', line 11 def weeks work_pattern.weeks end |
#work_pattern ⇒ Object
7 8 9 |
# File 'lib/workpattern/week_pattern.rb', line 7 def work_pattern @work_pattern end |
#workpattern(opts = {}, persist = nil) ⇒ Object
Applys a working or resting pattern to the Workpattern
object.
The #resting and #working methods are convenience methods that call this with the appropriate :work_type
already set.
apply to.It defaults to :all
days to apply the pattern. Defaults to 00:00
. days to apply the pattern. Defaults to 23:59
. Defaults to working.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/workpattern/week_pattern.rb', line 43 def workpattern(opts = {}, persist = nil) args = (opts) persist.store(name: @name, workpattern: args) if !persist.nil? args = standardise_args(args) upd_start = work_pattern.to_utc(args[:start]) upd_finish = work_pattern.to_utc(args[:finish]) while upd_start <= upd_finish current_wp = work_pattern.find_weekpattern(upd_start) if current_wp.start == upd_start if current_wp.finish > upd_finish clone_wp = fetch_updatable_week_pattern(current_wp, upd_finish + DAY, current_wp.finish, upd_start, upd_finish) update_and_store_week_pattern(clone_wp, args) upd_start = upd_finish + DAY else # (current_wp.finish == upd_finish) current_wp.workpattern(args[:days], args[:from_time], args[:to_time], args[:work_type]) upd_start = current_wp.finish + DAY end else clone_wp = fetch_updatable_week_pattern(current_wp, current_wp.start, upd_start - DAY, upd_start) if clone_wp.finish > upd_finish after_wp = fetch_updatable_week_pattern(clone_wp, upd_start, upd_finish, upd_finish + DAY) weeks << after_wp end update_and_store_week_pattern(clone_wp, args) upd_start = clone_wp.finish + DAY end end end |