Class: Enumattr::Enums
- Inherits:
-
Object
- Object
- Enumattr::Enums
- Defined in:
- lib/enumattr/enums.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#enumattr ⇒ Object
readonly
Returns the value of attribute enumattr.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #enum_by_key(key) ⇒ Object
- #enum_by_value(value) ⇒ Object
- #enums ⇒ Object
-
#initialize(enumattr, base, opts = {}, &block) ⇒ Enums
constructor
A new instance of Enums.
- #keys ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(enumattr, base, opts = {}, &block) ⇒ Enums
Returns a new instance of Enums.
7 8 9 10 11 12 13 |
# File 'lib/enumattr/enums.rb', line 7 def initialize(enumattr, base, opts = {}, &block) @enumattr = enumattr @base = base @opts = opts.freeze @enums = build_enums(&block) decorate @enums end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
5 6 7 |
# File 'lib/enumattr/enums.rb', line 5 def base @base end |
#enumattr ⇒ Object (readonly)
Returns the value of attribute enumattr.
5 6 7 |
# File 'lib/enumattr/enums.rb', line 5 def enumattr @enumattr end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
5 6 7 |
# File 'lib/enumattr/enums.rb', line 5 def opts @opts end |
Instance Method Details
#enum_by_key(key) ⇒ Object
27 28 29 |
# File 'lib/enumattr/enums.rb', line 27 def enum_by_key(key) @enums.find{|enum| enum.key == key } end |
#enum_by_value(value) ⇒ Object
31 32 33 |
# File 'lib/enumattr/enums.rb', line 31 def enum_by_value(value) @enums.find{|enum| enum.value == value } end |
#enums ⇒ Object
15 16 17 |
# File 'lib/enumattr/enums.rb', line 15 def enums @enums.clone end |
#keys ⇒ Object
19 20 21 |
# File 'lib/enumattr/enums.rb', line 19 def keys @enums.map(&:key) end |
#values ⇒ Object
23 24 25 |
# File 'lib/enumattr/enums.rb', line 23 def values @enums.map(&:value) end |