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.
Class Method Summary collapse
-
.create(*args) ⇒ Object
create a Week-instance call with hash: year and week :call-seq: Week.create(:year => x, :week => y) Week.create(:week => x) Week.create(:year => x).
Instance Method Summary collapse
-
#days ⇒ Object
returns collection of days as Date -instances.
-
#initialize(val = 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
extract_options_from_args!, #include?
Constructor Details
#initialize(val = 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
96 97 98 99 100 101 102 103 104 |
# File 'lib/date_utils.rb', line 96 def initialize(val=nil) if val.nil? _date = Date.today else _date = val.is_a?(Date) ? val : (raise ArgumentError.new("neither Fixnum nor Date given.")) end set_date(_date) create_instance_variables end |
Instance Attribute Details
#date ⇒ Object (readonly)
the initial / regular Date instance
88 89 90 |
# File 'lib/date_utils.rb', line 88 def date @date end |
#first_day ⇒ Object (readonly)
the first day (Monday) of the week
79 80 81 |
# File 'lib/date_utils.rb', line 79 def first_day @first_day end |
#last_day ⇒ Object (readonly)
the last day (Sunday) of the week
82 83 84 |
# File 'lib/date_utils.rb', line 82 def last_day @last_day end |
#month ⇒ Object (readonly)
the Month of the week
91 92 93 |
# File 'lib/date_utils.rb', line 91 def month @month end |
#num_week ⇒ Object (readonly)
the num of the week
85 86 87 |
# File 'lib/date_utils.rb', line 85 def num_week @num_week end |
Class Method Details
.create(*args) ⇒ Object
create a Week-instance call with hash: year and week :call-seq: Week.create(:year => x, :week => y) Week.create(:week => x) Week.create(:year => x)
113 114 115 116 117 118 119 120 |
# File 'lib/date_utils.rb', line 113 def self.create(*args) = Common::(args) year_date = .has_key?(:year) ? Date::civil([:year].to_i, 1,1) : Date.today unless .has_key?(:week) && ![:week].nil? return Week.new(year_date) end return Year.new(year_date).get_week([:week].to_i) end |
Instance Method Details
#days ⇒ Object
returns collection of days as Date -instances
136 137 138 139 140 |
# File 'lib/date_utils.rb', line 136 def days arr = [] @first_day.upto(@last_day) { |date| arr << date } arr end |