Class: CalendariumRomanum::PerpetualCalendar
- Inherits:
-
Object
- Object
- CalendariumRomanum::PerpetualCalendar
- Defined in:
- lib/calendarium-romanum/perpetual_calendar.rb
Overview
Has mostly the same public interface as Calendar, but represents a “perpetual” calendar, not a calendar for a single year, thus allowing the client code to query for liturgical data of any day, without bothering about boundaries of liturgical years.
Internally builds Calendar instances as needed and delegates method calls to them.
Instance Method Summary collapse
- #[](arg) ⇒ Day+
-
#calendar_for(*args) ⇒ Calendar
Returns a Calendar instance for the liturgical year containing the specified day.
-
#calendar_for_year(year) ⇒ Calendar
Returns a Calendar instance for the specified liturgical year.
- #day(*args) ⇒ Day
-
#initialize(sanctorale: nil, temporale_factory: nil, temporale_options: nil, cache: {}) ⇒ PerpetualCalendar
constructor
A new instance of PerpetualCalendar.
Constructor Details
#initialize(sanctorale: nil, temporale_factory: nil, temporale_options: nil, cache: {}) ⇒ PerpetualCalendar
Returns a new instance of PerpetualCalendar.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/calendarium-romanum/perpetual_calendar.rb', line 32 def initialize(sanctorale: nil, temporale_factory: nil, temporale_options: nil, cache: {}) if temporale_factory && raise ArgumentError.new('Specify either temporale_factory or temporale_options, not both') end @sanctorale = sanctorale @temporale_factory = temporale_factory || build_temporale_factory() @cache = cache end |
Instance Method Details
#[](arg) ⇒ Day+
52 53 54 55 56 57 58 59 60 |
# File 'lib/calendarium-romanum/perpetual_calendar.rb', line 52 def [](arg) if arg.is_a? Range return arg.collect do |date| calendar_for(date).day(date) end end day(arg) end |
#calendar_for(*args) ⇒ Calendar
Returns a Calendar instance for the liturgical year containing the specified day
Parameters like Calendar#day
68 69 70 71 72 |
# File 'lib/calendarium-romanum/perpetual_calendar.rb', line 68 def calendar_for(*args) date = Calendar.mk_date(*args) year = Temporale.liturgical_year date calendar_instance year end |
#calendar_for_year(year) ⇒ Calendar
Returns a Calendar instance for the specified liturgical year
78 79 80 |
# File 'lib/calendarium-romanum/perpetual_calendar.rb', line 78 def calendar_for_year(year) calendar_instance year end |
#day(*args) ⇒ Day
45 46 47 |
# File 'lib/calendarium-romanum/perpetual_calendar.rb', line 45 def day(*args) calendar_for(*args).day(*args) end |