Class: CalendariumRomanum::Calendar

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/calendarium-romanum/calendar.rb

Overview

Provides complete information concerning a liturgical year, it’s days and celebrations occurring on them.

Constant Summary collapse

EFFECTIVE_FROM =

Day when the implemented calendar system became effective

Date.new(1970, 1, 1).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, sanctorale = nil, temporale = nil, vespers: false) ⇒ Calendar

year: Integer returns a calendar for the liturgical year beginning with Advent of the specified civil year.



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

def initialize(year, sanctorale = nil, temporale = nil, vespers: false)
  if year < (EFFECTIVE_FROM.year - 1)
    raise system_not_effective
  end

  if temporale && temporale.year != year
    raise ArgumentError.new('Temporale year must be the same as year.')
  end

  @year = year
  @sanctorale = sanctorale || Sanctorale.new
  @temporale = temporale || Temporale.new(year)
  @populate_vespers = vespers

  @transferred = Transfers.new(@temporale, @sanctorale)
end

Instance Attribute Details

#sanctoraleObject (readonly)

Returns the value of attribute sanctorale.



64
65
66
# File 'lib/calendarium-romanum/calendar.rb', line 64

def sanctorale
  @sanctorale
end

#temporaleObject (readonly)

Returns the value of attribute temporale.



63
64
65
# File 'lib/calendarium-romanum/calendar.rb', line 63

def temporale
  @temporale
end

#yearObject (readonly)

Returns the value of attribute year.



62
63
64
# File 'lib/calendarium-romanum/calendar.rb', line 62

def year
  @year
end

Class Method Details

.for_day(date, *constructor_args) ⇒ Object

creates a Calendar for the liturgical year including given date



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

def for_day(date, *constructor_args)
  new(Temporale.liturgical_year(date), *constructor_args)
end

.mk_date(*args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/calendarium-romanum/calendar.rb', line 35

def mk_date(*args)
  ex = TypeError.new('Date, DateTime or three Integers expected')

  if args.size == 3
    args.each do |a|
      raise ex unless a.is_a? Integer
    end
    return Date.new(*args)

  elsif args.size == 1
    a = args.first
    raise ex unless a.is_a? Date
    return a

  else
    raise ex
  end
end

Instance Method Details

#==(b) ⇒ Object

Calendars are equal if they have equal settings (which means that to equal input they return equal data)



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

def ==(b)
  b.class == self.class &&
    year == b.year &&
    populates_vespers? == b.populates_vespers? &&
    temporale == b.temporale &&
    sanctorale == b.sanctorale
end

#[](args) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/calendarium-romanum/calendar.rb', line 80

def [](args)
  if(args.is_a?(Range))
    args.map{|date| day(date)}
  else
    day(args)
  end
end

#day(*args, vespers: false) ⇒ Object

accepts date information represented as Date, DateTime, or two to three integers (month - day or year - month - day); returns filled Day for the specified day



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/calendarium-romanum/calendar.rb', line 92

def day(*args, vespers: false)
  if args.size == 2
    date = Date.new(@year, *args)
    unless @temporale.date_range.include? date
      date = Date.new(@year + 1, *args)
    end
  else
    date = self.class.mk_date(*args)
    range_check date
  end

  if date < EFFECTIVE_FROM
    raise system_not_effective
  end

  celebrations = celebrations_for(date)
  vespers_celebration = nil
  if @populate_vespers || vespers
    begin
      vespers_celebration = first_vespers_on(date, celebrations)
    rescue RangeError
      # there is exactly one possible case when
      # range_check(date) passes and range_check(date + 1) fails:
      vespers_celebration = Temporale::CelebrationFactory.first_advent_sunday
    end
  end

  s = @temporale.season(date)
  Day.new(
    date: date,
    season: s,
    season_week: @temporale.season_week(s, date),
    celebrations: celebrations,
    vespers: vespers_celebration
  )
end

#eachObject



129
130
131
132
# File 'lib/calendarium-romanum/calendar.rb', line 129

def each
  (temporale.start_date..temporale.end_date)
    .each { |date| yield(day(date)) }
end

#ferial_lectionaryObject

Ferial lectionary cycle



140
141
142
# File 'lib/calendarium-romanum/calendar.rb', line 140

def ferial_lectionary
  @year % 2 + 1
end

#freezeObject



144
145
146
147
148
# File 'lib/calendarium-romanum/calendar.rb', line 144

def freeze
  @temporale.freeze
  @sanctorale.freeze
  super
end

#lectionaryObject

Sunday lectionary cycle



135
136
137
# File 'lib/calendarium-romanum/calendar.rb', line 135

def lectionary
  LECTIONARY_CYCLES[@year % 3]
end

#populates_vespers?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/calendarium-romanum/calendar.rb', line 66

def populates_vespers?
  @populate_vespers
end