Class: CalendariumRomanum::Sanctorale

Inherits:
Object
  • Object
show all
Defined in:
lib/calendarium-romanum/sanctorale.rb

Overview

knows the fixed-date celebrations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSanctorale

Returns a new instance of Sanctorale.



6
7
8
9
10
# File 'lib/calendarium-romanum/sanctorale.rb', line 6

def initialize
  @days = {}

  @solemnities = {}
end

Instance Attribute Details

#solemnitiesObject (readonly)

Returns the value of attribute solemnities.



12
13
14
# File 'lib/calendarium-romanum/sanctorale.rb', line 12

def solemnities
  @solemnities
end

Instance Method Details

#==(b) ⇒ Object



101
102
103
104
# File 'lib/calendarium-romanum/sanctorale.rb', line 101

def ==(b)
  self.class == b.class &&
    days == b.days
end

#[](date) ⇒ Object



56
57
58
59
# File 'lib/calendarium-romanum/sanctorale.rb', line 56

def [](date)
  adate = date.is_a?(AbstractDate) ? date : AbstractDate.from_date(date)
  @days[adate] || []
end

#add(month, day, celebration) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/calendarium-romanum/sanctorale.rb', line 14

def add(month, day, celebration)
  date = AbstractDate.new(month, day)
  unless @days.has_key? date
    @days[date] = []
  end

  if celebration.solemnity?
    @solemnities[date] = celebration
  end

  unless @days[date].empty?
    present = @days[date][0]
    if present.rank != Ranks::MEMORIAL_OPTIONAL
      raise ArgumentError.new("On #{date} there is already a #{present.rank}. No more celebrations can be added.")
    elsif celebration.rank != Ranks::MEMORIAL_OPTIONAL
      raise ArgumentError.new("Celebration of rank #{celebration.rank} cannot be grouped, but there is already another celebration on #{date}")
    end
  end

  @days[date] << celebration
end

#each_dayObject

for each day for which an entry is available yields an AbstractDate and an Array of Celebrations



79
80
81
82
83
# File 'lib/calendarium-romanum/sanctorale.rb', line 79

def each_day
  @days.each_pair do |date, celebrations|
    yield date, celebrations
  end
end

#empty?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/calendarium-romanum/sanctorale.rb', line 90

def empty?
  @days.empty?
end

#freezeObject



94
95
96
97
98
99
# File 'lib/calendarium-romanum/sanctorale.rb', line 94

def freeze
  @days.freeze
  @days.values.each(&:freeze)
  @solemnities.freeze
  super
end

#get(*args) ⇒ Object

returns an Array with one or more Celebrations scheduled for the given day

expected arguments: Date or two Integers (month, day)



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/calendarium-romanum/sanctorale.rb', line 65

def get(*args)
  if args.size == 1 && args[0].is_a?(Date)
    month = args[0].month
    day = args[0].day
  else
    month, day = args
  end

  date = AbstractDate.new(month, day)
  self[date]
end

#replace(month, day, celebrations) ⇒ Object

replaces content of the given day by given celebrations



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/calendarium-romanum/sanctorale.rb', line 37

def replace(month, day, celebrations)
  date = AbstractDate.new(month, day)

  if celebrations.first.solemnity?
    @solemnities[date] = celebrations.first
  elsif @solemnities.has_key? date
    @solemnities.delete date
  end

  @days[date] = celebrations.dup
end

#sizeObject

returns count of the days with celebrations filled



86
87
88
# File 'lib/calendarium-romanum/sanctorale.rb', line 86

def size
  @days.size
end

#update(sanctorale) ⇒ Object

adds all Celebrations from another instance



50
51
52
53
54
# File 'lib/calendarium-romanum/sanctorale.rb', line 50

def update(sanctorale)
  sanctorale.each_day do |date, celebrations|
    replace date.month, date.day, celebrations
  end
end