calendarium-romanum 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/bin/calendariumrom +2 -61
  3. data/config/locales/cs.yml +40 -0
  4. data/config/locales/en.yml +4 -1
  5. data/config/locales/it.yml +40 -0
  6. data/config/locales/la.yml +40 -0
  7. data/data/README.md +87 -0
  8. data/data/czech-brno-cs.txt +7 -0
  9. data/data/czech-budejovice-cs.txt +8 -0
  10. data/data/czech-cechy-cs.txt +8 -0
  11. data/data/czech-cs.txt +259 -0
  12. data/data/czech-hradec-cs.txt +6 -0
  13. data/data/czech-litomerice-cs.txt +8 -0
  14. data/data/czech-morava-cs.txt +7 -0
  15. data/data/czech-olomouc-cs.txt +4 -0
  16. data/data/czech-ostrava-cs.txt +6 -0
  17. data/data/czech-plzen-cs.txt +6 -0
  18. data/data/czech-praha-cs.txt +4 -0
  19. data/data/universal-en.txt +237 -0
  20. data/data/universal-it.txt +236 -0
  21. data/data/universal-la.txt +236 -0
  22. data/lib/calendarium-romanum.rb +2 -0
  23. data/lib/calendarium-romanum/calendar.rb +4 -1
  24. data/lib/calendarium-romanum/cli.rb +100 -0
  25. data/lib/calendarium-romanum/data.rb +41 -0
  26. data/lib/calendarium-romanum/day.rb +7 -1
  27. data/lib/calendarium-romanum/enum.rb +33 -0
  28. data/lib/calendarium-romanum/enums.rb +43 -35
  29. data/lib/calendarium-romanum/rank.rb +16 -12
  30. data/lib/calendarium-romanum/sanctorale.rb +9 -0
  31. data/lib/calendarium-romanum/sanctoraleloader.rb +8 -8
  32. data/lib/calendarium-romanum/temporale.rb +24 -9
  33. data/lib/calendarium-romanum/version.rb +1 -1
  34. data/spec/calendar_spec.rb +89 -7
  35. data/spec/cli_spec.rb +26 -0
  36. data/spec/data_spec.rb +16 -8
  37. data/spec/date_spec.rb +52 -1
  38. data/spec/enum_spec.rb +51 -0
  39. data/spec/i18n_spec.rb +59 -0
  40. data/spec/readme_spec.rb +50 -0
  41. data/spec/sanctorale_spec.rb +24 -1
  42. data/spec/sanctoraleloader_spec.rb +30 -1
  43. data/spec/temporale_spec.rb +24 -0
  44. metadata +28 -2
@@ -1,10 +1,61 @@
1
+ require 'spec_helper'
2
+
1
3
  # expectations concerning the Ruby implementation
2
4
  describe Date do
3
- describe 'substraction' do
5
+ describe '#-' do
4
6
  it 'returns Rational' do
5
7
  date_diff = Date.new(2013,5,5) - Date.new(2013,5,1)
6
8
  expect(date_diff).to be_a Rational
7
9
  expect(date_diff.numerator).to eq 4
8
10
  end
9
11
  end
12
+
13
+ describe 'range' do
14
+ let(:range) { (Date.new(2000,1,1) .. Date.new(2010,1,1)) }
15
+
16
+ # please note that the RSpec 'include' matcher cannot
17
+ # be used here, because it does't simply test
18
+ # if `n.include?(x)` returns true (see it's implementation)
19
+ # and it yields misleading results when testing inclusion
20
+ # of DateTime in a Date range.
21
+ describe 'test Date inclusion' do
22
+ it 'includes' do
23
+ expect(range.include?(Date.new(2005,3,3))).to be true
24
+ end
25
+
26
+ it 'excludes' do
27
+ expect(range.include?(Date.new(1995,3,3))).to be false
28
+ end
29
+ end
30
+
31
+ describe 'test DateTime inclusion' do
32
+ # DateTime without time details is treated just like Date
33
+ describe 'without time specified' do
34
+ it 'excludes' do
35
+ expect(range.include?(DateTime.new(1995,3,3))).to be false
36
+ end
37
+
38
+ it 'includes' do
39
+ expect(range.include?(DateTime.new(2005,3,3))).to be true
40
+ end
41
+ end
42
+
43
+ # treatment of a DateTime with time details is different
44
+ describe 'with time specified' do
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
47
+ end
48
+
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
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ describe 'inheritance' do
57
+ it 'is inherited by DateTime' do
58
+ expect(DateTime.new).to be_a Date
59
+ end
60
+ end
10
61
  end
@@ -0,0 +1,51 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe CalendariumRomanum::Enum do
4
+ let(:enum_values) { [:a, :b] }
5
+
6
+ let(:test_class) do
7
+ Class.new(described_class) { values { [:a, :b] } }
8
+ end
9
+
10
+ describe '.all' do
11
+ it 'returns all values in the original order' do
12
+ expect(test_class.all).to eq enum_values
13
+ end
14
+ end
15
+
16
+ describe '.each' do
17
+ it 'yields all values in the original order' do
18
+ expect {|b| test_class.each(&b) }.to yield_successive_args(*enum_values)
19
+ end
20
+ end
21
+
22
+ describe '[]' do
23
+ describe 'default indexing' do
24
+ it 'finds first element' do
25
+ expect(test_class[0]).to be :a
26
+ end
27
+
28
+ it 'finds last element' do
29
+ expect(test_class[1]).to be :b
30
+ end
31
+
32
+ it 'returns nil for index out of range' do
33
+ expect(test_class[2]).to be nil
34
+ end
35
+ end
36
+
37
+ describe 'indexed by a custom property' do
38
+ let(:test_class) do
39
+ Class.new(described_class) { values(index_by: :to_s) { [1] } }
40
+ end
41
+
42
+ it 'finds the element' do
43
+ expect(test_class['1']).to eq 1
44
+ end
45
+
46
+ it 'returns nil for an unknown index' do
47
+ expect(test_class[1]).to be nil
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,59 @@
1
+ # coding: utf-8
2
+ require_relative 'spec_helper'
3
+
4
+ describe 'internationalization' do
5
+ before :all do
6
+ I18n.backend.load_translations
7
+ end
8
+
9
+ let(:temporale) { CR::Temporale.new(2016) }
10
+ let(:easter_celebration) { temporale.get Date.new(2017, 4, 16) }
11
+
12
+ describe 'supported locales' do
13
+ before :each do
14
+ @last_locale = I18n.locale
15
+ I18n.locale = locale
16
+ end
17
+
18
+ after :each do
19
+ I18n.locale = @last_locale
20
+ end
21
+
22
+ describe 'English' do
23
+ let(:locale) { 'en' }
24
+
25
+ it 'translates Temporale feast names' do
26
+ expect(easter_celebration.title).to eq 'Easter Sunday of the Resurrection of the Lord'
27
+ end
28
+
29
+ it 'translates rank names' do
30
+ rank = CR::Ranks::SUNDAY_UNPRIVILEGED
31
+ expect(rank.desc).to eq 'Unprivileged Sundays'
32
+ expect(rank.short_desc).to eq 'Sunday'
33
+ end
34
+ end
35
+
36
+ describe 'Czech' do
37
+ let(:locale) { 'cs' }
38
+
39
+ it 'translates Temporale feast names' do
40
+ expect(easter_celebration.title).to eq 'Zmrtvýchvstání Páně'
41
+ end
42
+
43
+ it 'translates rank names' do
44
+ rank = CR::Ranks::SUNDAY_UNPRIVILEGED
45
+ expect(rank.desc).to eq 'Neprivilegované neděle'
46
+ expect(rank.short_desc).to eq 'neděle'
47
+ end
48
+ end
49
+ end
50
+
51
+ describe 'unsupported locale' do
52
+ # I will be most happy when this locale one day moves to the 'supported' branch!
53
+ let(:locale) { 'de' }
54
+
55
+ it 'attemt to switch to it fails by default' do
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ class MarkdownDocument
4
+ def initialize(str)
5
+ @str = str
6
+ end
7
+
8
+ def each_ruby_example
9
+ example = nil
10
+ line = nil
11
+ @str.each_line.with_index(1) do |l, i|
12
+ if example.nil?
13
+ if example_beginning?(l)
14
+ example = ''
15
+ line = i + 1
16
+ end
17
+ elsif example_end?(l)
18
+ yield example, line
19
+ example = nil
20
+ else
21
+ example += l
22
+ end
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def example_beginning?(line)
29
+ line =~ /^```ruby/
30
+ end
31
+
32
+ def example_end?(line)
33
+ line =~ /```/
34
+ end
35
+ end
36
+
37
+ describe 'README.md' do
38
+ readme_path = File.expand_path('../../README.md', __FILE__)
39
+ readme = File.read readme_path
40
+ doc = MarkdownDocument.new readme
41
+
42
+ doc.each_ruby_example do |code, line|
43
+ describe "example L#{line}" do
44
+ it 'executes without failure' do
45
+ cls = Class.new
46
+ cls.class_eval(code, readme_path, line)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -30,7 +30,7 @@ describe CR::Sanctorale do
30
30
  [
31
31
  'S. Fabiani, papae et martyris',
32
32
  'S. Sebastiani, martyris'
33
- ].each {|t| @s.add 1, 20, CR::Celebration.new(t) }
33
+ ].each {|t| @s.add 1, 20, CR::Celebration.new(t, CR::Ranks::MEMORIAL_OPTIONAL) }
34
34
  expect(@s.get(1, 20).size).to eq 2
35
35
  end
36
36
  end
@@ -57,6 +57,29 @@ describe CR::Sanctorale do
57
57
  it 'does not add non-solemnity to solemnities' do
58
58
  expect { @s.add 1, 13, CR::Celebration.new('S. Nullius') }.not_to change { @s.solemnities.size }
59
59
  end
60
+
61
+ describe 'multiple celebrations on a single day' do
62
+ it 'succeeds for any number of optional memorials' do
63
+ expect do
64
+ @s.add 1, 13, CR::Celebration.new('S. Nullius', CR::Ranks::MEMORIAL_OPTIONAL)
65
+ @s.add 1, 13, CR::Celebration.new('S. Ignoti', CR::Ranks::MEMORIAL_OPTIONAL)
66
+ end.not_to raise_exception
67
+ end
68
+
69
+ it 'fails when adding a non-optional memorial' do
70
+ expect do
71
+ @s.add 1, 13, CR::Celebration.new('S. Nullius', CR::Ranks::MEMORIAL_OPTIONAL)
72
+ @s.add 1, 13, CR::Celebration.new('S. Ignoti', CR::Ranks::MEMORIAL_GENERAL)
73
+ end.to raise_exception ArgumentError
74
+ end
75
+
76
+ it 'fails when adding to a non-optional memorial' do
77
+ expect do
78
+ @s.add 1, 13, CR::Celebration.new('S. Nullius', CR::Ranks::MEMORIAL_GENERAL)
79
+ @s.add 1, 13, CR::Celebration.new('S. Ignoti', CR::Ranks::MEMORIAL_OPTIONAL)
80
+ end.to raise_exception ArgumentError
81
+ end
82
+ end
60
83
  end
61
84
 
62
85
  describe '#replace' do
@@ -65,16 +65,45 @@ describe CR::SanctoraleLoader do
65
65
  @l.load_from_string str, @s
66
66
  expect(@s.get(4, 25).first.colour).to eq CR::Colours::RED
67
67
  end
68
+
69
+ it 'sets colour if specified (lowercase)' do
70
+ str = '4/25 f r : S. Marci, evangelistae'
71
+ @l.load_from_string str, @s
72
+ expect(@s.get(4, 25).first.colour).to eq CR::Colours::RED
73
+ end
68
74
  end
69
75
 
70
76
  describe 'rank' do
77
+ # say we specify a proper calendar of a church dedicated to St. George
78
+
79
+ it 'sets rank if specified' do
80
+
81
+ str = '4/23 s R : S. Georgii, martyris'
82
+ @l.load_from_string str, @s
83
+ celeb = @s.get(4, 23).first
84
+ expect(celeb.rank).to eq CR::Ranks::SOLEMNITY_GENERAL
85
+ end
86
+
87
+ it 'sets rank if specified (uppercase)' do
88
+ str = '4/23 S R : S. Georgii, martyris'
89
+ @l.load_from_string str, @s
90
+ celeb = @s.get(4, 23).first
91
+ expect(celeb.rank).to eq CR::Ranks::SOLEMNITY_GENERAL
92
+ end
93
+
71
94
  it 'sets exact rank if specified' do
72
- # say we specify a proper calendar of a church dedicated to St. George
73
95
  str = '4/23 s1.4 R : S. Georgii, martyris'
74
96
  @l.load_from_string str, @s
75
97
  celeb = @s.get(4, 23).first
76
98
  expect(celeb.rank).to eq CR::Ranks::SOLEMNITY_PROPER
77
99
  end
100
+
101
+ it 'sets exact rank if specified only by number' do
102
+ str = '4/23 1.4 R : S. Georgii, martyris'
103
+ @l.load_from_string str, @s
104
+ celeb = @s.get(4, 23).first
105
+ expect(celeb.rank).to eq CR::Ranks::SOLEMNITY_PROPER
106
+ end
78
107
  end
79
108
  end
80
109
 
@@ -245,10 +245,25 @@ describe CR::Temporale do
245
245
  expect(c.colour).to eq CR::Colours::WHITE
246
246
  end
247
247
 
248
+ it 'Ash Wednesday' do
249
+ c = @t13.get(3, 5)
250
+ expect(c.rank).to eq CR::Ranks::PRIMARY
251
+ expect(c.title).to eq 'Ash Wednesday'
252
+ expect(c.colour).to eq CR::Colours::VIOLET
253
+ end
254
+
255
+ it 'Palm Sunday' do
256
+ c = @t13.get(4, 13)
257
+ expect(c.rank).to eq CR::Ranks::PRIMARY
258
+ expect(c.title).to eq 'Palm Sunday of the Passion of the Lord'
259
+ expect(c.colour).to eq CR::Colours::RED
260
+ end
261
+
248
262
  it 'Good Friday' do
249
263
  c = @t13.get(4, 18)
250
264
  expect(c.rank).to eq CR::Ranks::TRIDUUM
251
265
  expect(c.title).to eq 'Friday of the Passion of the Lord'
266
+ expect(c.colour).to eq CR::Colours::RED
252
267
  end
253
268
 
254
269
  it 'Holy Saturday' do
@@ -262,11 +277,20 @@ describe CR::Temporale do
262
277
  c = @t13.get(4, 20)
263
278
  expect(c.rank).to eq CR::Ranks::TRIDUUM
264
279
  expect(c.title).to eq 'Easter Sunday of the Resurrection of the Lord'
280
+ expect(c.colour).to eq CR::Colours::WHITE
265
281
  end
266
282
 
267
283
  it 'day in the Easter Octave' do
268
284
  c = @t13.get(4, 22)
269
285
  expect(c.rank).to eq CR::Ranks::PRIMARY
286
+ expect(c.colour).to eq CR::Colours::WHITE
287
+ end
288
+
289
+ it 'Ascension' do
290
+ c = @t13.get(5, 29)
291
+ expect(c.rank).to eq CR::Ranks::PRIMARY
292
+ expect(c.title).to eq 'Ascension of the Lord'
293
+ expect(c.colour).to eq CR::Colours::WHITE
270
294
  end
271
295
 
272
296
  it 'Pentecost' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calendarium-romanum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Pavlík
@@ -69,16 +69,38 @@ dependencies:
69
69
  description: calendar computations according to the Roman Catholic liturgical calendar
70
70
  as instituted by MP Mysterii Paschalis of Paul VI (1969).
71
71
  email: jkb.pavlik@gmail.com
72
- executables: []
72
+ executables:
73
+ - calendariumrom
73
74
  extensions: []
74
75
  extra_rdoc_files: []
75
76
  files:
76
77
  - bin/calendariumrom
78
+ - config/locales/cs.yml
77
79
  - config/locales/en.yml
80
+ - config/locales/it.yml
81
+ - config/locales/la.yml
82
+ - data/README.md
83
+ - data/czech-brno-cs.txt
84
+ - data/czech-budejovice-cs.txt
85
+ - data/czech-cechy-cs.txt
86
+ - data/czech-cs.txt
87
+ - data/czech-hradec-cs.txt
88
+ - data/czech-litomerice-cs.txt
89
+ - data/czech-morava-cs.txt
90
+ - data/czech-olomouc-cs.txt
91
+ - data/czech-ostrava-cs.txt
92
+ - data/czech-plzen-cs.txt
93
+ - data/czech-praha-cs.txt
94
+ - data/universal-en.txt
95
+ - data/universal-it.txt
96
+ - data/universal-la.txt
78
97
  - lib/calendarium-romanum.rb
79
98
  - lib/calendarium-romanum/abstract_date.rb
80
99
  - lib/calendarium-romanum/calendar.rb
100
+ - lib/calendarium-romanum/cli.rb
101
+ - lib/calendarium-romanum/data.rb
81
102
  - lib/calendarium-romanum/day.rb
103
+ - lib/calendarium-romanum/enum.rb
82
104
  - lib/calendarium-romanum/enums.rb
83
105
  - lib/calendarium-romanum/i18n_setup.rb
84
106
  - lib/calendarium-romanum/rank.rb
@@ -91,9 +113,13 @@ files:
91
113
  - lib/calendarium-romanum/version.rb
92
114
  - spec/abstract_date_spec.rb
93
115
  - spec/calendar_spec.rb
116
+ - spec/cli_spec.rb
94
117
  - spec/data_spec.rb
95
118
  - spec/date_spec.rb
119
+ - spec/enum_spec.rb
120
+ - spec/i18n_spec.rb
96
121
  - spec/rank_spec.rb
122
+ - spec/readme_spec.rb
97
123
  - spec/sanctorale_factory_spec.rb
98
124
  - spec/sanctorale_spec.rb
99
125
  - spec/sanctoraleloader_spec.rb