Class: Calorie::WeeksInMonth
- Inherits:
-
Object
- Object
- Calorie::WeeksInMonth
- Defined in:
- lib/calorie/weeks_in_month.rb
Instance Method Summary collapse
- #blank_days_at_end ⇒ Object
- #blank_days_at_start ⇒ Object
- #days_for_slicing ⇒ Object
- #days_in_month ⇒ Object
- #first_day ⇒ Object
- #first_day_falls_on ⇒ Object
-
#initialize(days = []) ⇒ WeeksInMonth
constructor
A new instance of WeeksInMonth.
- #last_day ⇒ Object
- #number_of_weeks ⇒ Object
- #weeks ⇒ Object
Constructor Details
#initialize(days = []) ⇒ WeeksInMonth
Returns a new instance of WeeksInMonth.
3 4 5 |
# File 'lib/calorie/weeks_in_month.rb', line 3 def initialize(days = []) @source_days = days end |
Instance Method Details
#blank_days_at_end ⇒ Object
33 34 35 |
# File 'lib/calorie/weeks_in_month.rb', line 33 def blank_days_at_end 7 - ((blank_days_at_start + days_in_month) % 7) end |
#blank_days_at_start ⇒ Object
29 30 31 |
# File 'lib/calorie/weeks_in_month.rb', line 29 def blank_days_at_start first_day_falls_on end |
#days_for_slicing ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/calorie/weeks_in_month.rb', line 16 def days_for_slicing slices = @source_days.clone (1..blank_days_at_start).each do |i| slices.unshift(Calorie::NullDay.new(first_day - i)) end (1..blank_days_at_end).each do |i| slices.push(Calorie::NullDay.new(last_day + i)) end slices end |
#days_in_month ⇒ Object
41 42 43 |
# File 'lib/calorie/weeks_in_month.rb', line 41 def days_in_month @source_days.length end |
#first_day ⇒ Object
45 46 47 |
# File 'lib/calorie/weeks_in_month.rb', line 45 def first_day @source_days.first.date end |
#first_day_falls_on ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/calorie/weeks_in_month.rb', line 53 def first_day_falls_on if Calorie.configuration.week_starts_on?(:monday) (first_day.wday - 1) % 7 else first_day.wday end end |
#last_day ⇒ Object
49 50 51 |
# File 'lib/calorie/weeks_in_month.rb', line 49 def last_day @source_days.last.date end |
#number_of_weeks ⇒ Object
37 38 39 |
# File 'lib/calorie/weeks_in_month.rb', line 37 def number_of_weeks ((days_in_month + first_day_falls_on) / 7.0).ceil end |