Class: Glossarist::Utilities::Enum::EnumCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/glossarist/utilities/enum/enum_collection.rb

Instance Method Summary collapse

Constructor Details

#initializeEnumCollection

Returns a new instance of EnumCollection.



9
10
11
# File 'lib/glossarist/utilities/enum/enum_collection.rb', line 9

def initialize
  @collection = {}
end

Instance Method Details

#[](name) ⇒ Object



39
40
41
# File 'lib/glossarist/utilities/enum/enum_collection.rb', line 39

def [](name)
  @collection[name]
end

#add(name, values, options = {}) ⇒ Object



13
14
15
# File 'lib/glossarist/utilities/enum/enum_collection.rb', line 13

def add(name, values, options = {})
  @collection[name] = { registered_values: values, options: options }
end

#each(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/glossarist/utilities/enum/enum_collection.rb', line 17

def each(&block)
  if block_given?
    @collection.each do |object|
      block.call(object)
    end
  else
    enum_for(:each)
  end
end

#registered_enumsObject



27
28
29
# File 'lib/glossarist/utilities/enum/enum_collection.rb', line 27

def registered_enums
  @collection&.keys || []
end

#type_options(name) ⇒ Object



35
36
37
# File 'lib/glossarist/utilities/enum/enum_collection.rb', line 35

def type_options(name)
  @collection[name][:options]
end

#valid_types(name) ⇒ Object



31
32
33
# File 'lib/glossarist/utilities/enum/enum_collection.rb', line 31

def valid_types(name)
  @collection[name][:registered_values]
end