Class: Calrom::Month

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

Instance Method Summary collapse

Constructor Details

#initialize(year, month) ⇒ Month

Returns a new instance of Month.



45
46
47
48
49
# File 'lib/calrom/date_range.rb', line 45

def initialize(year, month)
  @year = year
  @month = month
  super Date.new(year, month, 1), next_month_beginning - 1
end

Instance Method Details

#<=>(other) ⇒ Object



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

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



55
56
57
58
59
# File 'lib/calrom/date_range.rb', line 55

def each_month
  return to_enum(:each_month) unless block_given?

  yield self
end

#succObject



61
62
63
64
# File 'lib/calrom/date_range.rb', line 61

def succ
  n = next_month_beginning
  self.class.new(n.year, n.month)
end

#to_sObject



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

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