Class: CalendariumRomanum::Temporale

Inherits:
Object
  • Object
show all
Defined in:
lib/calendarium-romanum/temporale.rb,
lib/calendarium-romanum/temporale/dates.rb,
lib/calendarium-romanum/temporale/celebration_factory.rb,
lib/calendarium-romanum/temporale/extensions/christ_eternal_priest.rb

Overview

determine seasons and dates of Temporale feasts of the given year

Defined Under Namespace

Modules: Dates, Extensions Classes: CelebrationFactory

Constant Summary collapse

WEEK =
7
SUNDAY_TRANSFERABLE_SOLEMNITIES =
%i(epiphany ascension corpus_christi).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, extensions: [], transfer_to_sunday: []) ⇒ Temporale

year is Integer - the civil year when the liturgical year begins



14
15
16
17
18
19
20
21
22
# File 'lib/calendarium-romanum/temporale.rb', line 14

def initialize(year, extensions: [], transfer_to_sunday: [])
  @year = year

  @extensions = extensions
  @transfer_to_sunday = transfer_to_sunday.sort
  validate_sunday_transfer!

  prepare_solemnities
end

Instance Attribute Details

#yearObject (readonly)

Returns the value of attribute year.



24
25
26
# File 'lib/calendarium-romanum/temporale.rb', line 24

def year
  @year
end

Class Method Details

.celebrationsObject

implementation detail, not to be touched by client code



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/calendarium-romanum/temporale.rb', line 55

def celebrations
  @celebrations ||=
    begin
      %i(
        nativity
        holy_family
        mother_of_god
        epiphany
        baptism_of_lord
        ash_wednesday
        good_friday
        holy_saturday
        palm_sunday
        easter_sunday
        ascension
        pentecost
        holy_trinity
        corpus_christi
        mother_of_church
        sacred_heart
        christ_king
        immaculate_heart
      ).collect do |symbol|
        date_method = symbol
        C.new(
          date_method,
          CelebrationFactory.public_send(symbol)
        )
      end
      # Immaculate Heart of Mary and Mary, Mother of the Church
      # are actually movable *sanctorale* feasts,
      # but as it would make little sense
      # to add support for movable sanctorale feasts because of
      # two, we cheat a bit and handle them in temporale.
    end
end

.create_celebration(title, rank, colour, symbol: nil, date: nil) ⇒ Object

factory method creating temporale celebrations with sensible defaults



47
48
49
# File 'lib/calendarium-romanum/temporale.rb', line 47

def create_celebration(title, rank, colour, symbol: nil, date: nil)
  Celebration.new(title, rank, colour, symbol, date, :temporale)
end

.for_day(date) ⇒ Object

creates a Calendar for the liturgical year including given date



41
42
43
# File 'lib/calendarium-romanum/temporale.rb', line 41

def for_day(date)
  new(liturgical_year(date))
end

.liturgical_year(date) ⇒ Object

Determines liturgical year for the given date



28
29
30
31
32
33
34
35
36
37
# File 'lib/calendarium-romanum/temporale.rb', line 28

def liturgical_year(date)
  year = date.year
  temporale = Temporale.new year

  if date < temporale.first_advent_sunday
    return year - 1
  end

  year
end

Instance Method Details

#==(b) ⇒ Object



222
223
224
225
226
227
# File 'lib/calendarium-romanum/temporale.rb', line 222

def ==(b)
  self.class == b.class &&
    year == b.year &&
    transfer_to_sunday == b.transfer_to_sunday &&
    Set.new(extensions) == Set.new(b.extensions)
end

#[](date) ⇒ Object



200
201
202
# File 'lib/calendarium-romanum/temporale.rb', line 200

def [](date)
  @solemnities[date] || @feasts[date] || sunday(date) || @memorials[date] || ferial(date)
end

#date_rangeObject



105
106
107
# File 'lib/calendarium-romanum/temporale.rb', line 105

def date_range
  start_date .. end_date
end

#end_dateObject



101
102
103
# File 'lib/calendarium-romanum/temporale.rb', line 101

def end_date
  Dates.first_advent_sunday(year + 1) - 1
end

#get(*args) ⇒ Object

returns a Celebration scheduled for the given day

expected arguments: Date or two Integers (month, day)



208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/calendarium-romanum/temporale.rb', line 208

def get(*args)
  if args.size == 1 && args[0].is_a?(Date)
    date = args[0]
  else
    month, day = args
    date = Date.new @year, month, day
    unless date_range.include? date
      date = Date.new @year + 1, month, day
    end
  end

  self[date]
end

#range_check(date) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/calendarium-romanum/temporale.rb', line 109

def range_check(date)
  # necessary in order to handle Date correctly
  date = date.to_date if date.class != Date

  unless date_range.include? date
    raise RangeError.new "Date out of range #{date}"
  end
end

#season(date) ⇒ Object

which liturgical season is it?



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/calendarium-romanum/temporale.rb', line 136

def season(date)
  range_check date

  if (first_advent_sunday <= date) &&
     nativity > date
    Seasons::ADVENT

  elsif (nativity <= date) &&
        (baptism_of_lord >= date)
    Seasons::CHRISTMAS

  elsif (ash_wednesday <= date) &&
        easter_sunday > date
    Seasons::LENT

  elsif (easter_sunday <= date) &&
        (pentecost >= date)
    Seasons::EASTER

  else
    Seasons::ORDINARY
  end
end

#season_beginning(s) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/calendarium-romanum/temporale.rb', line 160

def season_beginning(s)
  case s
  when Seasons::ADVENT
    first_advent_sunday
  when Seasons::CHRISTMAS
    nativity
  when Seasons::LENT
    ash_wednesday
  when Seasons::EASTER
    easter_sunday
  when Seasons::ORDINARY # ordinary time
    baptism_of_lord + 1
  else
    raise ArgumentError.new('unsupported season')
  end
end

#season_week(seasonn, date) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/calendarium-romanum/temporale.rb', line 177

def season_week(seasonn, date)
  week1_beginning = season_beginning = season_beginning(seasonn)
  unless season_beginning.sunday?
    week1_beginning = Dates.sunday_after(season_beginning)
  end

  week = date_difference(date, week1_beginning) / WEEK + 1

  if seasonn == Seasons::ORDINARY
    # ordinary time does not begin with Sunday, but the first week
    # is week 1, not 0
    week += 1

    if date > pentecost
      weeks_after_date = date_difference(Dates.first_advent_sunday(@year + 1), date) / WEEK
      week = 34 - weeks_after_date
      week += 1 if date.sunday?
    end
  end

  week
end

#start_dateObject



97
98
99
# File 'lib/calendarium-romanum/temporale.rb', line 97

def start_date
  first_advent_sunday
end

#transferred_to_sunday?(solemnity) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/calendarium-romanum/temporale.rb', line 93

def transferred_to_sunday?(solemnity)
  @transfer_to_sunday.include?(solemnity)
end