Class: Dry::Data::Type::Enum

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/data/type/enum.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/dry/data/type/enum.rb', line 6

def type
  @type
end

#valuesObject (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

#primitiveObject



14
15
16
# File 'lib/dry/data/type/enum.rb', line 14

def primitive
  type.primitive
end