Sha256: 5c0c0dfd10507c7e6baf5d23c121f0f7a4787dc52cbb4bb4bd7bf3431d7164e3

Contents?: true

Size: 688 Bytes

Versions: 3

Compression:

Stored size: 688 Bytes

Contents

require 'command_mapper/types/map'

module CommandMapper
  module Types
    class Enum < Map

      # @return [Array<Object>]
      attr_reader :values

      #
      # Initializes the enum type.
      #
      # @param [Array<Object>] values
      #   The values of the enum type.
      #
      def initialize(values)
        @values = values

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

      #
      # Creates a new enum.
      #
      # @param [Array<Object>] values
      #   List of enum values.
      #
      # @return [Enum]
      #   The newly created enum object.
      #
      def self.[](*values)
        new(values)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
command_mapper-0.2.0 lib/command_mapper/types/enum.rb
command_mapper-0.1.2 lib/command_mapper/types/enum.rb
command_mapper-0.1.1 lib/command_mapper/types/enum.rb