Class: DateUtils::Week
- Inherits:
-
Object
- Object
- DateUtils::Week
- Defined in:
- lib/date_utils.rb
Overview
Represents a ‘Week’ beginning on Mondays and ending on Sundays
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
the initial / regular Date instance.
-
#first_day ⇒ Object
readonly
the first day (Monday) of the week.
-
#last_day ⇒ Object
readonly
the last day (Sunday) of the week.
-
#month ⇒ Object
readonly
the Month of the week.
-
#num_week ⇒ Object
readonly
the num of the week.
Instance Method Summary collapse
-
#days ⇒ Object
returns collection of days as Date -instances.
-
#initialize(date = nil) ⇒ Week
constructor
create a new Week-instance with the given initial Date if ‘date’ is nil, create an instance with Date.today.
-
#next ⇒ Object
return new Week -instance one week after self.
-
#previous ⇒ Object
returns new Week -instance one week before self.
Constructor Details
#initialize(date = nil) ⇒ Week
create a new Week-instance with the given initial Date if ‘date’ is nil, create an instance with Date.today
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/date_utils.rb', line 65 def initialize(date=nil) date = Date.today if date.nil? if date.kind_of?(Date) @month = Month.new(date) @date = date @num_week = date.cweek @first_day = date - ( date.cwday - 1 ) @last_day = date + ( 7 - date.cwday ) else raise ArgumentError, "needs Date object as input." end end |
Instance Attribute Details
#date ⇒ Object (readonly)
the initial / regular Date instance
57 58 59 |
# File 'lib/date_utils.rb', line 57 def date @date end |
#first_day ⇒ Object (readonly)
the first day (Monday) of the week
48 49 50 |
# File 'lib/date_utils.rb', line 48 def first_day @first_day end |
#last_day ⇒ Object (readonly)
the last day (Sunday) of the week
51 52 53 |
# File 'lib/date_utils.rb', line 51 def last_day @last_day end |
#month ⇒ Object (readonly)
the Month of the week
60 61 62 |
# File 'lib/date_utils.rb', line 60 def month @month end |
#num_week ⇒ Object (readonly)
the num of the week
54 55 56 |
# File 'lib/date_utils.rb', line 54 def num_week @num_week end |
Instance Method Details
#days ⇒ Object
returns collection of days as Date -instances
92 93 94 95 96 |
# File 'lib/date_utils.rb', line 92 def days arr = [] @first_day.upto(@last_day) { |date| arr << date } arr end |