calendarium-romanum 0.2.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/bin/calendariumrom +4 -1
  3. data/config/locales/cs.yml +54 -2
  4. data/config/locales/en.yml +64 -14
  5. data/config/locales/es.yml +90 -0
  6. data/config/locales/fr.yml +90 -0
  7. data/config/locales/it.yml +54 -4
  8. data/config/locales/la.yml +52 -2
  9. data/data/README.md +105 -5
  10. data/data/czech-brno-cs.txt +11 -5
  11. data/data/czech-budejovice-cs.txt +11 -5
  12. data/data/czech-cechy-cs.txt +11 -5
  13. data/data/czech-cs.txt +243 -234
  14. data/data/czech-hradec-cs.txt +10 -4
  15. data/data/czech-litomerice-cs.txt +12 -6
  16. data/data/czech-morava-cs.txt +11 -5
  17. data/data/czech-olomouc-cs.txt +9 -3
  18. data/data/czech-ostrava-cs.txt +10 -4
  19. data/data/czech-plzen-cs.txt +10 -4
  20. data/data/czech-praha-cs.txt +10 -3
  21. data/data/universal-en.txt +218 -212
  22. data/data/universal-es.txt +243 -0
  23. data/data/universal-fr.txt +243 -0
  24. data/data/universal-it.txt +218 -212
  25. data/data/universal-la.txt +218 -211
  26. data/lib/calendarium-romanum.rb +30 -18
  27. data/lib/calendarium-romanum/abstract_date.rb +12 -0
  28. data/lib/calendarium-romanum/calendar.rb +210 -48
  29. data/lib/calendarium-romanum/cli.rb +101 -52
  30. data/lib/calendarium-romanum/cr.rb +16 -0
  31. data/lib/calendarium-romanum/data.rb +46 -18
  32. data/lib/calendarium-romanum/day.rb +200 -21
  33. data/lib/calendarium-romanum/enum.rb +24 -5
  34. data/lib/calendarium-romanum/enums.rb +123 -37
  35. data/lib/calendarium-romanum/errors.rb +4 -0
  36. data/lib/calendarium-romanum/ordinalizer.rb +61 -0
  37. data/lib/calendarium-romanum/perpetual_calendar.rb +97 -0
  38. data/lib/calendarium-romanum/rank.rb +43 -6
  39. data/lib/calendarium-romanum/sanctorale.rb +142 -22
  40. data/lib/calendarium-romanum/sanctorale_factory.rb +74 -3
  41. data/lib/calendarium-romanum/sanctorale_loader.rb +176 -0
  42. data/lib/calendarium-romanum/temporale.rb +296 -251
  43. data/lib/calendarium-romanum/temporale/celebration_factory.rb +106 -0
  44. data/lib/calendarium-romanum/temporale/dates.rb +232 -0
  45. data/lib/calendarium-romanum/temporale/extensions/christ_eternal_priest.rb +37 -0
  46. data/lib/calendarium-romanum/transfers.rb +43 -6
  47. data/lib/calendarium-romanum/util.rb +36 -3
  48. data/lib/calendarium-romanum/version.rb +5 -1
  49. data/spec/abstract_date_spec.rb +11 -3
  50. data/spec/calendar_spec.rb +645 -188
  51. data/spec/celebration_factory_spec.rb +40 -0
  52. data/spec/celebration_spec.rb +67 -0
  53. data/spec/cli_spec.rb +154 -11
  54. data/spec/colour_spec.rb +22 -0
  55. data/spec/data_spec.rb +26 -3
  56. data/spec/date_parser_spec.rb +68 -0
  57. data/spec/date_spec.rb +8 -8
  58. data/spec/dates_spec.rb +73 -0
  59. data/spec/day_spec.rb +151 -0
  60. data/spec/i18n_spec.rb +11 -2
  61. data/spec/ordinalizer_spec.rb +44 -0
  62. data/spec/perpetual_calendar_spec.rb +125 -0
  63. data/spec/rank_spec.rb +42 -7
  64. data/spec/readme_spec.rb +18 -10
  65. data/spec/sanctorale_factory_spec.rb +113 -9
  66. data/spec/sanctorale_loader_spec.rb +229 -0
  67. data/spec/sanctorale_spec.rb +176 -62
  68. data/spec/season_spec.rb +22 -0
  69. data/spec/spec_helper.rb +27 -1
  70. data/spec/temporale_spec.rb +473 -154
  71. data/spec/year_spec.rb +25 -0
  72. metadata +42 -7
  73. data/lib/calendarium-romanum/sanctoraleloader.rb +0 -104
  74. data/spec/sanctoraleloader_spec.rb +0 -171
@@ -0,0 +1,73 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe CR::Temporale::Dates do
4
+ let(:today) { Date.new 2014, 3, 16 }
5
+
6
+ describe '#weekday_before' do
7
+ describe 'works well for all 7 weekdays' do
8
+ [
9
+ [0, Date.new(2014, 3, 9)],
10
+ [1, Date.new(2014, 3, 10)],
11
+ [2, Date.new(2014, 3, 11)],
12
+ [3, Date.new(2014, 3, 12)],
13
+ [4, Date.new(2014, 3, 13)],
14
+ [5, Date.new(2014, 3, 14)],
15
+ [6, Date.new(2014, 3, 15)],
16
+ ].each do |e|
17
+ day_num, expected = e
18
+ it day_num do
19
+ actual = described_class.weekday_before(day_num, today)
20
+ expect(actual).to eq expected
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#weekday_after aliases' do
27
+ describe 'works well for all 7 weekdays' do
28
+ [
29
+ [:monday_after, Date.new(2014, 3, 17)],
30
+ [:tuesday_after, Date.new(2014, 3, 18)],
31
+ [:wednesday_after, Date.new(2014, 3, 19)],
32
+ [:thursday_after, Date.new(2014, 3, 20)],
33
+ [:friday_after, Date.new(2014, 3, 21)],
34
+ [:saturday_after, Date.new(2014, 3, 22)],
35
+ [:sunday_after, Date.new(2014, 3, 23)],
36
+ ].each do |e|
37
+ method, expected = e
38
+ it method do
39
+ actual = described_class.public_send(method, today)
40
+ expect(actual).to eq expected
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ describe 'transferable solemnities' do
47
+ # for sake of simplicity a year has been chosen when
48
+ # none of the transferable solemnities falls on a Sunday
49
+ let(:year) { 2013 }
50
+
51
+ %i(epiphany ascension corpus_christi).each do |solemnity|
52
+ it solemnity.to_s do
53
+ transferred =
54
+ described_class.public_send(solemnity, year, sunday: true)
55
+ not_transferred =
56
+ described_class.public_send(solemnity, year)
57
+
58
+ expect(transferred).not_to eq not_transferred
59
+ expect(transferred).to be_sunday
60
+ end
61
+ end
62
+
63
+ it 'Baptism of the Lord' do
64
+ transferred =
65
+ described_class.baptism_of_lord(year, epiphany_on_sunday: true)
66
+ not_transferred =
67
+ described_class.baptism_of_lord(year)
68
+
69
+ expect(transferred).to be_monday
70
+ expect(not_transferred).to be_sunday
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,151 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe CR::Day do
4
+ let(:d) do
5
+ described_class.new(
6
+ date: Date.today,
7
+ season: CR::Seasons::ORDINARY,
8
+ season_week: 1,
9
+ celebrations: [CR::Celebration.new],
10
+ vespers: vespers
11
+ )
12
+ end
13
+
14
+ let(:vespers) { nil }
15
+
16
+ describe '.new' do
17
+ it 'works without arguments' do
18
+ expect do
19
+ described_class.new
20
+ end.not_to raise_exception
21
+ end
22
+
23
+ it 'makes a shallow copy of celebrations' do
24
+ celebrations = [CR::Celebration.new]
25
+ day = described_class.new celebrations: celebrations
26
+
27
+ expect(day.celebrations).to eq celebrations
28
+ expect(day.celebrations).not_to be celebrations
29
+
30
+ expect(day.celebrations[0]).to be celebrations[0]
31
+ end
32
+ end
33
+
34
+ describe '#==' do
35
+ describe 'same content' do
36
+ let(:d2) do
37
+ described_class.new(
38
+ date: Date.today,
39
+ season: CR::Seasons::ORDINARY,
40
+ season_week: 1,
41
+ celebrations: [CR::Celebration.new]
42
+ )
43
+ end
44
+
45
+ it 'is equal' do
46
+ expect(d).to eq d2
47
+ end
48
+ end
49
+
50
+ describe 'different content' do
51
+ let(:d2) do
52
+ described_class.new(
53
+ date: Date.today,
54
+ season: CR::Seasons::LENT,
55
+ season_week: 1,
56
+ celebrations: [CR::Celebration.new]
57
+ )
58
+ end
59
+
60
+ it 'is different' do
61
+ expect(d).not_to eq d2
62
+ end
63
+ end
64
+
65
+ describe 'different celebrations' do
66
+ let(:d2) do
67
+ described_class.new(
68
+ date: Date.today,
69
+ season: CR::Seasons::ORDINARY,
70
+ season_week: 1,
71
+ celebrations: [CR::Celebration.new('another celebration')]
72
+ )
73
+ end
74
+
75
+ it 'is different' do
76
+ expect(d).not_to eq d2
77
+ end
78
+ end
79
+
80
+ describe 'different Vespers' do
81
+ let(:d2) do
82
+ described_class.new(
83
+ date: Date.today,
84
+ season: CR::Seasons::ORDINARY,
85
+ season_week: 1,
86
+ celebrations: [CR::Celebration.new],
87
+ vespers: CR::Temporale::CelebrationFactory.palm_sunday
88
+ )
89
+ end
90
+
91
+ it 'is different' do
92
+ expect(d).not_to eq d2
93
+ end
94
+ end
95
+ end
96
+
97
+ describe '#vespers_from_following?' do
98
+ describe 'vespers not set' do
99
+ it { expect(d.vespers_from_following?).to be false }
100
+ end
101
+
102
+ describe 'vespers set' do
103
+ let(:vespers) { CR::Celebration.new }
104
+
105
+ it { expect(d.vespers_from_following?).to be true }
106
+ end
107
+ end
108
+
109
+ describe '#to_s' do
110
+ it do
111
+ I18n.with_locale(:en) do
112
+ day = CR::PerpetualCalendar.new[Date.new(2000, 1, 8)]
113
+ expect(day.to_s).to eq "#<CalendariumRomanum::Day @date=2000-01-08 @season=#<CalendariumRomanum::Season christmas> @season_week=2 celebrations=[#<CalendariumRomanum::Celebration @title=\"Saturday after Epiphany\" @rank=#<CalendariumRomanum::Rank @priority=3.13 desc=\"Ferials\"> @colour=#<CalendariumRomanum::Colour white> symbol=nil date=nil cycle=:temporale>] vespers=nil>"
114
+ end
115
+ end
116
+ end
117
+
118
+ describe '#weekday' do
119
+ let(:sunday) { Date.new 2018, 5, 20 }
120
+ let(:saturday) { sunday - 1 }
121
+
122
+ it 'Sunday' do
123
+ expect(sunday).to be_sunday # make sure
124
+
125
+ d = described_class.new(date: sunday)
126
+ expect(d.weekday).to be 0
127
+ end
128
+
129
+ it 'Saturday' do
130
+ d = described_class.new(date: saturday)
131
+ expect(d.weekday).to be 6
132
+ end
133
+ end
134
+
135
+ describe '#weekday_name' do
136
+ let(:sunday) { Date.new 2018, 5, 20 }
137
+ let(:saturday) { sunday - 1 }
138
+
139
+ it 'Sunday' do
140
+ expect(sunday).to be_sunday # make sure
141
+
142
+ d = described_class.new(date: sunday)
143
+ expect(d.weekday_name).to eq(I18n.t('0', scope: 'weekday'))
144
+ end
145
+
146
+ it 'Saturday' do
147
+ d = described_class.new(date: saturday)
148
+ expect(d.weekday_name).to eq(I18n.t('6', scope: 'weekday'))
149
+ end
150
+ end
151
+ end
@@ -23,7 +23,7 @@ describe 'internationalization' do
23
23
  let(:locale) { 'en' }
24
24
 
25
25
  it 'translates Temporale feast names' do
26
- expect(easter_celebration.title).to eq 'Easter Sunday of the Resurrection of the Lord'
26
+ expect(easter_celebration.title).to eq 'Easter Sunday'
27
27
  end
28
28
 
29
29
  it 'translates rank names' do
@@ -31,6 +31,11 @@ describe 'internationalization' do
31
31
  expect(rank.desc).to eq 'Unprivileged Sundays'
32
32
  expect(rank.short_desc).to eq 'Sunday'
33
33
  end
34
+
35
+ it 'translates day weekday_names' do
36
+ sunday = CR::Day.new(date: Date.new(2018, 5, 20))
37
+ expect(sunday.weekday_name).to eq 'Sunday'
38
+ end
34
39
  end
35
40
 
36
41
  describe 'Czech' do
@@ -45,6 +50,11 @@ describe 'internationalization' do
45
50
  expect(rank.desc).to eq 'Neprivilegované neděle'
46
51
  expect(rank.short_desc).to eq 'neděle'
47
52
  end
53
+
54
+ it 'translates day weekday_names' do
55
+ sunday = CR::Day.new(date: Date.new(2018, 5, 20))
56
+ expect(sunday.weekday_name).to eq 'Neděle'
57
+ end
48
58
  end
49
59
  end
50
60
 
@@ -53,7 +63,6 @@ describe 'internationalization' do
53
63
  let(:locale) { 'de' }
54
64
 
55
65
  it 'attemt to switch to it fails by default' do
56
-
57
66
  end
58
67
  end
59
68
  end
@@ -0,0 +1,44 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe CalendariumRomanum::Ordinalizer do
4
+ describe '#ordinal' do
5
+ describe 'English' do
6
+ {
7
+ 1 => '1st',
8
+ 2 => '2nd',
9
+ 3 => '3rd',
10
+ 4 => '4th',
11
+ 11 => '11th',
12
+ 12 => '12th',
13
+ 13 => '13th',
14
+ 21 => '21st',
15
+ 22 => '22nd',
16
+ 23 => '23rd',
17
+ }.each_pair do |number, ordinal|
18
+ it number do
19
+ expect(described_class.ordinal(number, locale: :en)).to eq ordinal
20
+ end
21
+ end
22
+ end
23
+
24
+ describe 'French' do
25
+ {
26
+ 1 => '1er',
27
+ 2 => '2ème',
28
+ 3 => '3ème',
29
+ }.each_pair do |number, ordinal|
30
+ it number do
31
+ expect(described_class.ordinal(number, locale: :fr)).to eq ordinal
32
+ end
33
+ end
34
+ end
35
+
36
+ describe 'unsupported locale' do
37
+ [1, 2, 3].each do |number|
38
+ it number do
39
+ expect(described_class.ordinal(number, locale: :unsupported)).to eq number
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe CR::PerpetualCalendar do
4
+ let(:pcal) { described_class.new }
5
+
6
+ let(:date) { Date.new(2000, 1, 1) }
7
+ let(:year) { 2000 }
8
+
9
+ let(:sanctorale) { CR::Data::GENERAL_ROMAN_ENGLISH.load }
10
+
11
+ let(:factory) { CR::Temporale::CelebrationFactory }
12
+
13
+ describe '.new' do
14
+ describe 'with sanctorale' do
15
+ it 'uses the sanctorale' do
16
+ pc = described_class.new(sanctorale: sanctorale)
17
+
18
+ calendar = pc.calendar_for_year(year)
19
+ expect(calendar.sanctorale).to be sanctorale
20
+ end
21
+ end
22
+
23
+ describe 'with temporale options' do
24
+ it 'applies the options' do
25
+ pc = described_class.new(temporale_options: {transfer_to_sunday: [:epiphany]})
26
+
27
+ y = 2016
28
+ calendar = pc.calendar_for_year(y)
29
+ epiphany_date = CR::Temporale::Dates.epiphany(y, sunday: true)
30
+
31
+ expect(calendar.day(epiphany_date).celebrations[0]).to eq factory.epiphany
32
+ end
33
+ end
34
+
35
+ describe 'with temporale factory' do
36
+ it 'uses the factory' do
37
+ temporale_subcls = Class.new(CR::Temporale)
38
+ factory = lambda {|year| temporale_subcls.new year }
39
+
40
+ pc = described_class.new(temporale_factory: factory)
41
+ calendar = pc.calendar_for_year(year)
42
+ expect(calendar.temporale).to be_a temporale_subcls
43
+ end
44
+ end
45
+
46
+ describe 'with both temporale factory and options' do
47
+ it 'fails' do
48
+ expect do
49
+ described_class.new(
50
+ temporale_options: {transfer_to_sunday: [:epiphany]},
51
+ temporale_factory: lambda {|year| }
52
+ )
53
+ end.to raise_exception ArgumentError
54
+ end
55
+ end
56
+
57
+ describe 'with cache' do
58
+ it 'uses the supplied object as Calendar instance cache' do
59
+ cache = {}
60
+ pc = described_class.new(cache: cache)
61
+ calendar = pc.calendar_for_year(year)
62
+ expect(cache[2000]).to be calendar
63
+ end
64
+ end
65
+ end
66
+
67
+ describe '#day' do
68
+ it 'returns a Day' do
69
+ expect(pcal.day(Date.today)).to be_a CR::Day
70
+ end
71
+ end
72
+
73
+ describe '#[]' do
74
+ describe 'arguments' do
75
+ describe 'single Date' do
76
+ it 'returns a Day' do
77
+ expect(pcal[Date.today]).to be_a CR::Day
78
+ end
79
+ end
80
+
81
+ describe 'Range of Dates' do
82
+ shared_examples 'range' do
83
+ it 'returns an Array of Days' do
84
+ result = pcal[range]
85
+ expect(result).to be_an Array
86
+ expect(result[0]).to be_a CR::Day
87
+ end
88
+ end
89
+
90
+ describe 'of the same liturgical year' do
91
+ let(:range) { Date.new(2010, 1, 1) .. Date.new(2010, 1, 5) }
92
+
93
+ include_examples 'range'
94
+ end
95
+
96
+ describe 'across boundaries of the liturgical year' do
97
+ let(:first_advent) { CR::Temporale::Dates.first_advent_sunday(2010) }
98
+ let(:range) { (first_advent - 1) .. (first_advent + 1) }
99
+
100
+ include_examples 'range'
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ describe '#calendar_for' do
107
+ it 'returns a Calendar' do
108
+ expect(pcal.calendar_for(date)).to be_a CR::Calendar
109
+ end
110
+ end
111
+
112
+ describe '#calendar_for_year' do
113
+ it 'returns a Calendar' do
114
+ expect(pcal.calendar_for_year(year)).to be_a CR::Calendar
115
+ end
116
+ end
117
+
118
+ describe 'caching' do
119
+ it 'caches calendar instances' do
120
+ expect(CR::Calendar).to receive(:new)
121
+
122
+ 2.times { pcal.calendar_for_year(year) }
123
+ end
124
+ end
125
+ end
@@ -28,15 +28,50 @@ describe CR::Rank do
28
28
  it { expect(CR::Ranks[1.2]).not_to be == CR::Ranks[1.1] }
29
29
  end
30
30
 
31
- describe '#desc' do
32
- it { expect(CR::Ranks[1.1].desc).to eq 'Easter triduum' }
33
- end
31
+ describe 'descriptions' do
32
+ CR::Ranks.each do |rank|
33
+ describe "#{rank.priority} #{rank.short_desc}" do
34
+ it 'has #desc translated' do
35
+ expect(rank.desc).to have_translation
36
+ end
37
+
38
+ it 'is has #short_desc translated' do
39
+ if rank.short_desc # not set for some ranks
40
+ expect(rank.short_desc).to have_translation
41
+ end
42
+ end
43
+ end
44
+ end
34
45
 
35
- describe '#short_desc' do
36
- it 'is not always set' do
37
- expect(CR::Ranks[1.1].short_desc).to be_nil
46
+ describe '#short_desc' do
47
+ it 'is not always set' do
48
+ expect(CR::Ranks[1.1].short_desc).to be_nil
49
+ end
38
50
  end
51
+ end
52
+
53
+ describe '#memorial?' do
54
+ it { expect(CR::Ranks::MEMORIAL_OPTIONAL.memorial?).to be true }
55
+ it { expect(CR::Ranks::FERIAL.memorial?).to be false }
56
+ end
39
57
 
40
- it { expect(CR::Ranks[2.8].short_desc).to eq 'feast' }
58
+ describe '#sunday?' do
59
+ it { expect(CR::Ranks::SUNDAY_UNPRIVILEGED.sunday?).to be true }
60
+ it { expect(CR::Ranks::FERIAL.sunday?).to be false }
61
+ end
62
+
63
+ describe '#ferial?' do
64
+ it { expect(CR::Ranks::FERIAL.ferial?).to be true }
65
+ it { expect(CR::Ranks::FERIAL_PRIVILEGED.ferial?).to be true }
66
+ it { expect(CR::Ranks::MEMORIAL_OPTIONAL.ferial?).to be false }
67
+ end
68
+
69
+ describe '#to_s' do
70
+ it do
71
+ I18n.with_locale(:en) do
72
+ expect(CR::Ranks::FERIAL.to_s)
73
+ .to eq '#<CalendariumRomanum::Rank @priority=3.13 desc="Ferials">'
74
+ end
75
+ end
41
76
  end
42
77
  end