Class: Biz::Week

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/biz/week.rb

Class Method Summary collapse

Instance Method Summary collapse

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_dateObject



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

def start_date
  Date.from_day(week * Time.week_days)
end

#succObject



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

def succ
  self.class.new(week.succ)
end