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,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe CR::Temporale::CelebrationFactory do
4
+ describe '.first_advent_sunday' do
5
+ it 'returns Celebration equal to the one returned by Temporale' do
6
+ year = 2000
7
+ temporale = CR::Temporale.new(year)
8
+ date = CR::Temporale::Dates.first_advent_sunday(year)
9
+
10
+ c = temporale.get(date)
11
+ c2 = described_class.first_advent_sunday
12
+
13
+ expect(c2).to eq c
14
+ end
15
+ end
16
+
17
+ describe '.each' do
18
+ it 'yields' do
19
+ expect {|b| described_class.each(&b) }.to yield_control
20
+ end
21
+
22
+ it 'yields Celebrations' do
23
+ described_class.each do |c|
24
+ expect(c).to be_a CR::Celebration
25
+ end
26
+ end
27
+
28
+ it 'returns Enumerator if called without a block' do
29
+ expect(described_class.each).to be_a Enumerator
30
+ end
31
+ end
32
+
33
+ describe 'celebration titles are properly translated' do
34
+ described_class.each do |celebration|
35
+ it celebration.symbol.to_s do
36
+ expect(celebration.title).to have_translation
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,67 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe CR::Celebration do
4
+ describe '#==' do
5
+ let(:c) { described_class.new('title') }
6
+
7
+ describe 'same content' do
8
+ let(:c2) { described_class.new('title') }
9
+
10
+ it 'is equal' do
11
+ expect(c).to eq c2
12
+ end
13
+ end
14
+
15
+ describe 'different content' do
16
+ let(:c2) { described_class.new('another title') }
17
+
18
+ it 'is different' do
19
+ expect(c).not_to eq c2
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '#change' do
25
+ let(:c) { described_class.new('title') }
26
+
27
+ it 'produces a new instance' do
28
+ c2 = c.change rank: CR::Ranks::SOLEMNITY_GENERAL
29
+ expect(c2).not_to be c
30
+ end
31
+
32
+ it 'sets specified properties' do
33
+ c2 = c.change rank: CR::Ranks::SOLEMNITY_GENERAL
34
+ expect(c2.rank).not_to eq c.rank
35
+ expect(c2.rank).to be CR::Ranks::SOLEMNITY_GENERAL
36
+ end
37
+
38
+ it 'copies the rest' do
39
+ c2 = c.change rank: CR::Ranks::SOLEMNITY_GENERAL
40
+ expect(c2.title).to be c.title # reference copying is no problem, Celebrations are immutable
41
+ end
42
+ end
43
+
44
+ describe '#temporale?, #sanctorale?' do
45
+ let(:tc) { described_class.new.change(cycle: :temporale) }
46
+ let(:sc) { described_class.new.change(cycle: :sanctorale) }
47
+ let(:nc) { described_class.new.change(cycle: anything) }
48
+
49
+ it { expect(tc.temporale?).to be true }
50
+ it { expect(tc.sanctorale?).to be false }
51
+
52
+ it { expect(sc.sanctorale?).to be true }
53
+ it { expect(sc.temporale?).to be false }
54
+
55
+ it { expect(nc.sanctorale?).to be false }
56
+ it { expect(nc.temporale?).to be false }
57
+ end
58
+
59
+ describe '#to_s' do
60
+ it do
61
+ I18n.with_locale(:en) do
62
+ celebration = CR::PerpetualCalendar.new[Date.new(2000, 1, 8)].celebrations[0]
63
+ expect(celebration.to_s).to eq "#<CalendariumRomanum::Celebration @title=\"Saturday after Epiphany\" @rank=#<CalendariumRomanum::Rank @priority=3.13 desc=\"Ferials\"> @colour=#<CalendariumRomanum::Colour white> symbol=nil date=nil cycle=:temporale>"
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,26 +1,169 @@
1
1
  require 'spec_helper'
2
2
  require 'calendarium-romanum/cli'
3
3
 
4
- describe CalendariumRomanum::CLI do
5
- let(:path_universal_la) { File.expand_path('../../data/universal-la.txt', __FILE__) }
6
- let(:path_universal_en) { File.expand_path('../../data/universal-en.txt', __FILE__) }
4
+ describe CalendariumRomanum::CLI, type: :aruba do
5
+ let(:path_universal_la) { CR::Data::GENERAL_ROMAN_LATIN.path }
6
+ let(:path_universal_en) { CR::Data::GENERAL_ROMAN_ENGLISH.path }
7
+
8
+ before :each do
9
+ prepend_environment_variable('RUBYLIB', File.expand_path('../../lib', __FILE__) + ':')
10
+ end
11
+
7
12
  describe 'subcommands' do
8
13
  describe 'errors' do
9
- it 'raises no exception' do
10
- described_class.start(['errors', path_universal_la])
14
+ describe 'no errors detected' do
15
+ before(:each) { run "calendariumrom errors #{path_universal_la}" }
16
+ it { expect(last_command).to be_successfully_executed }
17
+ it { expect(all_output).to be_empty }
11
18
  end
12
19
 
13
- it 'fails on a non-existent file' do
14
- expect do
15
- described_class.start(['errors', 'does-not-exist.txt'])
16
- end.to raise_exception Errno::ENOENT
20
+ describe 'non-existent file' do
21
+ before(:each) { run 'calendariumrom errors does-not-exist.txt' }
22
+ it { expect(all_output).to include 'No such file or directory' }
23
+ it { expect(last_command).to have_exit_status 1 }
24
+ end
25
+
26
+ describe 'errors detected' do
27
+ before(:each) do
28
+ write_file 'data.txt', file_content
29
+ run 'calendariumrom errors data.txt'
30
+ end
31
+
32
+ describe 'completely broken record' do
33
+ let(:file_content) { 'invalid content' }
34
+
35
+ it { expect(all_output).to eq "L1: Syntax error, line skipped 'invalid content'\n" }
36
+ it { expect(last_command).to have_exit_status 1 }
37
+ end
38
+
39
+ describe 'wrong month title (month does not exist)' do
40
+ let(:file_content) { "= 13\n" }
41
+
42
+ it { expect(all_output).to start_with 'L1: Invalid month' }
43
+ it { expect(last_command).to have_exit_status 1 }
44
+ end
17
45
  end
18
46
  end
19
47
 
20
48
  describe 'cmp' do
21
- it 'raises no exception' do
22
- described_class.start(['cmp', path_universal_la, path_universal_en])
49
+ describe 'contents match' do
50
+ before(:each) { run "calendariumrom cmp #{path_universal_la} #{path_universal_en}" }
51
+
52
+ it { expect(all_output).to be_empty }
53
+ it { expect(last_command).to be_successfully_executed }
23
54
  end
55
+
56
+ describe 'contents do not match' do
57
+ before(:each) do
58
+ write_file 'cal1.txt', content1
59
+ write_file 'cal2.txt', content2
60
+ run 'calendariumrom cmp cal1.txt cal2.txt'
61
+ end
62
+
63
+ describe 'in rank' do
64
+ let(:content1) { '1/11 : St. None, abbot' }
65
+ let(:content2) { '1/11 m : St. None, abbot' }
66
+
67
+ it { expect(all_output).to include '1/11' }
68
+ it { expect(all_output).to include 'St. None, abbot' }
69
+ it { expect(all_output).to include 'differs in rank' }
70
+ it { expect(last_command).to be_successfully_executed }
71
+ end
72
+
73
+ describe 'in colour' do
74
+ let(:content1) { '1/11 : St. None, abbot' }
75
+ let(:content2) { '1/11 R : St. None, abbot and martyr' }
76
+
77
+ it { expect(all_output).to include '1/11' }
78
+ it { expect(all_output).to include 'St. None, abbot' }
79
+ it { expect(all_output).to include 'differs in colour' }
80
+ it { expect(last_command).to be_successfully_executed }
81
+ end
82
+
83
+ describe 'in optional memorial count' do
84
+ let(:content1) { '1/11 : St. None, abbot' }
85
+ let(:content2) { "1/11 : St. None, abbot\n1/11 : St. Nulla, abbess" }
86
+
87
+ it { expect(all_output).to include '1/11' }
88
+ it { expect(all_output).to include 'St. Nulla, abbess' }
89
+ it { expect(all_output).to include 'only in cal2.txt' }
90
+ it { expect(last_command).to be_successfully_executed }
91
+ end
92
+
93
+ describe 'only in one source' do
94
+ let(:content1) { '' }
95
+ let(:content2) { '1/11 : St. None, abbot' }
96
+
97
+ it { expect(all_output).to include '1/11' }
98
+ it { expect(all_output).to include 'St. None, abbot' }
99
+ it { expect(all_output).to include 'only in cal2.txt' }
100
+ it { expect(last_command).to be_successfully_executed }
101
+ end
102
+ end
103
+ end
104
+
105
+ describe 'query' do
106
+ describe 'invalid data file from file system' do
107
+ before(:each) do
108
+ write_file 'invalid.txt', 'Foo bar baz'
109
+ run 'calendariumrom query --calendar invalid.txt 2017-10-03'
110
+ end
111
+
112
+ it { expect(all_output).to include 'Invalid file format.' }
113
+ it { expect(last_command).to have_exit_status 1 }
114
+ end
115
+
116
+ describe 'correct data file from file system' do
117
+ before(:each) { run "calendariumrom query --calendar #{path_universal_la} 2017-10-03" }
118
+
119
+ it { expect(all_output).to include 'season: Ordinary Time' }
120
+ it { expect(last_command).to be_successfully_executed }
121
+ end
122
+
123
+ describe 'correct season naming' do
124
+ before(:each) { run 'calendariumrom query 2017-10-03' }
125
+
126
+ it { expect(all_output).to include 'season: Ordinary Time' }
127
+ it { expect(last_command).to be_successfully_executed }
128
+ end
129
+
130
+ describe 'correct month querying' do
131
+ before(:each) { run 'calendariumrom query 2015-06' }
132
+
133
+ it { expect(all_output).to include 'Saint Cyril of Alexandria' }
134
+ it { expect(all_output).to include 'Saint Anthony of Padua, priest and doctor' }
135
+ it { expect(last_command).to be_successfully_executed }
136
+ end
137
+
138
+ describe 'correct year querying' do
139
+ before(:each) { run 'calendariumrom query 2013' }
140
+
141
+ it { expect(all_output).to include 'Saint John the Apostle and evangelist' }
142
+ it { expect(all_output).to include 'Saint Paul of the Cross, priest' }
143
+ it { expect(last_command).to be_successfully_executed }
144
+ end
145
+
146
+ describe 'prints primary celebrations' do
147
+ before(:each) { run 'calendariumrom query 2018-12-25' }
148
+
149
+ it { expect(all_output).to include "2018-12-25\nseason: Christmas Season\n\nChristmas" }
150
+ it { expect(last_command).to be_successfully_executed }
151
+ end
152
+ end
153
+
154
+ describe 'calendars' do
155
+ before(:each) { run 'calendariumrom calendars' }
156
+
157
+ it { expect(all_output).to include 'universal-en' }
158
+ it { expect(all_output).to include 'czech-praha-cs' }
159
+ it { expect(last_command).to be_successfully_executed }
160
+ end
161
+
162
+ describe 'version' do
163
+ before(:each) { run 'calendariumrom version' }
164
+
165
+ it { expect(all_output).to include CR::VERSION }
166
+ it { expect(all_output).to include CR::RELEASE_DATE.strftime('%Y-%m-%d') }
24
167
  end
25
168
  end
26
169
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe CR::Colour do
4
+ CR::Colours.each do |colour|
5
+ describe colour do
6
+ describe '#name' do
7
+ it { expect(colour.name).to have_translation }
8
+ end
9
+ end
10
+ end
11
+
12
+ describe 'indexing' do
13
+ it 'is indexed by symbol' do
14
+ expect(CR::Colours[:red]).to be CR::Colours::RED
15
+ end
16
+ end
17
+
18
+ describe '#to_s' do
19
+ it { expect(CR::Colours::RED.to_s)
20
+ .to eq '#<CalendariumRomanum::Colour red>' }
21
+ end
22
+ end
@@ -6,9 +6,9 @@ describe CalendariumRomanum::Data do
6
6
  glob = File.join(data_path, '*.txt')
7
7
 
8
8
  Dir[glob].each do |file|
9
- it file do
10
- in_data = described_class.all.find {|f| f.path == file }
11
- expect(in_data).not_to be nil
9
+ it "#{file} has it's Data entry" do
10
+ expect(described_class.all)
11
+ .to include(an_object_having_attributes(path: file))
12
12
  end
13
13
  end
14
14
  end
@@ -20,4 +20,27 @@ describe CalendariumRomanum::Data do
20
20
  end
21
21
  end
22
22
  end
23
+
24
+ describe '#load_with_parents' do
25
+ let(:sanctorale) { CR::Data['czech-olomouc-cs'].load_with_parents }
26
+
27
+ it 'loads the specified calendar' do
28
+ expect(sanctorale.get(6, 30).first.title)
29
+ .to eq 'Výročí posvěcení katedrály sv. Václava'
30
+ end
31
+
32
+ it 'loads the parent calendar' do
33
+ c = sanctorale.get(5, 6).first
34
+
35
+ expect(c.title).to eq 'Sv. Jana Sarkandra, kněze a mučedníka'
36
+ expect(c.rank).to be CR::Ranks::MEMORIAL_PROPER
37
+ end
38
+
39
+ it 'loads the grand-parent calendar' do
40
+ c = sanctorale.get(9, 28).first
41
+
42
+ expect(c.title).to eq 'Sv. Václava, mučedníka, hlavního patrona českého národa'
43
+ expect(c.rank).to eq CR::Ranks::SOLEMNITY_PROPER
44
+ end
45
+ end
23
46
  end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe CR::Util::DateParser do
4
+ describe 'new' do
5
+ it 'should accept a full date YYYY/MM/DD' do
6
+ date_str = '2017/10/06'
7
+ expect do
8
+ described_class.new(date_str)
9
+ end.not_to raise_exception
10
+ end
11
+
12
+ it 'should accept a full date YYYY-MM-DD' do
13
+ date_str = '2017-10-06'
14
+ expect do
15
+ described_class.new(date_str)
16
+ end.not_to raise_exception
17
+ end
18
+
19
+ it 'should accept a month range YYYY/MM' do
20
+ date_str = '2017/10'
21
+ expect do
22
+ described_class.new(date_str)
23
+ end.not_to raise_exception
24
+ end
25
+
26
+ it 'should accept a month range YYYY-MM' do
27
+ date_str = '2017-10'
28
+ expect do
29
+ described_class.new(date_str)
30
+ end.not_to raise_exception
31
+ end
32
+
33
+ it 'should accept a year range YYYY' do
34
+ date_str = '2017'
35
+ expect do
36
+ described_class.new(date_str)
37
+ end.not_to raise_exception
38
+ end
39
+
40
+ it 'should not accept an invalid month' do
41
+ date_str = '2017-15'
42
+ expect do
43
+ described_class.new(date_str)
44
+ end.to raise_exception(ArgumentError)
45
+ end
46
+
47
+ it 'should not accept an invalid day' do
48
+ date_str = '2017-10-48'
49
+ expect do
50
+ described_class.new(date_str)
51
+ end.to raise_exception(ArgumentError)
52
+ end
53
+
54
+ it 'should not accept a not-matching string' do
55
+ date_str = 'foobar'
56
+ expect do
57
+ described_class.new(date_str)
58
+ end.to raise_exception(ArgumentError)
59
+ end
60
+
61
+ it 'should not accept an empty string' do
62
+ date_str = ''
63
+ expect do
64
+ described_class.new(date_str)
65
+ end.to raise_exception(ArgumentError)
66
+ end
67
+ end
68
+ end
@@ -4,14 +4,14 @@ require 'spec_helper'
4
4
  describe Date do
5
5
  describe '#-' do
6
6
  it 'returns Rational' do
7
- date_diff = Date.new(2013,5,5) - Date.new(2013,5,1)
7
+ date_diff = Date.new(2013, 5, 5) - Date.new(2013, 5, 1)
8
8
  expect(date_diff).to be_a Rational
9
9
  expect(date_diff.numerator).to eq 4
10
10
  end
11
11
  end
12
12
 
13
13
  describe 'range' do
14
- let(:range) { (Date.new(2000,1,1) .. Date.new(2010,1,1)) }
14
+ let(:range) { (Date.new(2000, 1, 1) .. Date.new(2010, 1, 1)) }
15
15
 
16
16
  # please note that the RSpec 'include' matcher cannot
17
17
  # be used here, because it does't simply test
@@ -20,11 +20,11 @@ describe Date do
20
20
  # of DateTime in a Date range.
21
21
  describe 'test Date inclusion' do
22
22
  it 'includes' do
23
- expect(range.include?(Date.new(2005,3,3))).to be true
23
+ expect(range.include?(Date.new(2005, 3, 3))).to be true
24
24
  end
25
25
 
26
26
  it 'excludes' do
27
- expect(range.include?(Date.new(1995,3,3))).to be false
27
+ expect(range.include?(Date.new(1995, 3, 3))).to be false
28
28
  end
29
29
  end
30
30
 
@@ -32,22 +32,22 @@ describe Date do
32
32
  # DateTime without time details is treated just like Date
33
33
  describe 'without time specified' do
34
34
  it 'excludes' do
35
- expect(range.include?(DateTime.new(1995,3,3))).to be false
35
+ expect(range.include?(DateTime.new(1995, 3, 3))).to be false
36
36
  end
37
37
 
38
38
  it 'includes' do
39
- expect(range.include?(DateTime.new(2005,3,3))).to be true
39
+ expect(range.include?(DateTime.new(2005, 3, 3))).to be true
40
40
  end
41
41
  end
42
42
 
43
43
  # treatment of a DateTime with time details is different
44
44
  describe 'with time specified' do
45
45
  it 'excludes a DateTime not falling in the range' do
46
- expect(range.include?(DateTime.new(1995,3,3,1,1,1))).to be false
46
+ expect(range.include?(DateTime.new(1995, 3, 3, 1, 1, 1))).to be false
47
47
  end
48
48
 
49
49
  it '... but also one *falling* in the range!' do
50
- expect(range.include?(DateTime.new(2005,3,3,1,1,1))).to be false
50
+ expect(range.include?(DateTime.new(2005, 3, 3, 1, 1, 1))).to be false
51
51
  end
52
52
  end
53
53
  end