Class: DateUtils::Year

Inherits:
Object
  • Object
show all
Defined in:
lib/date_utils.rb

Overview

represents a Year

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date = nil) ⇒ Year

create a new Year -instance with given Date



168
169
170
171
172
173
174
# File 'lib/date_utils.rb', line 168

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

#dateObject (readonly)

the initial Date of the Year -instance



161
162
163
# File 'lib/date_utils.rb', line 161

def date
  @date
end

#yearObject (readonly)

the Year as an Integer of self



164
165
166
# File 'lib/date_utils.rb', line 164

def year
  @year
end

Instance Method Details

#monthsObject

returns collection of Month -instances of self



178
179
180
181
182
183
184
# File 'lib/date_utils.rb', line 178

def months
  arr = []
  for i in 1..12
    arr.push( Month.new(Date.civil(@year,i) ) )
  end
  arr
end

#weeksObject

returns collection of Week -instances of self neccessarily overlaps year boundarys



189
190
191
192
193
194
195
196
197
198
199
# File 'lib/date_utils.rb', line 189

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