Class: CalendariumRomanum::Enum Abstract

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

Overview

This class is abstract.

Each subclass encapsulates a finite set of value objects.

Direct Known Subclasses

Colours, Data, Ranks, Seasons

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.allArray (readonly)

Returns all contained value objects

Returns:

  • (Array)


34
35
36
# File 'lib/calendarium-romanum/enum.rb', line 34

def all
  @all
end

Class Method Details

.[](identifier) ⇒ Object

Returns value object or nil.

Parameters:

  • identifier

Returns:

  • value object or nil



49
# File 'lib/calendarium-romanum/enum.rb', line 49

def_delegators :@indexed, :[]

.each { ... } ⇒ void

This method returns an undefined value.

Yields:

  • value object



41
# File 'lib/calendarium-romanum/enum.rb', line 41

def_delegators :@all, :each

.values(index_by: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • index_by (defaults to: nil)

    specifies which value objects’ property contains unique internal identifier for use with []



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/calendarium-romanum/enum.rb', line 15

def values(index_by: nil)
  defined?(@indexed) && raise(RuntimeError.new('initialized repeatedly'))

  @indexed = {}
  @all = yield.freeze

  @all.each_with_index do |val, i|
    val.freeze

    key = index_by ? val.public_send(index_by) : i
    @indexed[key] = val
  end

  @indexed.freeze
end