Class: DateUtils::Month
Overview
Represents a ‘Month’
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
the initial / regular Date instance.
-
#first_day ⇒ Object
readonly
the first day of the Month -instance.
-
#last_day ⇒ Object
readonly
the last day of the Month -instance.
-
#month ⇒ Object
readonly
the Month -number.
-
#num_days ⇒ Object
readonly
the number of days in Month.
Class Method Summary collapse
-
.create(*args) ⇒ Object
create a Month-instance call with hash: year and month :call-seq: Month.create(:year => x, :month => y) Month.create(:month => x) Month.create(:year => x).
Instance Method Summary collapse
-
#days ⇒ Object
returns collection of days as Date -instances of self.
-
#initialize(val = nil) ⇒ Month
constructor
create a new Month of given Date.
-
#next ⇒ Object
returns new Month -instance one Month later than self.
-
#previous ⇒ Object
returns a new Month -instance one Month prior to self.
Methods included from Common
extract_options_from_args!, #include?
Constructor Details
#initialize(val = nil) ⇒ Month
create a new Month of given Date
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/date_utils.rb', line 192 def initialize(val=nil) if val.nil? _date = Date.today else if val.is_a?(Date) _date = val elsif val.is_a?(Fixnum) && val <= 12 _date = Date::civil(Date.today.year.to_i,val,1) else raise ArgumentError.new("neither Fixnum nor Date given.") end end @date = _date create_instance_variables end |
Instance Attribute Details
#date ⇒ Object (readonly)
the initial / regular Date instance
176 177 178 |
# File 'lib/date_utils.rb', line 176 def date @date end |
#first_day ⇒ Object (readonly)
the first day of the Month -instance
179 180 181 |
# File 'lib/date_utils.rb', line 179 def first_day @first_day end |
#last_day ⇒ Object (readonly)
the last day of the Month -instance
182 183 184 |
# File 'lib/date_utils.rb', line 182 def last_day @last_day end |
#month ⇒ Object (readonly)
the Month -number
185 186 187 |
# File 'lib/date_utils.rb', line 185 def month @month end |
#num_days ⇒ Object (readonly)
the number of days in Month
188 189 190 |
# File 'lib/date_utils.rb', line 188 def num_days @num_days end |
Class Method Details
.create(*args) ⇒ Object
create a Month-instance call with hash: year and month :call-seq: Month.create(:year => x, :month => y) Month.create(:month => x) Month.create(:year => x)
215 216 217 218 219 220 |
# File 'lib/date_utils.rb', line 215 def self.create(*args) = Common::(args) int_year = .has_key?(:year) && [:year].is_a?(Fixnum) ? [:year] : nil int_month = .has_key?(:month) && [:month].is_a?(Fixnum) && [:month] <= 12 ? [:month] : nil return Month.new(Date::civil(int_year || Date.today.year, int_month || 1)) end |
Instance Method Details
#days ⇒ Object
returns collection of days as Date -instances of self
236 237 238 239 240 |
# File 'lib/date_utils.rb', line 236 def days arr = [] @first_day.upto(@last_day) { |date| arr << date } arr end |