Class: DateUtils::Year
Overview
represents a Year
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
the initial Date of the Year -instance.
-
#first_day ⇒ Object
readonly
first day of this year.
-
#last_day ⇒ Object
readonly
last day of this year.
-
#year ⇒ Object
readonly
the Year as an Integer of self.
Class Method Summary collapse
-
.create(*args) ⇒ Object
call with hash: year :call-seq: Year.create(:year => x).
Instance Method Summary collapse
-
#get_month(num) ⇒ Object
returns Month ‘num’ of self.
-
#get_week(num) ⇒ Object
returns Week ‘num’ of self.
-
#initialize(date = nil) ⇒ Year
constructor
create a new Year -instance with given Date.
-
#months ⇒ Object
returns collection of Month -instances of self.
-
#next ⇒ Object
returns new Year instance one year later TODO implement.
-
#previous ⇒ Object
returns new Year instance one year previous TODO implement.
-
#weeks ⇒ Object
returns collection of Week -instances of self neccessarily overlaps year boundarys.
Methods included from Common
extract_options_from_args!, #include?
Constructor Details
#initialize(date = nil) ⇒ Year
create a new Year -instance with given Date
278 279 280 281 282 283 284 285 286 287 |
# File 'lib/date_utils.rb', line 278 def initialize(date=nil) date = Date.today if date.nil? unless date.kind_of?(Date) raise ArgumentError, "needs Date as input!" end @year = date.year @date = date @first_day = Date::parse("#{@year}-01-01") @last_day = Date::parse("#{@year}-12-31") end |
Instance Attribute Details
#date ⇒ Object (readonly)
the initial Date of the Year -instance
265 266 267 |
# File 'lib/date_utils.rb', line 265 def date @date end |
#first_day ⇒ Object (readonly)
first day of this year
271 272 273 |
# File 'lib/date_utils.rb', line 271 def first_day @first_day end |
#last_day ⇒ Object (readonly)
last day of this year
274 275 276 |
# File 'lib/date_utils.rb', line 274 def last_day @last_day end |
#year ⇒ Object (readonly)
the Year as an Integer of self
268 269 270 |
# File 'lib/date_utils.rb', line 268 def year @year end |
Class Method Details
.create(*args) ⇒ Object
call with hash: year :call-seq: Year.create(:year => x)
294 295 296 297 298 |
# File 'lib/date_utils.rb', line 294 def self.create(*args) = Common::(args) date_year = .has_key?(:year) ? Date.civil([:year]) : (raise ArgumentError.new("no key :year in hash.")) return Year.new(date_year) end |
Instance Method Details
#get_month(num) ⇒ Object
returns Month ‘num’ of self
333 334 335 |
# File 'lib/date_utils.rb', line 333 def get_month(num) ! num.kind_of?(Fixnum) || num > 12 ? ArgumentError.new("invalid week-number 'num'"): self.months[num-1] end |
#get_week(num) ⇒ Object
returns Week ‘num’ of self
327 328 329 |
# File 'lib/date_utils.rb', line 327 def get_week(num) ! num.kind_of?(Fixnum) || num > 52 ? ArgumentError.new("invalid week-number 'num'"): self.weeks[num -1] end |
#months ⇒ Object
returns collection of Month -instances of self
302 303 304 305 306 307 308 |
# File 'lib/date_utils.rb', line 302 def months arr = [] for i in 1..12 arr.push( Month.new(Date.civil(@year,i) ) ) end arr end |
#next ⇒ Object
returns new Year instance one year later TODO implement
339 340 |
# File 'lib/date_utils.rb', line 339 def next end |
#previous ⇒ Object
returns new Year instance one year previous TODO implement
344 345 |
# File 'lib/date_utils.rb', line 344 def previous end |
#weeks ⇒ Object
returns collection of Week -instances of self neccessarily overlaps year boundarys
313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/date_utils.rb', line 313 def weeks d = Date.civil(@year) arr = [] week = Week.new(d) arr.push(week) for i in 1..52 week = week.next arr.push(week) end arr end |