class Calendario::Month

Any of the twelve parts, as January or February, into which the calendar year is divided

Constants

LAST_DAY_OF_THE_WEEK

The last day of the week is Saturday, in conformity with Ruby's standard library

MONTH_NAMES

List of month names (January, February, etc)

Attributes

days[R]

Array of 28 to 31 days, depending on the month

@api private @return [Array<Date>]

month_number[R]

The month's number from 1 to 12

@api private @return [Integer]

year_number[R]

The primitive numeric representation of a year

@api private @return [Integer]

Public Class Methods

new(year_number, month_number) click to toggle source

Initialize a month

@api private @param [Integer] year_number The primitive numeric representation of a year @param [Integer] month_number The month's number from 1 to 12

# File lib/calendario/month.rb, line 39
def initialize(year_number, month_number)
  @year_number = year_number
  @month_number = month_number
  @days = (first_day..last_day).to_a
end

Public Instance Methods

<=>(other) click to toggle source

Operator to sorts months in chronological order

@api private @param [Month] other @return [Integer]

# File lib/calendario/month.rb, line 102
def <=>(other)
  (year_number <=> other.year_number).nonzero? || month_number <=> other.month_number
end
first_day() click to toggle source

First day of the month

@api private @return [Date]

# File lib/calendario/month.rb, line 50
def first_day
  @first_day ||= Date.new(year_number, month_number, 1)
end
last_day() click to toggle source

Last day of the month

@api private @return [Date]

# File lib/calendario/month.rb, line 59
def last_day
  @last_day ||= Date.new(year_number, month_number, -1)
end
name() click to toggle source

Full name of the month (ex: January)

@api private @return [String]

# File lib/calendario/month.rb, line 79
def name
  MONTH_NAMES[month_number]
end
succ() click to toggle source

The following month

@api private @return [Month]

# File lib/calendario/month.rb, line 88
def succ
  if month_number == 12
    self.class.new(year_number + 1, 1)
  else
    self.class.new(year_number, month_number + 1)
  end
end
weeks() click to toggle source

Array of weeks in the month. Weeks start on Sunday and end on Saturday

@api private @return [Array<Date>]

# File lib/calendario/month.rb, line 68
def weeks
  @weeks ||= days.slice_when do |day|
    Date::DAYNAMES[day.wday] == LAST_DAY_OF_THE_WEEK
  end.to_a
end