Class: YearWeek

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.currentObject



23
24
25
# File 'lib/year_week.rb', line 23

def self.current
  for_date(Date.current)
end

.for_date(date) ⇒ Object



19
20
21
# File 'lib/year_week.rb', line 19

def self.for_date(date)
  new(date.cwyear, date.cweek)
end

Instance Method Details

#<=>(other) ⇒ Object



7
8
9
# File 'lib/year_week.rb', line 7

def <=>(other)
  to_s <=> other.to_s
end

#beginObject



31
32
33
# File 'lib/year_week.rb', line 31

def begin
  DateTime.commercial(@year, @week)
end

#endObject



35
36
37
# File 'lib/year_week.rb', line 35

def end
  DateTime.commercial(@year, @week, 7, 23, 59, 59)
end

#gt(att) ⇒ Object



55
56
57
# File 'lib/year_week.rb', line 55

def gt(att)
  att.lt(self.begin)
end

#gteq(att) ⇒ Object



59
60
61
# File 'lib/year_week.rb', line 59

def gteq(att)
  succ.gt(att)
end

#include?(other) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/year_week.rb', line 15

def include?(other)
  to_range.include?(other.to_date)
end

#lt(att) ⇒ Object



47
48
49
# File 'lib/year_week.rb', line 47

def lt(att)
  att.gt(self.end)
end

#lteq(att) ⇒ Object



51
52
53
# File 'lib/year_week.rb', line 51

def lteq(att)
  pred.lt(att)
end

#predObject



43
44
45
# File 'lib/year_week.rb', line 43

def pred
  self.class.for_date(self.begin.prev_day)
end

#succObject



39
40
41
# File 'lib/year_week.rb', line 39

def succ
  self.class.for_date(self.begin.next_week)
end

#to_rangeObject



27
28
29
# File 'lib/year_week.rb', line 27

def to_range
  (self.begin..self.end)
end

#to_sObject



11
12
13
# File 'lib/year_week.rb', line 11

def to_s
  "#{@year}-#{@week}"
end