Class: Month

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/qualitysmith_extensions/month.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, month) ⇒ Month

Returns a new instance of Month.



18
19
20
21
# File 'lib/qualitysmith_extensions/month.rb', line 18

def initialize(year, month)
  @year = year
  @month = month
end

Instance Attribute Details

#monthObject (readonly)

Returns the value of attribute month.



16
17
18
# File 'lib/qualitysmith_extensions/month.rb', line 16

def month
  @month
end

#yearObject (readonly)

Returns the value of attribute year.



16
17
18
# File 'lib/qualitysmith_extensions/month.rb', line 16

def year
  @year
end

Instance Method Details

#<=>(other) ⇒ Object



31
32
33
34
# File 'lib/qualitysmith_extensions/month.rb', line 31

def <=>(other)
  #puts "#{self.inspect} <=> #{other.inspect}"
  return self.to_date <=> other.to_date
end

#inspectObject



36
37
38
# File 'lib/qualitysmith_extensions/month.rb', line 36

def inspect
  "#{@year}-#{@month}"
end

#succObject



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

def succ
  (to_date >> 1).to_month
end

#to_dateObject



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

def to_date
  Date.new(year, month)
end