Class: Calendario::Year

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

Overview

A period of 365 or 366 days, in the Gregorian calendar, divided into 12 calendar months

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year_number = 2020) ⇒ Year

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 year

Parameters:

  • year_number (Integer) (defaults to: 2020)

    The primitive numeric representation of a year



26
27
28
29
30
31
# File 'lib/calendario/year.rb', line 26

def initialize(year_number = 2020)
  @year_number = year_number
  @months = 1.upto(12).map do |month_number|
    Month.new(year_number, month_number)
  end
end

Instance Attribute Details

#monthsArray<Month> (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 all calendar months

Returns:



12
13
14
# File 'lib/calendario/year.rb', line 12

def months
  @months
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)


19
20
21
# File 'lib/calendario/year.rb', line 19

def year_number
  @year_number
end

Instance Method Details

#daysDate

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.

An array of 365 or 365 dates representing every day of the year

Returns:

  • (Date)


56
57
58
# File 'lib/calendario/year.rb', line 56

def days
  @days ||= months.map(&:days).flatten
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.

The first day of the year (1st of January)

Returns:

  • (Date)


38
39
40
# File 'lib/calendario/year.rb', line 38

def first_day
  @first_day ||= months.first.first_day
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.

The last day of the year (31st of December)

Returns:

  • (Date)


47
48
49
# File 'lib/calendario/year.rb', line 47

def last_day
  @last_day ||= months.last.last_day
end