Class: Dry::Data::Type::Enum
- Inherits:
-
Object
- Object
- Dry::Data::Type::Enum
- Defined in:
- lib/dry/data/type/enum.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #call(input) ⇒ Object (also: #[])
-
#initialize(values, type) ⇒ Enum
constructor
A new instance of Enum.
- #primitive ⇒ Object
Constructor Details
#initialize(values, type) ⇒ Enum
Returns a new instance of Enum.
8 9 10 11 12 |
# File 'lib/dry/data/type/enum.rb', line 8 def initialize(values, type) @values = values.freeze @type = type values.each(&:freeze) end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/dry/data/type/enum.rb', line 6 def type @type end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
5 6 7 |
# File 'lib/dry/data/type/enum.rb', line 5 def values @values end |
Instance Method Details
#call(input) ⇒ Object Also known as: []
18 19 20 21 22 |
# File 'lib/dry/data/type/enum.rb', line 18 def call(input) case input when Fixnum then type[values[input]] else type[input] end end |
#primitive ⇒ Object
14 15 16 |
# File 'lib/dry/data/type/enum.rb', line 14 def primitive type.primitive end |