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.
Instance Method Summary collapse
-
#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
Constructor Details
#initialize(date = nil) ⇒ Year
create a new Year -instance with given Date
202 203 204 205 206 207 208 |
# File 'lib/date_utils.rb', line 202 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 end |
Instance Attribute Details
#date ⇒ Object (readonly)
the initial Date of the Year -instance
195 196 197 |
# File 'lib/date_utils.rb', line 195 def date @date end |
#year ⇒ Object (readonly)
the Year as an Integer of self
198 199 200 |
# File 'lib/date_utils.rb', line 198 def year @year end |
Instance Method Details
#get_week(num) ⇒ Object
returns Week ‘num’ of self
237 238 239 |
# File 'lib/date_utils.rb', line 237 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
212 213 214 215 216 217 218 |
# File 'lib/date_utils.rb', line 212 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
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/date_utils.rb', line 223 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 |