Class: Tempora::Week
- Inherits:
-
TimePeriod
- Object
- TimePeriod
- Tempora::Week
- Extended by:
- Initialization
- Defined in:
- lib/week.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Attributes inherited from TimePeriod
Instance Method Summary collapse
- #id(seperator = "-") ⇒ Object
-
#initialize(year, week) ⇒ Week
constructor
A new instance of Week.
- #next ⇒ Object (also: #succ)
- #prev ⇒ Object (also: #pred)
- #to_s ⇒ Object
Methods included from Initialization
Methods inherited from TimePeriod
#<=>, #contains?, #duration, #hash, #intersection, #overlaps?, #range, #shift
Methods included from HasTime
Methods included from HasDays
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
#number ⇒ Object (readonly)
Returns the value of attribute number.
8 9 10 |
# File 'lib/week.rb', line 8 def number @number end |
#year ⇒ Object (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 |
#next ⇒ Object Also known as: succ
26 27 28 |
# File 'lib/week.rb', line 26 def next self.class.from(start_date + 7) end |
#prev ⇒ Object Also known as: pred
30 31 32 |
# File 'lib/week.rb', line 30 def prev self.class.from(start_date - 7) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/week.rb', line 22 def to_s "#{I18n.t('timeperiod.week')} #{number}, #{year}" end |