Class: FullMonth

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

Overview

Fills month up with the missing days from one day after the last hand in date to the next hand in date. Used for interactive mode for instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(month) ⇒ FullMonth

Returns a new instance of FullMonth.


6
7
8
# File 'lib/full_month.rb', line 6

def initialize(month)
  @month = Marshal.load Marshal.dump(month)
end

Instance Attribute Details

#monthObject

Returns the value of attribute month


4
5
6
# File 'lib/full_month.rb', line 4

def month
  @month
end

Instance Method Details

#full_monthMonth

Returns the complete month.

Returns:

  • (Month)

    the complete month.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/full_month.rb', line 11

def full_month
  current_month_year = month.month_year
  prev_month_year = current_month_year.prev

  current_month_days =
    month.days.select { |d| current_month_year.month_eq? d.month }.map(&:day)

  prev_month_days =
    month.days.select { |d| prev_month_year.month_eq? d.month }.map(&:day)

  ((1..Punch.config.hand_in_date).to_a - current_month_days).each do |d|
    day = Day.new
    day.day = d
    day.year, day.month = current_month_year
    month.days << day
  end

  (((Punch.config.hand_in_date + 1)..days_in_month(prev_month_year)).
    to_a - prev_month_days).each do |d|

    day = Day.new
    day.day = d
    day.year, day.month = prev_month_year
    month.days << day
  end

  month.days.sort!

  month
end