calendarium-romanum 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/config/locales/cs.yml +2 -0
  3. data/config/locales/en.yml +16 -14
  4. data/config/locales/fr.yml +2 -0
  5. data/config/locales/it.yml +2 -0
  6. data/config/locales/la.yml +2 -0
  7. data/lib/calendarium-romanum/calendar.rb +31 -18
  8. data/lib/calendarium-romanum/cli.rb +9 -3
  9. data/lib/calendarium-romanum/day.rb +39 -11
  10. data/lib/calendarium-romanum/enums.rb +17 -13
  11. data/lib/calendarium-romanum/perpetual_calendar.rb +10 -0
  12. data/lib/calendarium-romanum/rank.rb +15 -1
  13. data/lib/calendarium-romanum/sanctorale.rb +15 -1
  14. data/lib/calendarium-romanum/{sanctoraleloader.rb → sanctorale_loader.rb} +52 -39
  15. data/lib/calendarium-romanum/temporale/celebration_factory.rb +21 -6
  16. data/lib/calendarium-romanum/temporale/dates.rb +4 -0
  17. data/lib/calendarium-romanum/temporale.rb +31 -8
  18. data/lib/calendarium-romanum/version.rb +2 -2
  19. data/lib/calendarium-romanum.rb +2 -2
  20. data/spec/abstract_date_spec.rb +11 -3
  21. data/spec/calendar_spec.rb +169 -16
  22. data/spec/celebration_factory_spec.rb +20 -0
  23. data/spec/celebration_spec.rb +15 -0
  24. data/spec/cli_spec.rb +7 -0
  25. data/spec/colour_spec.rb +5 -0
  26. data/spec/data_spec.rb +2 -2
  27. data/spec/dates_spec.rb +28 -0
  28. data/spec/day_spec.rb +17 -0
  29. data/spec/i18n_spec.rb +1 -1
  30. data/spec/ordinalizer_spec.rb +8 -0
  31. data/spec/perpetual_calendar_spec.rb +37 -3
  32. data/spec/rank_spec.rb +20 -0
  33. data/spec/readme_spec.rb +3 -1
  34. data/spec/sanctorale_loader_spec.rb +204 -0
  35. data/spec/sanctorale_spec.rb +27 -0
  36. data/spec/season_spec.rb +5 -0
  37. data/spec/temporale_spec.rb +160 -38
  38. metadata +4 -4
  39. data/spec/sanctoraleloader_spec.rb +0 -176
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4faa0e6242f3815ad7bdc2b32c13c61f203cd5e6
4
- data.tar.gz: 78018940d6ae8129c0625db963543991bf980350
3
+ metadata.gz: ca0a118c46265f72b4b8fc27d6680779a49313c6
4
+ data.tar.gz: 757e015ca4d21a39a09056589826ee2c37996291
5
5
  SHA512:
6
- metadata.gz: f3b27ee6cd3919d97b6a819baa88cf694a9eedf9b5182ddf766dedf39a9ef85fef8c90962d6fee8417ac3261d0062d158bb60f9cd7a801fcd67f7e1d2d816e85
7
- data.tar.gz: 2cdfdb4bb9d604e5c1b6e59e604719634458c5b0859c79d70d2cb6fe80bf29139ec5400273f83f7e81854144b88cc75affb49f4dfd25681648f1464dc68fb9d7
6
+ metadata.gz: 1b2d1dd8a18416939f81f2ed73d8300a981264cf7197f1a0dac21ff521fdcd6345af66bb15a2e3b7cbe9ab0d325b79650fe2c9c3ec0b65ff17b3fed946970c94
7
+ data.tar.gz: 88eabc461278fc61cf1bf381e2db023447849874796949291d2b11cfc87c3f9488d33241c17487a0f28c394d0f2466c619b06fea78ff5d08d99fba952a2ae9f3
@@ -22,8 +22,10 @@ cs:
22
22
  holy_trinity: Nejsvětější Trojice
23
23
  corpus_christi: Těla a krve Páně
24
24
  sacred_heart: Nejsvětějšího srdce Ježíšova
25
+ mother_of_church: Panny Marie, Matky církve
25
26
  immaculate_heart: Neposkvrněného Srdce Panny Marie
26
27
  christ_king: Ježíše Krista krále
28
+ saturday_memorial_bvm: Sobotní památka Panny Marie
27
29
  extension:
28
30
  christ_eternal_priest: Ježíše Krista, nejvyššího a věčného kněze
29
31
  ordinary:
@@ -7,23 +7,25 @@ en:
7
7
  easter: Easter Season
8
8
  ordinary: Ordinary Time
9
9
  solemnity:
10
- nativity: The Nativity of the Lord
11
- holy_family: The Holy Family of Jesus, Mary and Joseph
12
- mother_of_god: Octave Day of Christmas, of Mary, Mother of God
13
- epiphany: The Epiphany of the Lord
10
+ nativity: Christmas
11
+ holy_family: The Holy Family
12
+ mother_of_god: Mary, Mother of God (Octave of Christmas)
13
+ epiphany: The Epiphany
14
14
  baptism_of_lord: The Baptism of the Lord
15
15
  ash_wednesday: Ash Wednesday
16
- palm_sunday: Palm Sunday of the Passion of the Lord
17
- good_friday: Friday of the Passion of the Lord
16
+ palm_sunday: Passion Sunday (Palm Sunday)
17
+ good_friday: Good Friday
18
18
  holy_saturday: Holy Saturday
19
- easter_sunday: Easter Sunday of the Resurrection of the Lord
20
- ascension: Ascension of the Lord
21
- pentecost: Pentecost Sunday
22
- holy_trinity: The Most Holy Trinity
23
- corpus_christi: The Most Holy Body and Blood of Christ
24
- sacred_heart: The Most Sacred Heart of Jesus
25
- immaculate_heart: Immaculate Heart of Mary
26
- christ_king: Our Lord Jesus Christ, King of the Universe
19
+ easter_sunday: Easter Sunday
20
+ ascension: The Ascension
21
+ pentecost: Pentecost
22
+ holy_trinity: Trinity Sunday
23
+ corpus_christi: Corpus Christi (The Body and Blood of Christ)
24
+ sacred_heart: The Sacred Heart of Jesus
25
+ mother_of_church: Mary, Mother of the Church
26
+ immaculate_heart: The Immaculate Heart of Mary
27
+ christ_king: Christ The King
28
+ saturday_memorial_bvm: The Memorial of the Blessed Virgin Mary on Saturday
27
29
  ordinary:
28
30
  sunday: '%{week} Sunday in Ordinary Time'
29
31
  ferial: '%{weekday}, %{week} week in Ordinary Time'
@@ -22,8 +22,10 @@ fr:
22
22
  holy_trinity: La Très Sainte Trinité
23
23
  corpus_christi: Le Très Saint Corps et Sang du Christ
24
24
  sacred_heart: Le Sacré-Coeur de Jésus
25
+ mother_of_church: Sainte Marie, Mère de l’Eglise
25
26
  immaculate_heart: Le Coeur Immaculé de Marie
26
27
  christ_king: Notre Seigneur Jésus Christ, Roi de l'Univers
28
+ saturday_memorial_bvm: Mémoire de Sainte-Marie le samedi
27
29
  ordinary:
28
30
  sunday: '%{week} Dimanche de Temps Ordinaire'
29
31
  ferial: '%{weekday}, %{week} semaine de Temps Ordinaire'
@@ -22,8 +22,10 @@ it:
22
22
  holy_trinity: Santissima Trinità
23
23
  corpus_christi: Santissimo Corpo e Sangue di Cristo
24
24
  sacred_heart: Sacro Cuore di Gesù
25
+ mother_of_church: Maria Madre della Chiesa
25
26
  immaculate_heart: Cuore Immacolato di Maria
26
27
  christ_king: "Nostro Signore Gesù Cristo Re dell'universo"
28
+ saturday_memorial_bvm: Memoria di santa Maria in sabato
27
29
  ordinary:
28
30
  sunday: '%{week} Domenica del Tempo Ordinario'
29
31
  ferial: '%{weekday} della %{week} settimana del Tempo Ordinario'
@@ -22,8 +22,10 @@ la:
22
22
  holy_trinity: Sanctissimae Trinitatis
23
23
  corpus_christi: Sanctissimi Corporis et Sanguinis Christi
24
24
  sacred_heart: Sacratissimi Cordis Iesu
25
+ mother_of_church: B. Mariae Virginis Ecclesiae Matris
25
26
  immaculate_heart: Immaculati Cordis B. Mariae Virginis
26
27
  christ_king: Domini nostri Iesu Christi universorum regis
28
+ saturday_memorial_bvm: Memoria Sanctae Mariae in Sabbato
27
29
  ordinary:
28
30
  sunday: 'Dominica %{week} per annum'
29
31
  ferial: '%{weekday}, hebdomada %{week} per annum'
@@ -37,17 +37,13 @@ module CalendariumRomanum
37
37
 
38
38
  if args.size == 3
39
39
  args.each do |a|
40
- unless a.is_a? Integer
41
- raise ex
42
- end
40
+ raise ex unless a.is_a? Integer
43
41
  end
44
42
  return Date.new(*args)
45
43
 
46
44
  elsif args.size == 1
47
45
  a = args.first
48
- unless a.is_a? Date
49
- raise ex
50
- end
46
+ raise ex unless a.is_a? Date
51
47
  return a
52
48
 
53
49
  else
@@ -67,19 +63,25 @@ module CalendariumRomanum
67
63
  attr_reader :temporale
68
64
  attr_reader :sanctorale
69
65
 
70
- def ==(obj)
71
- unless obj.is_a? Calendar
72
- return false
73
- end
66
+ def populates_vespers?
67
+ @populate_vespers
68
+ end
74
69
 
75
- year == obj.year
70
+ # Calendars are equal if they have equal settings
71
+ # (which means that to equal input they return equal data)
72
+ def ==(b)
73
+ b.class == self.class &&
74
+ year == b.year &&
75
+ populates_vespers? == b.populates_vespers? &&
76
+ temporale == b.temporale &&
77
+ sanctorale == b.sanctorale
76
78
  end
77
79
 
78
80
  def [](args)
79
81
  if(args.is_a?(Range))
80
82
  args.map{|date| day(date)}
81
83
  else
82
- day(*args)
84
+ day(args)
83
85
  end
84
86
  end
85
87
 
@@ -124,6 +126,11 @@ module CalendariumRomanum
124
126
  )
125
127
  end
126
128
 
129
+ def each
130
+ (temporale.start_date..temporale.end_date)
131
+ .each { |date| yield(day(date)) }
132
+ end
133
+
127
134
  # Sunday lectionary cycle
128
135
  def lectionary
129
136
  LECTIONARY_CYCLES[@year % 3]
@@ -146,8 +153,15 @@ module CalendariumRomanum
146
153
  tr = @transferred.get(date)
147
154
  return [tr] if tr
148
155
 
149
- t = @temporale.get date
150
- st = @sanctorale.get date
156
+ t = @temporale[date]
157
+ st = @sanctorale[date]
158
+
159
+ if date.saturday? &&
160
+ @temporale.season(date) == Seasons::ORDINARY &&
161
+ (st.empty? || st.first.rank == Ranks::MEMORIAL_OPTIONAL) &&
162
+ t.rank <= Ranks::MEMORIAL_OPTIONAL
163
+ st = st.dup << Temporale::CelebrationFactory.saturday_memorial_bvm
164
+ end
151
165
 
152
166
  unless st.empty?
153
167
  if st.first.rank > t.rank
@@ -157,11 +171,10 @@ module CalendariumRomanum
157
171
  return st
158
172
  end
159
173
  elsif t.rank == Ranks::FERIAL_PRIVILEGED && st.first.rank.memorial?
160
- st = st.collect do |c|
161
- Celebration.new(c.title, Ranks::COMMEMORATION, t.colour)
174
+ commemorations = st.collect do |c|
175
+ c.change(rank: Ranks::COMMEMORATION, colour: t.colour)
162
176
  end
163
- st.unshift t
164
- return st
177
+ return commemorations.unshift t
165
178
  elsif t.symbol == :immaculate_heart &&
166
179
  [Ranks::MEMORIAL_GENERAL, Ranks::MEMORIAL_PROPER].include?(st.first.rank)
167
180
  optional_memorials = ([t] + st).collect do |celebration|
@@ -76,7 +76,6 @@ module CalendariumRomanum
76
76
  ca = a[i]
77
77
  cb = b[i]
78
78
  compared = [ca, cb]
79
- differences = []
80
79
 
81
80
  if compared.index(&:nil?)
82
81
  notnili = compared.index {|c| !c.nil? }
@@ -88,8 +87,9 @@ module CalendariumRomanum
88
87
  next
89
88
  end
90
89
 
91
- differences << 'rank' if ca.rank != cb.rank
92
- differences << 'colour' if ca.colour != cb.colour
90
+ differences = %i(rank colour symbol).select do |property|
91
+ ca.public_send(property) != cb.public_send(property)
92
+ end
93
93
 
94
94
  next if differences.empty?
95
95
  print date(d)
@@ -101,6 +101,12 @@ module CalendariumRomanum
101
101
  end
102
102
  end
103
103
 
104
+ desc 'version', 'print version information'
105
+ def version
106
+ puts 'calendarium-romanum CLI'
107
+ puts "calendarium-romanum: version #{CalendariumRomanum::VERSION}, released #{CalendariumRomanum::RELEASE_DATE}"
108
+ end
109
+
104
110
  private
105
111
 
106
112
  def date(d)
@@ -51,20 +51,24 @@ module CalendariumRomanum
51
51
 
52
52
  # information on one particular celebration of the liturgical year
53
53
  # (like a Sunday, feast or memorial);
54
- # some days have no (ferial office is used), some have one,
55
- # some have more among which one may and may not be chosen
54
+ # some days have one,
55
+ # some have more among which one is to be chosen
56
56
  class Celebration
57
57
  extend Forwardable
58
58
 
59
- def initialize(title = '', rank = Ranks::FERIAL, colour = Colours::GREEN, symbol = nil)
59
+ def initialize(title = '', rank = Ranks::FERIAL, colour = Colours::GREEN, symbol = nil, date = nil, cycle = :sanctorale)
60
60
  @title = title
61
61
  @rank = rank
62
62
  @colour = colour
63
63
  @symbol = symbol
64
+ @date = date
65
+ @cycle = cycle
64
66
  end
65
67
 
68
+ # Rank instance
66
69
  attr_reader :rank
67
- def_delegators :@rank, :solemnity?, :feast?, :memorial?
70
+
71
+ def_delegators :@rank, :solemnity?, :feast?, :memorial?, :sunday?, :ferial?
68
72
 
69
73
  def title
70
74
  if @title.respond_to? :call
@@ -74,24 +78,48 @@ module CalendariumRomanum
74
78
  end
75
79
  end
76
80
 
81
+ # Colour instance (always set) - liturgical colour
77
82
  attr_reader :colour
78
83
  alias color colour
79
84
 
85
+ # Symbol uniquely identifying the celebration (may be nil)
80
86
  attr_reader :symbol
81
87
 
82
- def ==(other)
83
- self.class == other.class &&
84
- title == other.title &&
85
- rank == other.rank &&
86
- colour == other.colour
88
+ # AbstractDate instance - usual date of the celebration.
89
+ # Only set for celebrations with fixed date.
90
+ attr_reader :date
91
+
92
+ # Symbol :temporale|:sanctorale
93
+ # Describes the celebration as belonging either to the
94
+ # temporale or sanctorale cycle
95
+ attr_reader :cycle
96
+
97
+ def ==(b)
98
+ self.class == b.class &&
99
+ title == b.title &&
100
+ rank == b.rank &&
101
+ colour == b.colour &&
102
+ symbol == b.symbol &&
103
+ date == b.date &&
104
+ cycle == b.cycle
105
+ end
106
+
107
+ def temporale?
108
+ cycle == :temporale
109
+ end
110
+
111
+ def sanctorale?
112
+ cycle == :sanctorale
87
113
  end
88
114
 
89
- def change(title: nil, rank: nil, colour: nil, color: nil, symbol: nil)
115
+ def change(title: nil, rank: nil, colour: nil, color: nil, symbol: nil, date: nil, cycle: nil)
90
116
  self.class.new(
91
117
  title || self.title,
92
118
  rank || self.rank,
93
119
  colour || color || self.colour,
94
- symbol || self.symbol
120
+ symbol || self.symbol,
121
+ date || self.date,
122
+ cycle || self.cycle,
95
123
  )
96
124
  end
97
125
  end
@@ -1,17 +1,24 @@
1
1
  module CalendariumRomanum
2
-
3
- class Colour
4
- def initialize(symbol)
5
- @symbol = symbol
6
- @i18n_key = "colour.#{@symbol}"
7
- end
8
-
2
+ module ValueObjectInterface
9
3
  attr_reader :symbol
10
4
  alias to_sym symbol
11
5
 
12
6
  def name
13
7
  I18n.t @i18n_key
14
8
  end
9
+
10
+ def to_s
11
+ "#<#{self.class.name} #{symbol}>"
12
+ end
13
+ end
14
+
15
+ class Colour
16
+ include ValueObjectInterface
17
+
18
+ def initialize(symbol)
19
+ @symbol = symbol
20
+ @i18n_key = "colour.#{@symbol}"
21
+ end
15
22
  end
16
23
 
17
24
  class Colours < Enum
@@ -28,18 +35,15 @@ module CalendariumRomanum
28
35
  Colors = Colours
29
36
 
30
37
  class Season
38
+ include ValueObjectInterface
39
+
31
40
  def initialize(symbol, colour)
32
41
  @symbol = symbol
33
42
  @colour = colour
34
43
  @i18n_key = "temporale.season.#{@symbol}"
35
44
  end
36
45
 
37
- attr_reader :symbol, :colour
38
- alias to_sym symbol
39
-
40
- def name
41
- I18n.t @i18n_key
42
- end
46
+ attr_reader :colour
43
47
  end
44
48
 
45
49
  class Seasons < Enum
@@ -18,6 +18,16 @@ module CalendariumRomanum
18
18
  calendar_for(*args).day(*args)
19
19
  end
20
20
 
21
+ def [](arg)
22
+ if arg.is_a? Range
23
+ return arg.collect do |date|
24
+ calendar_for(date).day(date)
25
+ end
26
+ end
27
+
28
+ day(arg)
29
+ end
30
+
21
31
  # returns a Calendar instance for the liturgical year containing
22
32
  # the specified day
23
33
  def calendar_for(*args)
@@ -15,7 +15,12 @@ module CalendariumRomanum
15
15
  @desc && I18n.t(@desc)
16
16
  end
17
17
 
18
- alias to_s desc
18
+ def to_s
19
+ # 'desc' instead of '@desc' is intentional -
20
+ # for a good reason we don't present contents of an instance
21
+ # variable but result of an instance method
22
+ "#<#{self.class.name} @priority=#{priority} desc=#{desc.inspect}>"
23
+ end
19
24
 
20
25
  def short_desc
21
26
  @short_desc && I18n.t(@short_desc)
@@ -29,6 +34,10 @@ module CalendariumRomanum
29
34
  priority.to_i == 1
30
35
  end
31
36
 
37
+ def sunday?
38
+ self == Ranks::SUNDAY_UNPRIVILEGED
39
+ end
40
+
32
41
  def feast?
33
42
  priority.to_i == 2
34
43
  end
@@ -36,5 +45,10 @@ module CalendariumRomanum
36
45
  def memorial?
37
46
  priority.to_i == 3 && priority <= 3.12
38
47
  end
48
+
49
+ def ferial?
50
+ self == Ranks::FERIAL ||
51
+ self == Ranks::FERIAL_PRIVILEGED
52
+ end
39
53
  end
40
54
  end
@@ -53,6 +53,11 @@ module CalendariumRomanum
53
53
  end
54
54
  end
55
55
 
56
+ def [](date)
57
+ adate = date.is_a?(AbstractDate) ? date : AbstractDate.from_date(date)
58
+ @days[adate] || []
59
+ end
60
+
56
61
  # returns an Array with one or more Celebrations
57
62
  # scheduled for the given day
58
63
  #
@@ -66,7 +71,7 @@ module CalendariumRomanum
66
71
  end
67
72
 
68
73
  date = AbstractDate.new(month, day)
69
- @days[date] || []
74
+ self[date]
70
75
  end
71
76
 
72
77
  # for each day for which an entry is available
@@ -92,5 +97,14 @@ module CalendariumRomanum
92
97
  @solemnities.freeze
93
98
  super
94
99
  end
100
+
101
+ def ==(b)
102
+ self.class == b.class &&
103
+ days == b.days
104
+ end
105
+
106
+ protected
107
+
108
+ attr_reader :days
95
109
  end
96
110
  end