Class: Cal::Month

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, number) ⇒ Month

Returns a new instance of Month.



5
6
7
8
# File 'lib/cal/month.rb', line 5

def initialize(year, number)
  @year = year.to_i
  @number = number.to_i
end

Instance Attribute Details

#numberObject (readonly) Also known as: to_i

Returns the value of attribute number.



10
11
12
# File 'lib/cal/month.rb', line 10

def number
  @number
end

#yearObject (readonly)

Returns the value of attribute year.



10
11
12
# File 'lib/cal/month.rb', line 10

def year
  @year
end

Instance Method Details

#<=>(other) ⇒ Object



14
15
16
# File 'lib/cal/month.rb', line 14

def <=>(other)
  date <=> other.send(:date) if other.is_a?(self.class)
end

#previousObject



26
27
28
# File 'lib/cal/month.rb', line 26

def previous
  self.class.new *(number == 1 ? [(year - 1), 12] : [year, (number - 1)])
end

#succObject



22
23
24
# File 'lib/cal/month.rb', line 22

def succ
  self.class.new *(number == 12 ? [(year + 1), 1] : [year, (number + 1)])
end

#to_monthObject



30
31
32
# File 'lib/cal/month.rb', line 30

def to_month
  self
end

#to_s(*args) ⇒ Object



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

def to_s(*args)
  date.strftime *args
end