Class: DateUtils::Year
Overview
represents a Year
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
the initial Date of the Year -instance.
-
#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(:week => 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.
-
#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
263 264 265 266 267 268 269 270 |
# File 'lib/date_utils.rb', line 263 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 end |
Instance Attribute Details
#date ⇒ Object (readonly)
the initial Date of the Year -instance
256 257 258 |
# File 'lib/date_utils.rb', line 256 def date @date end |
#year ⇒ Object (readonly)
the Year as an Integer of self
259 260 261 |
# File 'lib/date_utils.rb', line 259 def year @year end |
Class Method Details
.create(*args) ⇒ Object
call with hash: year :call-seq: Year.create(:week => x)
277 278 279 280 281 |
# File 'lib/date_utils.rb', line 277 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
316 317 318 |
# File 'lib/date_utils.rb', line 316 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
310 311 312 |
# File 'lib/date_utils.rb', line 310 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
285 286 287 288 289 290 291 |
# File 'lib/date_utils.rb', line 285 def months arr = [] for i in 1..12 arr.push( Month.new(Date.civil(@year,i) ) ) end arr end |
#weeks ⇒ Object
returns collection of Week -instances of self neccessarily overlaps year boundarys
296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/date_utils.rb', line 296 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 |