Class: CommandMapper::Types::Enum

Inherits:
Map
  • Object
show all
Defined in:
lib/command_mapper/types/enum.rb

Overview

Represents a mapping of Ruby values to their String equivalents.

Constant Summary

Constants inherited from Map

Map::EnabledDisabled, Map::YesNo

Instance Attribute Summary collapse

Attributes inherited from Map

#map

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Map

#format, #validate

Methods inherited from Type

#format, #validate

Constructor Details

#initialize(values) ⇒ Enum

Initializes the enum type.

Parameters:

  • values (Array<Object>)

    The values of the enum type.



24
25
26
27
28
# File 'lib/command_mapper/types/enum.rb', line 24

def initialize(values)
  @values = values

  super(Hash[values.map { |value| [value, value.to_s] }])
end

Instance Attribute Details

#valuesArray<Object> (readonly)

The values of the enum.

Returns:

  • (Array<Object>)


16
17
18
# File 'lib/command_mapper/types/enum.rb', line 16

def values
  @values
end

Class Method Details

.[](*values) ⇒ Enum

Creates a new enum.

Parameters:

  • values (Array<Object>)

    List of enum values.

Returns:

  • (Enum)

    The newly created enum object.



39
40
41
# File 'lib/command_mapper/types/enum.rb', line 39

def self.[](*values)
  new(values)
end