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.



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

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.



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

def number
  @number
end

#yearObject (readonly)

Returns the value of attribute year.



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

def year
  @year
end

Instance Method Details

#<=>(other) ⇒ Object



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

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

#previousObject



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

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

#succObject



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

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

#to_monthObject



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

def to_month
  self
end

#to_s(*args) ⇒ Object



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

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