Module: CalendariumRomanum::Enum Private

Extended by:
Forwardable
Included in:
Colours, Data, Ranks, Seasons
Defined in:
lib/calendarium-romanum/enum.rb

Overview

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

Each Enum encapsulates a finite set of value objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allArray (readonly)

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.

Returns all contained value objects

Returns:

  • (Array)


31
32
33
# File 'lib/calendarium-romanum/enum.rb', line 31

def all
  @all
end

Instance Method Details

#[](identifier) ⇒ Object

Returns value object or nil.

Parameters:

  • identifier

Returns:

  • value object or nil



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

def_delegators :@indexed, :[]

#each { ... } ⇒ void

This method returns an undefined value.

Yields:

  • value object



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

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 #[]



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

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

  @all = yield.freeze
  @all.each &:freeze

  @indexed = {}
  @all.each_with_index do |val, i|
    key = index_by ? val.public_send(index_by) : i
    @indexed[key] = val
  end
  @indexed.freeze
end