Class: Tempora::Week

Inherits:
TimePeriod show all
Extended by:
Initialization
Defined in:
lib/week.rb

Instance Attribute Summary collapse

Attributes inherited from TimePeriod

#end_date, #start_date

Instance Method Summary collapse

Methods included from Initialization

from, now

Methods inherited from TimePeriod

#<=>, #contains?, #duration, #hash, #intersection, #overlaps?, #range, #shift

Methods included from HasTime

#end_time, #start_time

Methods included from HasDays

#days, #each_day

Constructor Details

#initialize(year, week) ⇒ Week

Returns a new instance of Week.



10
11
12
13
14
15
16
# File 'lib/week.rb', line 10

def initialize(year, week)
  @year   = Integer(year)
  @number = Integer(week)

  @start_date = Date.commercial(@year, @number, 1)
  @end_date   = start_date + 6
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



8
9
10
# File 'lib/week.rb', line 8

def number
  @number
end

#yearObject (readonly)

Returns the value of attribute year.



8
9
10
# File 'lib/week.rb', line 8

def year
  @year
end

Instance Method Details

#id(seperator = "-") ⇒ Object



18
19
20
# File 'lib/week.rb', line 18

def id(seperator="-")
  "#{year}#{seperator}W#{format('%02d', number)}"
end

#nextObject Also known as: succ



26
27
28
# File 'lib/week.rb', line 26

def next
  self.class.from(start_date + 7)
end

#prevObject Also known as: pred



30
31
32
# File 'lib/week.rb', line 30

def prev
  self.class.from(start_date - 7)
end

#to_sObject



22
23
24
# File 'lib/week.rb', line 22

def to_s
  "#{I18n.t('timeperiod.week')} #{number}, #{year}"
end