Sha256: ef235397c708d2b4272104b5474d8c0845bc6cf2c5e2ee0937cec8b2c1144153

Contents?: true

Size: 899 Bytes

Versions: 3

Compression:

Stored size: 899 Bytes

Contents

require 'command_mapper/arg'

module CommandMapper
  #
  # Represents the value for an option.
  #
  class OptionValue < Arg

    #
    # Validates whether a given value is compatible with the option {#type}.
    #
    # @param [Object] value
    #   The given value to validate.
    #
    # @return [true, (false, String)]
    #   Returns true if the value is valid, or `false` and a validation error
    #   message if the value is not compatible.
    #
    # @api semipublic
    #
    def validate(value)
      if !required? && value == true
        return true
      else
        super(value)
      end
    end

    #
    # Formats a value using the options {#type}.
    #
    # @param [Object] value
    #   The given value to format.
    #
    # @return [String]
    #   The formatted value.
    #
    # @api semipublic
    #
    def format(value)
      @type.format(value)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
command_mapper-0.3.1 lib/command_mapper/option_value.rb
command_mapper-0.3.0 lib/command_mapper/option_value.rb
command_mapper-0.2.1 lib/command_mapper/option_value.rb