Class: Workpattern::WeekPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/workpattern/week_pattern.rb

Instance Method Summary collapse

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

#fromObject



15
16
17
# File 'lib/workpattern/week_pattern.rb', line 15

def from
  work_pattern.from
end

#toObject



19
20
21
# File 'lib/workpattern/week_pattern.rb', line 19

def to
  work_pattern.to
end

#weeksObject



11
12
13
# File 'lib/workpattern/week_pattern.rb', line 11

def weeks
  work_pattern.weeks
end

#work_patternObject



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.

Parameters:

  • opts (Hash) (defaults to: {})

    the options used to apply a workpattern

Options Hash (opts):

  • :start (Date)

    The first date to apply the pattern. Defaults to the start attribute.

  • :finish (Date)

    The last date to apply the pattern. Defaults to the finish attribute.

  • :days (DAYNAMES)

    The specific day or days the pattern will

  • :start_time ((#hour, #min))

    The first time in the selected

  • :finish_time ((#hour, #min))

    The last time in the selected

  • :work_type ((WORK_TYPE || REST_TYPE))

    Either working or resting.

See Also:

  • #working
  • #resting


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 = all_workpattern_options(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