Class: CalendariumRomanum::Celebration

Inherits:
Object
  • Object
show all
Includes:
RankPredicates
Defined in:
lib/calendarium-romanum/day.rb

Overview

One particular celebration of the liturgical year (like a Sunday, feast or memorial); some days have one, some have more among which one is to be chosen

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RankPredicates

#feast?, #ferial?, #memorial?, #obligatory_memorial?, #optional_memorial?, #solemnity?

Constructor Details

#initialize(title = '', rank = Ranks::FERIAL, colour = Colours::GREEN, symbol = nil, date = nil, cycle = :sanctorale, sunday = false, **kwargs) ⇒ Celebration

All arguments can be passed either as positional or keyword arguments. In case of conflict keyword arguments win.

Examples:

Celebration.new('Lost title', title: 'Winning title') # will have title 'Winning title'

Parameters:

  • title (String|Proc) (defaults to: '')

    Celebration title/name. If a Proc is passed, it is expected not to receive arguments and to return a String. (Used for celebration titles which have to be internationalizable - the Proc is called whenever #title is invoked, which allows the value to vary depending e.g. on state of the Proc or some global setting - like I18n.locale - it may access.)

  • rank (Rank) (defaults to: Ranks::FERIAL)

    Celebration rank

  • colour (Colour) (defaults to: Colours::GREEN)

    Liturgical colour

  • symbol (Symbol, nil) (defaults to: nil)

    Unique machine-readable identifier of the celebration

  • date (AbstractDate, nil) (defaults to: nil)

    Normal fixed date of the celebration

  • cycle (:sanctorale, :temporale) (defaults to: :sanctorale)

    Cycle the celebration belongs to



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/calendarium-romanum/day.rb', line 129

def initialize(title = '', rank = Ranks::FERIAL, colour = Colours::GREEN, symbol = nil, date = nil, cycle = :sanctorale, sunday = false, **kwargs)
  @title = kwargs.delete(:title) || title
  @rank = kwargs.delete(:rank) || rank
  @colour = kwargs.delete(:colour) || kwargs.delete(:color) || colour
  @symbol = kwargs.delete(:symbol) || symbol
  @date = kwargs.delete(:date) || date
  @cycle = kwargs.delete(:cycle) || cycle
  @sunday = kwargs.delete(:sunday) || sunday

  unless kwargs.empty?
    raise ArgumentError.new('Unexpected keyword arguments: ' + kwargs.keys.inspect)
  end

  if @sunday && ![Ranks::SUNDAY_UNPRIVILEGED, Ranks::PRIMARY].include?(@rank)
    raise ArgumentError.new("Rank #{@rank} cannot be Sunday")
  end
end

Instance Attribute Details

#colourColour (readonly) Also known as: color

Liturgical colour

Returns:



181
182
183
# File 'lib/calendarium-romanum/day.rb', line 181

def colour
  @colour
end

#cycle:sanctorale, :temporale (readonly)

Describes the celebration as belonging either to the temporale or sanctorale cycle

Returns:

  • (:sanctorale, :temporale)

Since:

  • 0.6.0



206
207
208
# File 'lib/calendarium-romanum/day.rb', line 206

def cycle
  @cycle
end

#dateAbstractDate? (readonly)

Usual date of the celebration.

Only set for celebrations with fixed date. (Only) In case of solemnities it may happen that #date differs from Day#date due to transfer of an impeded solemnity.

Returns:

Since:

  • 0.6.0



199
200
201
# File 'lib/calendarium-romanum/day.rb', line 199

def date
  @date
end

#rankRank (readonly)

Returns:



165
166
167
# File 'lib/calendarium-romanum/day.rb', line 165

def rank
  @rank
end

#symbolSymbol? (readonly)

Symbol uniquely identifying the celebration

Returns:

  • (Symbol, nil)

Since:

  • 0.5.0



188
189
190
# File 'lib/calendarium-romanum/day.rb', line 188

def symbol
  @symbol
end

Instance Method Details

#==(b) ⇒ Object



208
209
210
211
212
213
214
215
216
# File 'lib/calendarium-romanum/day.rb', line 208

def ==(b)
  self.class == b.class &&
    title == b.title &&
    rank == b.rank &&
    colour == b.colour &&
    symbol == b.symbol &&
    date == b.date &&
    cycle == b.cycle
end

#change(title: nil, rank: nil, colour: nil, color: nil, symbol: nil, date: nil, cycle: nil, sunday: nil) ⇒ Celebration

Build a new instance using the receiver’s attributes for all properties for which (a non-nil) value was not passed.

Returns:

Since:

  • 0.5.0



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/calendarium-romanum/day.rb', line 152

def change(title: nil, rank: nil, colour: nil, color: nil, symbol: nil, date: nil, cycle: nil, sunday: nil)
  self.class.new(
    title: title || self.title,
    rank: rank || self.rank,
    colour: colour || color || self.colour,
    symbol: symbol || self.symbol,
    date: date || self.date,
    cycle: cycle || self.cycle,
    sunday: sunday || @sunday
  )
end

#sanctorale?Boolean

Does the celebration belong to the sanctorale cycle?

Returns:

  • (Boolean)

Since:

  • 0.6.0



230
231
232
# File 'lib/calendarium-romanum/day.rb', line 230

def sanctorale?
  cycle == :sanctorale
end

#sunday?Boolean

Is the celebration a Sunday?

Please note that for “privileged Sundays” true is returned, while RankPredicates#sunday? returns false (because not all celebrations of that rank are Sundays).

Returns:

  • (Boolean)


240
241
242
# File 'lib/calendarium-romanum/day.rb', line 240

def sunday?
  rank.sunday? || @sunday
end

#temporale?Boolean

Does the celebration belong to the temporale cycle?

Returns:

  • (Boolean)

Since:

  • 0.6.0



222
223
224
# File 'lib/calendarium-romanum/day.rb', line 222

def temporale?
  cycle == :temporale
end

#titleString

Feast title/name

Returns:

  • (String)


170
171
172
173
174
175
176
# File 'lib/calendarium-romanum/day.rb', line 170

def title
  if @title.respond_to? :call
    @title.call
  else
    @title
  end
end

#to_sString

String representation of the object’s contents (not very pretty, intended mostly for development inspections).

Returns:

  • (String)

Since:

  • 0.7.0



249
250
251
# File 'lib/calendarium-romanum/day.rb', line 249

def to_s
  "#<#{self.class.name} @title=\"#{title}\" @rank=#{rank} @colour=#{colour} symbol=#{symbol.inspect} date=#{date.inspect} cycle=#{cycle.inspect}>"
end