Class: Biz::Week

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#weekObject (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_dateObject



34
35
36
# File 'lib/biz/week.rb', line 34

def start_date
  Date.from_day(week * Time::DAYS_IN_WEEK)
end

#succObject



38
39
40
# File 'lib/biz/week.rb', line 38

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