Class: Calrom::Month

Inherits:
DateRange show all
Defined in:
lib/calrom/date_range.rb

Instance Method Summary collapse

Methods inherited from DateRange

#spans_multiple_months?

Constructor Details

#initialize(year, month) ⇒ Month

Returns a new instance of Month.



67
68
69
70
71
72
# File 'lib/calrom/date_range.rb', line 67

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

  super Date.new(year, month, 1), Date.new(year, month, -1)
end

Instance Method Details

#<=>(other) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/calrom/date_range.rb', line 89

def <=>(other)
  years_cmp = year <=> other.year

  if years_cmp != 0
    years_cmp
  else
    month <=> other.month
  end
end

#each_month {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Calrom::Month)

    the object that the method was called on



78
79
80
81
82
# File 'lib/calrom/date_range.rb', line 78

def each_month
  return to_enum(:each_month) unless block_given?

  yield self
end

#succObject



84
85
86
87
# File 'lib/calrom/date_range.rb', line 84

def succ
  n = Date.new(@year, @month, 1).next_month
  self.class.new(n.year, n.month)
end

#to_sObject



74
75
76
# File 'lib/calrom/date_range.rb', line 74

def to_s
  first.strftime '%B %Y'
end