Class: Biz::Week
Class Method Summary collapse
- .from_date(date) ⇒ Object
- .from_time(time) ⇒ Object (also: since_epoch)
Instance Method Summary collapse
- #+(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.
22 23 24 |
# File 'lib/biz/week.rb', line 22 def initialize(week) @week = Integer(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((date - Date.epoch).to_i / Time.week_days) 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
42 43 44 |
# File 'lib/biz/week.rb', line 42 def +(other) self.class.new(week + other.week) end |
#downto(final_week) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/biz/week.rb', line 34 def downto(final_week) return enum_for(:downto, final_week) unless block_given? week.downto(final_week.week).each do |raw_week| yield self.class.new(raw_week) end end |
#start_date ⇒ Object
26 27 28 |
# File 'lib/biz/week.rb', line 26 def start_date Date.from_day(week * Time.week_days) end |
#succ ⇒ Object
30 31 32 |
# File 'lib/biz/week.rb', line 30 def succ self.class.new(week.succ) end |