Class: Glossarist::Utilities::Enum::EnumCollection
- Inherits:
-
Object
- Object
- Glossarist::Utilities::Enum::EnumCollection
- Includes:
- Enumerable
- Defined in:
- lib/glossarist/utilities/enum/enum_collection.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add(name, values, options = {}) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ EnumCollection
constructor
A new instance of EnumCollection.
- #registered_enums ⇒ Object
- #type_options(name) ⇒ Object
- #valid_types(name) ⇒ Object
Constructor Details
#initialize ⇒ EnumCollection
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, = {}) @collection[name] = { registered_values: values, 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_enums ⇒ Object
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 (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 |