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

#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


74
75
76
77
78
# File 'lib/calendarium-romanum/sanctorale.rb', line 74

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

#empty?Boolean

Returns:

  • (Boolean)

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

def empty?
  @days.empty?
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)


60
61
62
63
64
65
66
67
68
69
70
# File 'lib/calendarium-romanum/sanctorale.rb', line 60

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)
  return @days[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
end

#sizeObject

returns count of the days with celebrations filled


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

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