Class: Calendario::Month

Inherits:
Object
  • Object
show all
Defined in:
lib/calendario/month.rb

Overview

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

Constant Summary collapse

MONTH_NAMES =

List of month names (January, February, etc)

Date::MONTHNAMES.freeze
LAST_DAY_OF_THE_WEEK =

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

'Saturday'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year_number, month_number) ⇒ Month

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a month

Parameters:

  • year_number (Integer)

    The primitive numeric representation of a year

  • month_number (Integer)

    The month’s number from 1 to 12



39
40
41
42
43
# 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

Instance Attribute Details

#daysArray<Date> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Array of 28 to 31 days, depending on the month

Returns:

  • (Array<Date>)


17
18
19
# File 'lib/calendario/month.rb', line 17

def days
  @days
end

#month_numberInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The month’s number from 1 to 12

Returns:

  • (Integer)


24
25
26
# File 'lib/calendario/month.rb', line 24

def month_number
  @month_number
end

#year_numberInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The primitive numeric representation of a year

Returns:

  • (Integer)


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

def year_number
  @year_number
end

Instance Method Details

#<=>(other) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Operator to sorts months in chronological order

Parameters:

Returns:

  • (Integer)


102
103
104
# File 'lib/calendario/month.rb', line 102

def <=>(other)
  (year_number <=> other.year_number).nonzero? || month_number <=> other.month_number
end

#first_dayDate

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

First day of the month

Returns:

  • (Date)


50
51
52
# File 'lib/calendario/month.rb', line 50

def first_day
  @first_day ||= Date.new(year_number, month_number, 1)
end

#last_dayDate

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Last day of the month

Returns:

  • (Date)


59
60
61
# File 'lib/calendario/month.rb', line 59

def last_day
  @last_day ||= Date.new(year_number, month_number, -1)
end

#nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Full name of the month (ex: January)

Returns:

  • (String)


79
80
81
# File 'lib/calendario/month.rb', line 79

def name
  MONTH_NAMES[month_number]
end

#succMonth

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The following month

Returns:



88
89
90
91
92
93
94
# 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

#weeksArray<Date>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns:

  • (Array<Date>)


68
69
70
71
72
# 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