Class: Calendario::Month
- Inherits:
-
Object
- Object
- Calendario::Month
- 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
-
#days ⇒ Array<Date>
readonly
private
Array of 28 to 31 days, depending on the month.
-
#month_number ⇒ Integer
readonly
private
The month’s number from 1 to 12.
-
#year_number ⇒ Integer
readonly
private
The primitive numeric representation of a year.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
private
Operator to sorts months in chronological order.
-
#first_day ⇒ Date
private
First day of the month.
-
#initialize(year_number, month_number) ⇒ Month
constructor
private
Initialize a month.
-
#last_day ⇒ Date
private
Last day of the month.
-
#name ⇒ String
private
Full name of the month (ex: January).
-
#succ ⇒ Month
private
The following month.
-
#weeks ⇒ Array<Date>
private
Array of weeks in the month.
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
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
#days ⇒ Array<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
17 18 19 |
# File 'lib/calendario/month.rb', line 17 def days @days end |
#month_number ⇒ Integer (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
24 25 26 |
# File 'lib/calendario/month.rb', line 24 def month_number @month_number end |
#year_number ⇒ Integer (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
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
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_day ⇒ 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.
First day of the month
50 51 52 |
# File 'lib/calendario/month.rb', line 50 def first_day @first_day ||= Date.new(year_number, month_number, 1) end |
#last_day ⇒ 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.
Last day of the month
59 60 61 |
# File 'lib/calendario/month.rb', line 59 def last_day @last_day ||= Date.new(year_number, month_number, -1) end |
#name ⇒ String
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)
79 80 81 |
# File 'lib/calendario/month.rb', line 79 def name MONTH_NAMES[month_number] end |
#succ ⇒ 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.
The following month
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 |
#weeks ⇒ Array<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
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 |