class ActiveWeek::Week

Constants

WEEKDAY_MONDAY
WEEKDAY_SUNDAY

Attributes

first_day[R]

Public Class Methods

current() click to toggle source
# File lib/active_week/week.rb, line 13
def current
  date = Time.zone ? Time.zone.today : Date.today
  new(date.cwyear, date.cweek)
end
from_date(date) click to toggle source
# File lib/active_week/week.rb, line 18
def from_date(date)
  new(date.cwyear, date.cweek)
end
new(year, number) click to toggle source
# File lib/active_week/week.rb, line 23
def initialize(year, number)
  @first_day = Date.commercial(year, number, WEEKDAY_MONDAY)
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/active_week/week.rb, line 57
def <=>(other)
  raise ArgumentError.new("#{self.class} can't be compared with #{other.class}") unless other.is_a?(self.class)

  first_day <=> other.first_day
end
==(other) click to toggle source
# File lib/active_week/week.rb, line 63
def ==(other)
  raise ArgumentError.new("#{self.class} can't be compared with #{other.class}") unless other.is_a?(self.class)

  first_day == other.first_day
end
Also aliased as: eql?
each_day() { |d| ... } click to toggle source
# File lib/active_week/week.rb, line 51
def each_day
  return to_enum(__callee__) unless block_given?
  (first_day..last_day).each { |d| yield d }
  self
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/active_week/week.rb, line 71
def hash
  year.hash ^ number.hash
end
last_day() click to toggle source
# File lib/active_week/week.rb, line 35
def last_day
  Date.commercial(year, number, WEEKDAY_SUNDAY)
end
next_week() click to toggle source
# File lib/active_week/week.rb, line 39
def next_week
  date = first_day.next_week
  self.class.new(date.cwyear, date.cweek)
end
Also aliased as: succ
number() click to toggle source
# File lib/active_week/week.rb, line 31
def number
  @first_day.cweek
end
prev_week() click to toggle source
# File lib/active_week/week.rb, line 46
def prev_week
  date = first_day.prev_week
  self.class.new(date.cwyear, date.cweek)
end
succ()
Alias for: next_week
year() click to toggle source
# File lib/active_week/week.rb, line 27
def year
  @first_day.cwyear
end