Sha256: 8eeef6f963698e3bffc7635437439dbf2c6778e8a48bc75e21e43b3ce790bef5

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'movingsign_api/commands/internal/pretty_keyable'

module MovingsignApi
  # Align mode for a sign.
  #
  # Valid values are:
  # * +:left+ or +'1'+
  # * +:center+ or +'2'+
  # * +:right+ or +'3+
  class AlignMode
    include PrettyKeyable

    # @return [Symbol] align mode (one of {#left}, {#right}, {#center})
    attr_accessor :key

    protected

    # Registers a specific align mode key and value combo
    def self.align_mode(key, code)
      register key, code
    end

    public

    # @!group Align Mode Constants
    # @!macro [attach] dm.align_mode
    #   @!attribute [r] $1
    #   Align mode +:$1+ (protocol align mode +'$2'+)
    #   @return [Symbol] +:$1+
    align_mode :left, '1'
    align_mode :right, '3'
    align_mode :center, '2'
    # @!endgroup

    # @param key [Symbol] one of the valid alignment keys
    def initialize(key)
      @key = key
    end

    # Parses an symbol or string into a valid {AlignMode} instance
    # @return [AlignMode]
    def self.parse(input)
      if key = parse_to_key(input)
        self.new key
      else
        raise InvalidInputError, "Align mode '#{input}' is invalid."
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
movingsign_api-0.0.2 lib/movingsign_api/commands/internal/align_mode.rb
movingsign_api-0.0.1 lib/movingsign_api/commands/internal/align_mode.rb