Class: DateUtils::Week
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 or Week-number 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.
Methods included from Common
Constructor Details
#initialize(date = nil) ⇒ Week
create a new Week-instance with the given initial Date or Week-number if ‘date’ is nil, create an instance with Date.today
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/date_utils.rb', line 91 def initialize(date=nil) if date.nil? _date = Date.today elsif date.kind_of?(Date) _date = date elsif date.kind_of?(Fixnum) _date = Year.new.get_week(date).date else raise ArgumentError, "needs Date object or Fixnum for Week as input." end @month = Month.new(_date) @date = _date @num_week = _date.cweek @first_day = _date - ( _date.cwday - 1 ) @last_day = _date + ( 7 - _date.cwday ) end |
Instance Attribute Details
#date ⇒ Object (readonly)
the initial / regular Date instance
83 84 85 |
# File 'lib/date_utils.rb', line 83 def date @date end |
#first_day ⇒ Object (readonly)
the first day (Monday) of the week
74 75 76 |
# File 'lib/date_utils.rb', line 74 def first_day @first_day end |
#last_day ⇒ Object (readonly)
the last day (Sunday) of the week
77 78 79 |
# File 'lib/date_utils.rb', line 77 def last_day @last_day end |
#month ⇒ Object (readonly)
the Month of the week
86 87 88 |
# File 'lib/date_utils.rb', line 86 def month @month end |
#num_week ⇒ Object (readonly)
the num of the week
80 81 82 |
# File 'lib/date_utils.rb', line 80 def num_week @num_week end |
Instance Method Details
#days ⇒ Object
returns collection of days as Date -instances
122 123 124 125 126 |
# File 'lib/date_utils.rb', line 122 def days arr = [] @first_day.upto(@last_day) { |date| arr << date } arr end |