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, vespers: false, cache: {}) ⇒ PerpetualCalendar
constructor
A new instance of PerpetualCalendar.
Constructor Details
#initialize(sanctorale: nil, temporale_factory: nil, temporale_options: nil, vespers: false, cache: {}) ⇒ PerpetualCalendar
Returns a new instance of PerpetualCalendar.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/calendarium-romanum/perpetual_calendar.rb', line 34 def initialize(sanctorale: nil, temporale_factory: nil, temporale_options: nil, vespers: false, 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() @vespers = vespers @cache = cache end |
Instance Method Details
#[](arg) ⇒ Day+
55 56 57 58 59 60 61 62 63 |
# File 'lib/calendarium-romanum/perpetual_calendar.rb', line 55 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
71 72 73 74 75 |
# File 'lib/calendarium-romanum/perpetual_calendar.rb', line 71 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
81 82 83 |
# File 'lib/calendarium-romanum/perpetual_calendar.rb', line 81 def calendar_for_year(year) calendar_instance year end |
#day(*args) ⇒ Day
48 49 50 |
# File 'lib/calendarium-romanum/perpetual_calendar.rb', line 48 def day(*args) calendar_for(*args).day(*args) end |