calendarium-romanum 0.4.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.rubocop.yml +47 -0
- data/.travis.yml +22 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +431 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +86 -0
- data/README.md +598 -0
- data/Rakefile +16 -0
- data/bin/calendariumrom +4 -1
- data/calendarium-romanum.gemspec +31 -0
- data/config/locales/cs.yml +5 -0
- data/config/locales/en.yml +21 -14
- data/config/locales/es.yml +94 -0
- data/config/locales/fr.yml +7 -0
- data/config/locales/it.yml +7 -0
- data/config/locales/la.yml +7 -0
- data/data/README.md +70 -24
- data/data/czech-brno-cs.txt +4 -6
- data/data/czech-budejovice-cs.txt +4 -6
- data/data/czech-cechy-cs.txt +4 -5
- data/data/czech-cs.txt +236 -234
- data/data/czech-hradec-cs.txt +3 -5
- data/data/czech-litomerice-cs.txt +5 -7
- data/data/czech-morava-cs.txt +4 -5
- data/data/czech-olomouc-cs.txt +2 -4
- data/data/czech-ostrava-cs.txt +3 -5
- data/data/czech-plzen-cs.txt +3 -5
- data/data/czech-praha-cs.txt +3 -4
- data/data/easter_dates.txt +67 -0
- data/data/universal-1969-la.txt +234 -0
- data/data/universal-en.txt +214 -211
- data/data/universal-es.txt +243 -0
- data/data/universal-fr.txt +214 -210
- data/data/universal-it.txt +214 -211
- data/data/universal-la.txt +214 -210
- data/doc/data_readme.md +2 -0
- data/doc/images/class_diagram.png +0 -0
- data/doc/images/class_diagram.puml +44 -0
- data/doc/yard_readme.rdoc +76 -0
- data/lib/calendarium-romanum.rb +35 -22
- data/lib/calendarium-romanum/abstract_date.rb +15 -0
- data/lib/calendarium-romanum/calendar.rb +207 -42
- data/lib/calendarium-romanum/cli.rb +63 -80
- data/lib/calendarium-romanum/cli/comparator.rb +63 -0
- data/lib/calendarium-romanum/cli/date_parser.rb +30 -0
- data/lib/calendarium-romanum/cli/dumper.rb +68 -0
- data/lib/calendarium-romanum/cli/helper.rb +23 -0
- data/lib/calendarium-romanum/cli/querier.rb +73 -0
- data/lib/calendarium-romanum/cr.rb +16 -0
- data/lib/calendarium-romanum/data.rb +50 -20
- data/lib/calendarium-romanum/day.rb +208 -32
- data/lib/calendarium-romanum/enum.rb +42 -25
- data/lib/calendarium-romanum/enums.rb +124 -44
- data/lib/calendarium-romanum/errors.rb +4 -0
- data/lib/calendarium-romanum/ordinalizer.rb +23 -2
- data/lib/calendarium-romanum/perpetual_calendar.rb +58 -7
- data/lib/calendarium-romanum/rank.rb +43 -12
- data/lib/calendarium-romanum/rank_predicates.rb +43 -0
- data/lib/calendarium-romanum/sanctorale.rb +164 -24
- data/lib/calendarium-romanum/sanctorale_factory.rb +74 -3
- data/lib/calendarium-romanum/sanctorale_loader.rb +180 -0
- data/lib/calendarium-romanum/sanctorale_writer.rb +119 -0
- data/lib/calendarium-romanum/temporale.rb +226 -94
- data/lib/calendarium-romanum/temporale/celebration_factory.rb +107 -0
- data/lib/calendarium-romanum/temporale/dates.rb +84 -16
- data/lib/calendarium-romanum/temporale/easter_table.rb +27 -0
- data/lib/calendarium-romanum/temporale/extensions.rb +15 -0
- data/lib/calendarium-romanum/temporale/extensions/christ_eternal_priest.rb +16 -3
- data/lib/calendarium-romanum/temporale/extensions/dedication_before_all_saints.rb +73 -0
- data/lib/calendarium-romanum/transfers.rb +60 -15
- data/lib/calendarium-romanum/util.rb +22 -3
- data/lib/calendarium-romanum/version.rb +5 -1
- data/liturgical_law/1969_normae_universales.md +568 -0
- data/liturgical_law/1977_decretum_de_celebratione_baptismatis_domini.md +58 -0
- data/liturgical_law/1990_decretum_de_variatione_inducenda.md +67 -0
- data/liturgical_law/1998_notificatio_de_occurrentia.md +57 -0
- data/liturgical_law/2002_normae_universales.md +946 -0
- data/liturgical_law/2006_notification.md +37 -0
- data/liturgical_law/2012_declarationes.md +38 -0
- data/liturgical_law/README.md +74 -0
- metadata +50 -28
- data/lib/calendarium-romanum/sanctoraleloader.rb +0 -115
- data/spec/abstract_date_spec.rb +0 -62
- data/spec/calendar_spec.rb +0 -330
- data/spec/celebration_spec.rb +0 -23
- data/spec/cli_spec.rb +0 -26
- data/spec/colour_spec.rb +0 -17
- data/spec/data_spec.rb +0 -23
- data/spec/date_spec.rb +0 -61
- data/spec/dates_spec.rb +0 -45
- data/spec/day_spec.rb +0 -59
- data/spec/enum_spec.rb +0 -51
- data/spec/i18n_spec.rb +0 -59
- data/spec/ordinalizer_spec.rb +0 -22
- data/spec/perpetual_calendar_spec.rb +0 -91
- data/spec/rank_spec.rb +0 -57
- data/spec/readme_spec.rb +0 -52
- data/spec/sanctorale_factory_spec.rb +0 -42
- data/spec/sanctorale_spec.rb +0 -191
- data/spec/sanctoraleloader_spec.rb +0 -171
- data/spec/season_spec.rb +0 -17
- data/spec/spec_helper.rb +0 -35
- data/spec/temporale_spec.rb +0 -519
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'thor'
|
4
|
+
gem 'i18n'
|
5
|
+
gem 'roman-numerals'
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem 'rake'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :development do
|
12
|
+
gem 'rubocop'
|
13
|
+
gem 'yard'
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem 'rspec'
|
18
|
+
gem 'aruba'
|
19
|
+
# We don't use cucumber, but it is required by aruba
|
20
|
+
# and cucumber >= 3.0.0 requires ruby >= 2.1,
|
21
|
+
# but we want the tests to pass on ruby 2.0 as earliest target
|
22
|
+
gem 'cucumber', '~> 2.99'
|
23
|
+
gem 'simplecov'
|
24
|
+
gem 'backports', '~> 3.18'
|
25
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
aruba (0.8.1)
|
5
|
+
childprocess (~> 0.5.6)
|
6
|
+
contracts (~> 0.9)
|
7
|
+
cucumber (>= 1.3.19)
|
8
|
+
rspec-expectations (>= 2.99)
|
9
|
+
ast (2.3.0)
|
10
|
+
backports (3.18.1)
|
11
|
+
builder (3.2.3)
|
12
|
+
childprocess (0.5.9)
|
13
|
+
ffi (~> 1.0, >= 1.0.11)
|
14
|
+
contracts (0.16.0)
|
15
|
+
cucumber (2.99.0)
|
16
|
+
builder (>= 2.1.2)
|
17
|
+
cucumber-core (~> 1.5.0)
|
18
|
+
cucumber-wire (~> 0.0.1)
|
19
|
+
diff-lcs (>= 1.1.3)
|
20
|
+
gherkin (~> 4.0)
|
21
|
+
multi_json (>= 1.7.5, < 2.0)
|
22
|
+
multi_test (>= 0.1.2)
|
23
|
+
cucumber-core (1.5.0)
|
24
|
+
gherkin (~> 4.0)
|
25
|
+
cucumber-wire (0.0.1)
|
26
|
+
diff-lcs (1.3)
|
27
|
+
docile (1.1.5)
|
28
|
+
ffi (1.9.18)
|
29
|
+
gherkin (4.1.3)
|
30
|
+
i18n (0.6.9)
|
31
|
+
json (2.0.2)
|
32
|
+
multi_json (1.12.2)
|
33
|
+
multi_test (0.1.2)
|
34
|
+
parser (2.4.0.0)
|
35
|
+
ast (~> 2.2)
|
36
|
+
powerpack (0.1.1)
|
37
|
+
rainbow (2.1.0)
|
38
|
+
rake (12.0.0)
|
39
|
+
roman-numerals (0.3.0)
|
40
|
+
rspec (3.7.0)
|
41
|
+
rspec-core (~> 3.7.0)
|
42
|
+
rspec-expectations (~> 3.7.0)
|
43
|
+
rspec-mocks (~> 3.7.0)
|
44
|
+
rspec-core (3.7.0)
|
45
|
+
rspec-support (~> 3.7.0)
|
46
|
+
rspec-expectations (3.7.0)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.7.0)
|
49
|
+
rspec-mocks (3.7.0)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.7.0)
|
52
|
+
rspec-support (3.7.0)
|
53
|
+
rubocop (0.46.0)
|
54
|
+
parser (>= 2.3.1.1, < 3.0)
|
55
|
+
powerpack (~> 0.1)
|
56
|
+
rainbow (>= 1.99.1, < 3.0)
|
57
|
+
ruby-progressbar (~> 1.7)
|
58
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
59
|
+
ruby-progressbar (1.8.1)
|
60
|
+
simplecov (0.12.0)
|
61
|
+
docile (~> 1.1.0)
|
62
|
+
json (>= 1.8, < 3)
|
63
|
+
simplecov-html (~> 0.10.0)
|
64
|
+
simplecov-html (0.10.0)
|
65
|
+
thor (0.18.1)
|
66
|
+
unicode-display_width (1.1.2)
|
67
|
+
yard (0.9.16)
|
68
|
+
|
69
|
+
PLATFORMS
|
70
|
+
ruby
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
aruba
|
74
|
+
backports (~> 3.18)
|
75
|
+
cucumber (~> 2.99)
|
76
|
+
i18n
|
77
|
+
rake
|
78
|
+
roman-numerals
|
79
|
+
rspec
|
80
|
+
rubocop
|
81
|
+
simplecov
|
82
|
+
thor
|
83
|
+
yard
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
1.16.6
|
data/README.md
ADDED
@@ -0,0 +1,598 @@
|
|
1
|
+
# calendarium-romanum
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/igneus/calendarium-romanum.svg?branch=master)](https://travis-ci.org/igneus/calendarium-romanum)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/calendarium-romanum.svg)](https://badge.fury.io/rb/calendarium-romanum)
|
5
|
+
|
6
|
+
API documentation:
|
7
|
+
[0.8.0](http://www.rubydoc.info/gems/calendarium-romanum/0.8.0)
|
8
|
+
[0.7.1](http://www.rubydoc.info/gems/calendarium-romanum/0.7.1)
|
9
|
+
[0.6.0](http://www.rubydoc.info/gems/calendarium-romanum/0.6.0)
|
10
|
+
[0.5.0](http://www.rubydoc.info/gems/calendarium-romanum/0.5.0)
|
11
|
+
[0.4.0](http://www.rubydoc.info/gems/calendarium-romanum/0.4.0)
|
12
|
+
[0.3.0](http://www.rubydoc.info/gems/calendarium-romanum/0.3.0)
|
13
|
+
[0.2.0](http://www.rubydoc.info/gems/calendarium-romanum/0.2.0)
|
14
|
+
|
15
|
+
Ruby gem for
|
16
|
+
calendar computations according to the Roman Catholic liturgical calendar as instituted by
|
17
|
+
[MP Mysterii Paschalis](http://w2.vatican.va/content/paul-vi/en/motu_proprio/documents/hf_p-vi_motu-proprio_19690214_mysterii-paschalis.html)
|
18
|
+
of Paul VI. (AAS 61 (1969), pp. 222-226),
|
19
|
+
defined in *General Norms for the Liturgical Year and the Calendar*
|
20
|
+
([English translation][gnlyc])
|
21
|
+
and subsequent [documents of liturgical legislation][liturgical_law].
|
22
|
+
|
23
|
+
`calendarium-romanum` aspires to become the most complete and most accurate
|
24
|
+
FOSS implementation of this calendar system
|
25
|
+
(see [list of implementations available][awesomecc]).
|
26
|
+
|
27
|
+
## Features
|
28
|
+
|
29
|
+
`calendarium-romanum` is now a **feature-complete** implementation of the abovementioned calendar
|
30
|
+
system, capable of generating a complete and (at least mostly) correct Roman Catholic liturgical
|
31
|
+
calendar for any year according to the most recent calendar rules and data
|
32
|
+
(i.e. today's state of the calendar is used also for years in the past - for historically accurate
|
33
|
+
computations see a [related project][crhistorical]).
|
34
|
+
|
35
|
+
It is **continuously kept up-to-date** with latest developments of the liturgical
|
36
|
+
legislation and newly introduced feasts.
|
37
|
+
|
38
|
+
**Accuracy** is highly valued. Therefore just a very limited set of calendar data
|
39
|
+
is bundled in the library, but with a guarantee that a theologian continuously takes care
|
40
|
+
of them being up-to-date and correct. Users of the library will usually want to prepare
|
41
|
+
and maintain their own data files representing their local calendars.
|
42
|
+
(For ready-to-use calendar data without guarantees of correctness
|
43
|
+
see a [related repository][data-contrib].)
|
44
|
+
|
45
|
+
The project's scope is strictly limited to computing **liturgical calendar in a narrow sense.**
|
46
|
+
It doesn't provide functionality specific for individual liturgical books, unless it is
|
47
|
+
dealt with in general liturgical norms regarding the calendar.
|
48
|
+
(Liturgical colours being an exception from this rule, as it is very common to include
|
49
|
+
them in all kinds of liturgical calendars.)
|
50
|
+
But the library is designed with machine-readability in mind, so that additional layers
|
51
|
+
of functionality, implementing book-specific calculations, can be built upon it.
|
52
|
+
|
53
|
+
Strings are **localized** (using the [i18n][i18n] Ruby gem). Translations to six languages
|
54
|
+
(Latin, English, Spanish, French, Italian, Czech)
|
55
|
+
are provided. The built-in translations can be both replaced and/or supplemented
|
56
|
+
with translations to additional languages without having to modify the gem's code.
|
57
|
+
|
58
|
+
## Credits
|
59
|
+
|
60
|
+
includes computation of the Easter date from the
|
61
|
+
[easter](https://github.com/jrobertson/easter) gem
|
62
|
+
by James Robertson.
|
63
|
+
|
64
|
+
See also changelog for list of contributions and their authors.
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
dual licensed: freely choose between GNU/LGPL 3 and MIT
|
69
|
+
|
70
|
+
## Project status
|
71
|
+
|
72
|
+
The library is currently considered feature-complete for release 1.0.0
|
73
|
+
and it's public API mostly stabilized.
|
74
|
+
Development focuses on reaching higher degree of certainty regarding
|
75
|
+
correctness by means of making the test suite more comprehensive and rigorous.
|
76
|
+
|
77
|
+
## Backward compatibility
|
78
|
+
|
79
|
+
The gem's public interface has now been mostly stabilized, but until v1.0.0 release
|
80
|
+
there is still no guaranteed backward compatibility between minor versions.
|
81
|
+
|
82
|
+
When using the gem in your projects, it is recommended to lock
|
83
|
+
the dependency to a particular minor version.
|
84
|
+
|
85
|
+
In your app's Gemfile
|
86
|
+
|
87
|
+
```
|
88
|
+
gem 'calendarium-romanum', '~>0.8.0'
|
89
|
+
```
|
90
|
+
|
91
|
+
or in gemspec of your gem
|
92
|
+
|
93
|
+
```
|
94
|
+
spec.add_dependency 'calendarium-romanum', '~>0.8.0'
|
95
|
+
```
|
96
|
+
|
97
|
+
## Usage
|
98
|
+
|
99
|
+
All the examples below expect that you first required the gem:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
require 'calendarium-romanum'
|
103
|
+
```
|
104
|
+
|
105
|
+
### 1. Typical usage
|
106
|
+
|
107
|
+
The easiest way to obtain calendar entry of a liturgical day:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
I18n.locale = :en # set locale
|
111
|
+
|
112
|
+
# build calendar
|
113
|
+
pcal = CalendariumRomanum::PerpetualCalendar.new(
|
114
|
+
sanctorale: CalendariumRomanum::Data::GENERAL_ROMAN_ENGLISH.load
|
115
|
+
)
|
116
|
+
|
117
|
+
# query
|
118
|
+
day = pcal[Date.new(2000, 1, 1)]
|
119
|
+
```
|
120
|
+
|
121
|
+
For explanation see the detailed steps below.
|
122
|
+
|
123
|
+
### 2. What liturgical day is it today?
|
124
|
+
|
125
|
+
`PerpetualCalendar` used in the example above is a high-level API.
|
126
|
+
In order to understand what's happening under the hood, we will
|
127
|
+
now take a lower-level approach and work on the level of a simple
|
128
|
+
`Calendar`.
|
129
|
+
Each `Calendar` instance describes a particular *liturgical year*.
|
130
|
+
We may not know which liturgical year our day of interest
|
131
|
+
belongs to, but fortunately there is "alternative constructor"
|
132
|
+
`Calendar.for_day()` to rescue:
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
date = Date.new(2016, 8, 19)
|
136
|
+
calendar = CalendariumRomanum::Calendar.for_day(date)
|
137
|
+
day = calendar[date]
|
138
|
+
|
139
|
+
day.season # => #<CalendariumRomanum::Season:0x00000001d4cfa0 @symbol=:ordinary, @colour=#<CalendariumRomanum::Colour:0x00000001d4d928 @symbol=:green, @i18n_key="colour.green">, @i18n_key="temporale.season.ordinary">
|
140
|
+
day.season.equal? CalendariumRomanum::Seasons::ORDINARY # => true
|
141
|
+
|
142
|
+
day.celebrations
|
143
|
+
# => [#<CalendariumRomanum::Celebration:0x00000001c69cc8 @title="Friday, 20th week in Ordinary Time", @rank=#<CalendariumRomanum::Rank:0x00000001d4c708 @priority=3.13, @desc="rank.3_13", @short_desc="rank.short.ferial">, @colour=#<CalendariumRomanum::Colour:0x00000001d4d928 @symbol=:green, @i18n_key="colour.green">, @symbol=nil>]
|
144
|
+
c = day.celebrations.first
|
145
|
+
c.title # => "Friday, 20th week in Ordinary Time"
|
146
|
+
c.rank # => #<CalendariumRomanum::Rank:0x00000001d4c708 @priority=3.13, @desc="rank.3_13", @short_desc="rank.short.ferial">
|
147
|
+
c.rank.equal? CalendariumRomanum::Ranks::FERIAL # => true
|
148
|
+
c.rank < CalendariumRomanum::Ranks::MEMORIAL_PROPER # => true
|
149
|
+
c.colour
|
150
|
+
# => #<CalendariumRomanum::Colour:0x00000001d4d928 @symbol=:green, @i18n_key="colour.green">
|
151
|
+
```
|
152
|
+
|
153
|
+
`Calendar#[]` returns a single `Day`, describing a liturgical day.
|
154
|
+
Each day belongs to some `#season`; every day, we can choose from
|
155
|
+
one or more `#celebrations` to celebrate.
|
156
|
+
(The only case with multiple choices is combination of a ferial
|
157
|
+
with one or more optional memorials; higher-ranking celebrations
|
158
|
+
are always exclusive.)
|
159
|
+
|
160
|
+
Each `Celebration` is described by a `#title`, `#rank` and `#colour`.
|
161
|
+
|
162
|
+
### 3. But does it take feasts of saints in account?
|
163
|
+
|
164
|
+
Actually, no. Not yet. We need to load some calendar data first:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
CR = CalendariumRomanum
|
168
|
+
loader = CR::SanctoraleLoader.new
|
169
|
+
sanctorale = loader.load_from_file 'data/universal-en.txt' # insert path to your data file
|
170
|
+
date = Date.new(2016, 8, 19)
|
171
|
+
calendar = CR::Calendar.for_day(date, sanctorale)
|
172
|
+
day = calendar[date]
|
173
|
+
day.celebrations # => [#<CalendariumRomanum::Celebration:0x000000027d9590 @title="Friday, 20th week in Ordinary Time", @rank=#<CalendariumRomanum::Rank:0x000000029e1108 @priority=3.13, ... >, @colour=#<CalendariumRomanum::Colour:0x000000029e1f68 @symbol=:green>>, #<CalendariumRomanum::Celebration:0x000000029c96c0 @title="Saint John Eudes, priest", @rank=#<CalendariumRomanum::Rank:0x000000029e1180 @priority=3.12, ... >, @colour=#<CalendariumRomanum::Colour:0x000000029e1f18 @symbol=:white>>]
|
174
|
+
```
|
175
|
+
|
176
|
+
Unless a sanctorale is loaded, `Calendar` only counts with
|
177
|
+
temporale feasts, Sundays and ferials.
|
178
|
+
|
179
|
+
Note how we saved some typing by defining new constant `CR`
|
180
|
+
referencing the `CalendariumRomanum` module.
|
181
|
+
In fact you can save even more typing by replacing
|
182
|
+
`require 'calendarium-romanum'`
|
183
|
+
by
|
184
|
+
`require 'calendarium-romanum/cr'`
|
185
|
+
which loads the gem *and* defines the `CR` shortcut for you.
|
186
|
+
Following examples expect the `CR` constant to be defined
|
187
|
+
and reference the `CalendariumRomanum` module.
|
188
|
+
|
189
|
+
Another possible way of saving some typing (if you don't care about
|
190
|
+
possible name clashes or polluting current namespace)
|
191
|
+
is including `CalendariumRomanum` module in the current module.
|
192
|
+
Then `CalendariumRomanum` classes can be referenced unqualified:
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
include CalendariumRomanum
|
196
|
+
|
197
|
+
loader = SanctoraleLoader.new
|
198
|
+
# etc.
|
199
|
+
```
|
200
|
+
|
201
|
+
### 4. Isn't there an easier way to get sanctorale data?
|
202
|
+
|
203
|
+
Yes! There are a few data files bundled in the gem.
|
204
|
+
You can explore them by iterating over `CalendariumRomanum::Data.all`.
|
205
|
+
Those of general interest are additionally identified by their proper
|
206
|
+
constants, e.g. `CalendariumRomanum::Data::GENERAL_ROMAN_ENGLISH`.
|
207
|
+
Bundled data files can be loaded by a handy shortcut method `#load`:
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
sanctorale = CR::Data::GENERAL_ROMAN_ENGLISH.load # easy loading
|
211
|
+
date = Date.new(2016, 8, 19)
|
212
|
+
calendar = CR::Calendar.for_day(date, sanctorale)
|
213
|
+
day = calendar[date]
|
214
|
+
```
|
215
|
+
|
216
|
+
### 5. I don't want to care about (liturgical) years
|
217
|
+
|
218
|
+
Each Calendar instance is bound to a particular *liturgical* year.
|
219
|
+
Calling `Calendar#[]` with a date out of the year's range
|
220
|
+
results in a `RangeError`:
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
calendar = CR::Calendar.new(2000)
|
224
|
+
begin
|
225
|
+
day = calendar[Date.new(2000, 1, 1)]
|
226
|
+
rescue RangeError
|
227
|
+
STDERR.puts 'ouch' # will happen
|
228
|
+
end
|
229
|
+
```
|
230
|
+
|
231
|
+
The example demonstrates the well known fact,
|
232
|
+
that the **civil and liturgical year don't match:**
|
233
|
+
1st January 2000
|
234
|
+
does not belong to the liturgical year 2000-2001
|
235
|
+
(which will begin on the first Sunday of Advent,
|
236
|
+
i.e. on 3rd December 2000), but to the year 1999-2000.
|
237
|
+
For the sake of simplicity, `calendarium-romanum` denotes
|
238
|
+
liturgical years by the starting year only, so you create
|
239
|
+
a `Calendar` for liturgical year 1999-2000 by calling
|
240
|
+
`Calendar.new(1999)`.
|
241
|
+
|
242
|
+
We have already seen `Calendar.for_day()`, which takes care
|
243
|
+
of finding the liturgical year a particular date belongs to
|
244
|
+
and creating a `Calendar` for this year.
|
245
|
+
But maybe you want to query a calendar without caring about liturgical
|
246
|
+
years altogether, possibly picking days across multiple years.
|
247
|
+
The best tool for such use cases is `PerpetualCalendar`.
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
pcal = CR::PerpetualCalendar.new
|
251
|
+
|
252
|
+
# get days
|
253
|
+
d1 = pcal[Date.new(2000, 1, 1)]
|
254
|
+
d2 = pcal[Date.new(2100, 1, 1)]
|
255
|
+
d3 = pcal[Date.new(1970, 1, 1)]
|
256
|
+
|
257
|
+
# get Calendar instances if you need them
|
258
|
+
calendar = pcal.calendar_for_year(1987)
|
259
|
+
```
|
260
|
+
|
261
|
+
Just like `Calendar` with the default settings (no sanctorale data
|
262
|
+
etc.) is usually of little use, so is a `PerpetualCalendar`
|
263
|
+
creating such `Calendar`s. Of course it is possible to specify
|
264
|
+
configuration which is then applied on the `Calendar`s
|
265
|
+
being created:
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
pcal = CR::PerpetualCalendar.new(
|
269
|
+
# Sanctorale instance
|
270
|
+
sanctorale: CR::Data::GENERAL_ROMAN_ENGLISH.load,
|
271
|
+
# options that will be passed to Temporale.new
|
272
|
+
temporale_options: {
|
273
|
+
transfer_to_sunday: [:epiphany],
|
274
|
+
extensions: [CR::Temporale::Extensions::ChristEternalPriest]
|
275
|
+
}
|
276
|
+
)
|
277
|
+
d = pcal[Date.new(2000, 1, 1)]
|
278
|
+
|
279
|
+
# It is also possible to supply Temporale factory instead of options:
|
280
|
+
pcal = CR::PerpetualCalendar.new(
|
281
|
+
# Proc returning a Temporale instance for the specified year
|
282
|
+
temporale_factory: lambda do |year|
|
283
|
+
CR::Temporale.new(year, transfer_to_sunday: [:ascension])
|
284
|
+
end
|
285
|
+
)
|
286
|
+
pcal[Date.new(2000, 1, 1)]
|
287
|
+
```
|
288
|
+
|
289
|
+
**Memory management note:**
|
290
|
+
Internally, `PerpetualCalendar` builds `Calendar` instances as needed
|
291
|
+
and by default caches them *perpetually.* This is OK in most cases,
|
292
|
+
but it can lead to memory exhaustion if you traverse an excessive
|
293
|
+
amount of liturgical years. In such cases you can supply
|
294
|
+
your own cache (a `Hash` or anything with hash-like interface)
|
295
|
+
and implement some kind of cache size limiting.
|
296
|
+
|
297
|
+
```ruby
|
298
|
+
my_cache = {}
|
299
|
+
pcal = CR::PerpetualCalendar.new(cache: my_cache)
|
300
|
+
```
|
301
|
+
|
302
|
+
## Sanctorale Data
|
303
|
+
|
304
|
+
### Use prepared data or create your own
|
305
|
+
|
306
|
+
The gem expects data files following a custom format -
|
307
|
+
see README in the [data](/data) directory for it's description.
|
308
|
+
The same directory contains a bunch of example data files.
|
309
|
+
(All of them are also bundled in the gem and accessible via
|
310
|
+
`CalendariumRomanum::Data`, as described above.)
|
311
|
+
|
312
|
+
`universal-en.txt` and `universal-la.txt` are data of the General
|
313
|
+
Roman Calendar in English and Latin.
|
314
|
+
|
315
|
+
The `czech-*.txt` files, when layered properly, can be used to assemble
|
316
|
+
proper calendar of any diocese in the Czech Republic.
|
317
|
+
|
318
|
+
### Implement custom loading strategy
|
319
|
+
|
320
|
+
In case you already have sanctorale data in another format,
|
321
|
+
it might be better suited for you to implement your own loading
|
322
|
+
routine instead of transforming them to our custom format.
|
323
|
+
`SanctoraleLoader` is the class to look into for inspiration.
|
324
|
+
|
325
|
+
The important bit is that for each celebration you
|
326
|
+
build a `Celebration` instance and push it in a `Sanctorale`
|
327
|
+
instance by a call to `Sanctorale#add`, which receives a month,
|
328
|
+
a day (as integers) and a `Celebration`:
|
329
|
+
|
330
|
+
```ruby
|
331
|
+
sanctorale = CR::Sanctorale.new
|
332
|
+
celebration = CR::Celebration.new('Saint John Eudes, priest', CR::Ranks::MEMORIAL_OPTIONAL, CR::Colours::WHITE)
|
333
|
+
sanctorale.add 8, 19, celebration
|
334
|
+
|
335
|
+
date = Date.new(2016, 8, 19)
|
336
|
+
calendar = CR::Calendar.for_day(date, sanctorale)
|
337
|
+
|
338
|
+
day = calendar[date]
|
339
|
+
day.celebrations # => [#<CalendariumRomanum::Celebration:0x000000010deea8 @title="", @rank=#<struct CalendariumRomanum::Rank priority=3.13, desc="Unprivileged ferials", short_desc="ferial">, @colour=:green>, #<CalendariumRomanum::Celebration:0x000000010fec08 @title="Saint John Eudes, priest", @rank=#<struct CalendariumRomanum::Rank priority=3.12, desc="Optional memorials", short_desc="optional memorial">, @colour=:white>]
|
340
|
+
```
|
341
|
+
|
342
|
+
### Proper calendar of a church
|
343
|
+
|
344
|
+
One common case of preparing custom sanctorale data is
|
345
|
+
implementing proper calendar of a church
|
346
|
+
(cf. *General Norms for the Liturgical Year and the Calendar* par. 52 c).
|
347
|
+
Proper calendar of a church is built by adding to the calendar
|
348
|
+
of the diocese (or religious institute) the church'es proper celebration,
|
349
|
+
which are usually just two solemnities: anniversary of dedication
|
350
|
+
and titular solemnity.
|
351
|
+
|
352
|
+
Let's say you have calendar of your diocese in sanctorale data file
|
353
|
+
`my-diocese.txt`.
|
354
|
+
You could copy the file to a new location and add the two proper solemnities,
|
355
|
+
but your programmer better self won't allow you to do that.
|
356
|
+
What options are left? You can create a new sanctorale file
|
357
|
+
with the two proper celebrations and then load it over the calendar
|
358
|
+
of the diocese, as explained in [data](/data).
|
359
|
+
Or, if you need the calendar just for that single little script
|
360
|
+
and don't care about creating data files, you can build the two
|
361
|
+
proper solemnities in code:
|
362
|
+
|
363
|
+
```ruby
|
364
|
+
# here you would load your 'diocese.txt' instead
|
365
|
+
diocese = CR::SanctoraleLoader.new.load_from_file 'data/universal-en.txt'
|
366
|
+
|
367
|
+
dedication = CR::Celebration.new('Anniversary of Dedication of the Parish Church', CR::Ranks::SOLEMNITY_PROPER, CR::Colours::WHITE)
|
368
|
+
titular = CR::Celebration.new('Saint Nicholas, Bishop, Titular Solemnity of the Parish Church', CR::Ranks::SOLEMNITY_PROPER, CR::Colours::WHITE)
|
369
|
+
|
370
|
+
# solution 1 - directly modify the loaded Sanctorale
|
371
|
+
|
372
|
+
diocese.replace(10, 25, [dedication])
|
373
|
+
diocese.replace(12, 6, [titular])
|
374
|
+
|
375
|
+
# solution 2 - create a new Sanctorale with just the two solemnities,
|
376
|
+
# then create a third instance merging contents of the two without modifying them
|
377
|
+
|
378
|
+
proper_solemnities = CR::Sanctorale.new
|
379
|
+
proper_solemnities.replace(10, 25, [dedication])
|
380
|
+
proper_solemnities.replace(12, 6, [titular])
|
381
|
+
|
382
|
+
complete_proper_calendar = CR::SanctoraleFactory.create_layered(diocese, proper_solemnities)
|
383
|
+
```
|
384
|
+
|
385
|
+
## I18n, or, how to fix names of temporale feasts
|
386
|
+
|
387
|
+
One drawback of the current implementation is that names
|
388
|
+
of *temporale* feasts are totally independent of *sanctorale* feast
|
389
|
+
names. They are hardcoded in the gem, as [i18n][]
|
390
|
+
[translation strings][translations].
|
391
|
+
|
392
|
+
When you load *sanctorale* data in your favourite language,
|
393
|
+
the `Calendar` will by default still produce *temporale*
|
394
|
+
feasts with names in English.
|
395
|
+
This can be fixed by changing locale to match your *sanctorale*
|
396
|
+
data.
|
397
|
+
|
398
|
+
`I18n.locale = :la # or :en, :fr, :it, :cs`
|
399
|
+
|
400
|
+
The gem ships with English, Latin, Italian, Spanish, French and Czech translation.
|
401
|
+
Contributed translations to other languages are most welcome.
|
402
|
+
|
403
|
+
## Transfer of solemnities to a Sunday
|
404
|
+
|
405
|
+
As specified in
|
406
|
+
[General Norms for the Liturgical Year and the Calendar][gnlyc] 7,
|
407
|
+
the solemnities of Epiphany, Ascension and Corpus Christi
|
408
|
+
can be transferred to a Sunday.
|
409
|
+
`Temporale` by default preserves the regular dates of these
|
410
|
+
solemnities, but it has an option to enable the transfer:
|
411
|
+
|
412
|
+
```ruby
|
413
|
+
# transfer all three to Sunday
|
414
|
+
temporale = CR::Temporale.new(2016, transfer_to_sunday: [:epiphany, :ascension, :corpus_christi])
|
415
|
+
```
|
416
|
+
|
417
|
+
Usually you don't want to work with `Temporale` alone, but with
|
418
|
+
a `Calendar`. In order to create a `Calendar` with non-default
|
419
|
+
`Temporale` settings, it is necessary to provide a `Temporale`
|
420
|
+
as third argument to the constructor.
|
421
|
+
|
422
|
+
```ruby
|
423
|
+
year = 2000
|
424
|
+
sanctorale = CR::Data::GENERAL_ROMAN_ENGLISH.load
|
425
|
+
temporale = CR::Temporale.new(year, transfer_to_sunday: [:epiphany])
|
426
|
+
|
427
|
+
calendar = CR::Calendar.new(year, sanctorale, temporale)
|
428
|
+
```
|
429
|
+
|
430
|
+
## Custom movable feasts
|
431
|
+
|
432
|
+
Some local calendars may include proper movable feasts.
|
433
|
+
In Czech Republic this has recently been the case with the newly
|
434
|
+
introduced feast of *Christ the Priest* (celebrated on Thursday
|
435
|
+
after Pentecost). Support for this feast, celebrated in several other
|
436
|
+
dioceses and religious institutes, is included in the gem
|
437
|
+
as `Temporale` extension.
|
438
|
+
|
439
|
+
In order to build a complete Czech `Calendar` with proper sanctorale
|
440
|
+
feasts and the additional temporale feast of *Christ the Priest*,
|
441
|
+
it is necessary, apart of loading the sanctorale data,
|
442
|
+
to provide a `Temporale` instance with the extension applied:
|
443
|
+
|
444
|
+
```ruby
|
445
|
+
year = 2016
|
446
|
+
sanctorale = CR::Data::CZECH.load
|
447
|
+
temporale =
|
448
|
+
CR::Temporale.new(
|
449
|
+
year,
|
450
|
+
# the important bit: apply the Temporale extension
|
451
|
+
extensions: [CR::Temporale::Extensions::ChristEternalPriest]
|
452
|
+
)
|
453
|
+
|
454
|
+
calendar = CR::Calendar.new(year, sanctorale, temporale)
|
455
|
+
```
|
456
|
+
|
457
|
+
The feast of *Christ the Priest*, by it's nature, extends the cycle of
|
458
|
+
*Feasts of the Lord in the Ordinary Time* and thus clearly belongs
|
459
|
+
to the *temporale.* Even if your proper movable feast
|
460
|
+
is by it's nature a *sanctorale* feast, just having a movable
|
461
|
+
date, the only way to handle it using this gem is to write
|
462
|
+
a *temporale* extension. There is no support for movable feasts
|
463
|
+
in the `Sanctorale` class. Even the single movable sanctorale
|
464
|
+
feast of the General Roman Calendar,
|
465
|
+
the memorial of *Immaculate Heart of Mary,* is, by a little cheat,
|
466
|
+
currently implemented in the `Temporale`.
|
467
|
+
|
468
|
+
Any object defining method `each_celebration`, which yields
|
469
|
+
pairs of "date computer" and `Celebration`, can be used as
|
470
|
+
temporale extension. Unless you have a good reason to do otherwise,
|
471
|
+
a class or module defining `each_celebration` as class/module method
|
472
|
+
is a convenient choice.
|
473
|
+
|
474
|
+
```ruby
|
475
|
+
module MyExtension
|
476
|
+
# yields celebrations defined by the extension
|
477
|
+
def self.each_celebration
|
478
|
+
yield(
|
479
|
+
:my_feast_date, # name of a method computing date of the feast
|
480
|
+
CR::Celebration.new(
|
481
|
+
'My Feast', # feast title
|
482
|
+
CR::Ranks::FEAST_PROPER, # rank
|
483
|
+
CR::Colours::WHITE # colour
|
484
|
+
)
|
485
|
+
)
|
486
|
+
|
487
|
+
yield(
|
488
|
+
# Proc can be used for date computation instead of a method
|
489
|
+
# referenced by name
|
490
|
+
lambda {|year| CR::Temporale::Dates.easter_sunday(year) + 9 },
|
491
|
+
CR::Celebration.new(
|
492
|
+
# It is possible to use a Proc as feast title if you want it
|
493
|
+
# to be determined at runtime - e.g. because you want to
|
494
|
+
# have the feast title translated and follow changes of `I18n.locale`
|
495
|
+
proc { I18n.t('my_feasts.another_feast') },
|
496
|
+
CR::Ranks::MEMORIAL_PROPER,
|
497
|
+
CR::Colours::WHITE
|
498
|
+
)
|
499
|
+
)
|
500
|
+
end
|
501
|
+
|
502
|
+
# computes date of the feast;
|
503
|
+
# the year passed as argument is year when the liturgical
|
504
|
+
# year in question _began_
|
505
|
+
def self.my_feast_date(year)
|
506
|
+
# the day before Christ the King
|
507
|
+
CR::Temporale::Dates.christ_king(year) - 1
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
temporale = CR::Temporale.new(2016, extensions: [MyExtension])
|
512
|
+
|
513
|
+
# the feast is there!
|
514
|
+
temporale[Date.new(2017, 11, 25)] # => #<CalendariumRomanum::Celebration:0x0000000246fd78 @title="My Feast", @rank=#<CalendariumRomanum::Rank:0x000000019c27e0 @priority=2.8, ... >, @colour=#<CalendariumRomanum::Colour:0x000000019c31e0 @symbol=:white>>
|
515
|
+
```
|
516
|
+
|
517
|
+
## Internationalization internals
|
518
|
+
|
519
|
+
It was already mentioned earlier in this document that
|
520
|
+
for internationalization of temporale feast names and
|
521
|
+
other "built-in strings"
|
522
|
+
`calendarium-romanum` relies upon the `i18n` gem.
|
523
|
+
Some internal details may be worth a mention:
|
524
|
+
|
525
|
+
On `require 'calendarium-romanum'`, paths of a few translation
|
526
|
+
files bundled in the gem are added to `I18n.config.load_path`.
|
527
|
+
While otherwise we avoid polluting or modifying the environment
|
528
|
+
outside the gem's own scope, in this case we exceptionally
|
529
|
+
modify global configuration in order to make the internationalization
|
530
|
+
easily and conveniently work.
|
531
|
+
If your application requires `calendarium-romanum` to handle
|
532
|
+
languages not bundled in the gem, or if you don't like the default
|
533
|
+
translations, just prepare a [translation file](/config/locales),
|
534
|
+
put it anywhere in your project's tree
|
535
|
+
and add it's path to `I18n.config.load_path`.
|
536
|
+
If, on the other hand, even the officially supported languages
|
537
|
+
don't work for you, check if paths to the gem's translation files
|
538
|
+
are present in `I18n.config.load_path` and possibly search your
|
539
|
+
application (and it's other dependencies) for code which kicked
|
540
|
+
them out.
|
541
|
+
|
542
|
+
## Executable
|
543
|
+
|
544
|
+
This gem provides an executable, `calendariumrom`.
|
545
|
+
It's handful of subcommands can be used to query liturgical calendar
|
546
|
+
from the command line and to check validity of sanctorale data files.
|
547
|
+
|
548
|
+
### 1. Query liturgical calendar from the command line
|
549
|
+
|
550
|
+
- `calendariumrom query` prints calendar entries for today or a specified day, month or year.
|
551
|
+
See `calendariumrom help query` for available options and arguments.
|
552
|
+
- `calendariumrom calendars` lists data files bundled in `calendarium-romanum`.
|
553
|
+
|
554
|
+
Tip: `calendariumrom query` is a rather bare-bones calendar querying
|
555
|
+
tool. Check out the [`calrom`][calrom] gem for a more feature-rich
|
556
|
+
liturgical calendar for your command line.
|
557
|
+
|
558
|
+
### 2. Check sanctorale data files
|
559
|
+
|
560
|
+
- `calendariumrom cmp FILE1 FILE2` loads two data files and prints any differences between them
|
561
|
+
(excepting differences in celebration titles)
|
562
|
+
- `calendariumrom errors FILE1, ...` attempts loading a data file (or several of them),
|
563
|
+
reports eventual errors
|
564
|
+
|
565
|
+
### 3. Help
|
566
|
+
|
567
|
+
- `calendariumrom` lists available subcommands
|
568
|
+
- `calendariumrom help [COMMAND]` outputs a short help for all available subcommands
|
569
|
+
- `calendariumrom version` prints installed version of the gem
|
570
|
+
|
571
|
+
## For Developers
|
572
|
+
|
573
|
+
Get the sources and install development depencencies:
|
574
|
+
|
575
|
+
1. `git clone git@github.com:igneus/calendarium-romanum.git`
|
576
|
+
2. `cd calendarium-romanum`
|
577
|
+
3. `bundle install` or `bundle install --path vendor/bundle`
|
578
|
+
|
579
|
+
### Run from CLI
|
580
|
+
|
581
|
+
`bundle exec ruby -Ilib bin/calendariumrom`
|
582
|
+
|
583
|
+
### Run Tests
|
584
|
+
|
585
|
+
`bundle exec rake spec`
|
586
|
+
|
587
|
+
See also `.travis.yml` for comprehensive tests run on the CI.
|
588
|
+
|
589
|
+
[awesomecc]: https://github.com/calendarium-romanum/awesome-church-calendar
|
590
|
+
[gnlyc]: https://www.ewtn.com/catholicism/library/liturgical-year-2193
|
591
|
+
[i18n]: https://github.com/svenfuchs/i18n
|
592
|
+
[translations]: /tree/master/config/locales
|
593
|
+
[liturgical_law]: /tree/master/liturgical_law
|
594
|
+
[module-included]: http://ruby-doc.org/core-2.2.2/Module.html#method-i-included
|
595
|
+
[calrom]: https://github.com/calendarium-romanum/calrom
|
596
|
+
[crhistorical]: https://github.com/calendarium-romanum/historical
|
597
|
+
[data-contrib]: https://github.com/calendarium-romanum/data-contrib
|
598
|
+
[i18n]: https://github.com/ruby-i18n/i18n
|