Class: Biz::Week
- Inherits:
-
Object
- Object
- Biz::Week
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/biz/week.rb
Instance Attribute Summary collapse
-
#week ⇒ Object
readonly
Returns the value of attribute week.
Class Method Summary collapse
- .from_date(date) ⇒ Object
- .from_time(time) ⇒ Object (also: since_epoch)
Instance Method Summary collapse
- #+(other) ⇒ Object
- #coerce(other) ⇒ Object
- #downto(final_week) ⇒ Object
-
#initialize(week) ⇒ Week
constructor
A new instance of Week.
- #start_date ⇒ Object
- #succ ⇒ Object
Constructor Details
#initialize(week) ⇒ Week
Returns a new instance of Week.
30 31 32 |
# File 'lib/biz/week.rb', line 30 def initialize(week) @week = Integer(week) end |
Instance Attribute Details
#week ⇒ Object (readonly)
Returns the value of attribute week.
22 23 24 |
# File 'lib/biz/week.rb', line 22 def week @week end |
Class Method Details
.from_date(date) ⇒ Object
8 9 10 |
# File 'lib/biz/week.rb', line 8 def self.from_date(date) new(Day.from_date(date).to_i / Time::DAYS_IN_WEEK) end |
.from_time(time) ⇒ Object Also known as: since_epoch
12 13 14 |
# File 'lib/biz/week.rb', line 12 def self.from_time(time) from_date(time.to_date) end |
Instance Method Details
#+(other) ⇒ Object
50 51 52 |
# File 'lib/biz/week.rb', line 50 def +(other) self.class.new(week + other.week) end |
#coerce(other) ⇒ Object
54 55 56 |
# File 'lib/biz/week.rb', line 54 def coerce(other) [self.class.new(other), self] end |
#downto(final_week) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/biz/week.rb', line 42 def downto(final_week) return enum_for(:downto, final_week) unless block_given? week.downto(final_week.to_i).each do |raw_week| yield self.class.new(raw_week) end end |
#start_date ⇒ Object
34 35 36 |
# File 'lib/biz/week.rb', line 34 def start_date Date.from_day(week * Time::DAYS_IN_WEEK) end |
#succ ⇒ Object
38 39 40 |
# File 'lib/biz/week.rb', line 38 def succ self.class.new(week.succ) end |