Class: CommandMapper::OptionValue

Inherits:
Arg
  • Object
show all
Defined in:
lib/command_mapper/option_value.rb

Overview

Represents the value for an option.

Instance Attribute Summary

Attributes inherited from Arg

#type

Instance Method Summary collapse

Methods inherited from Arg

#initialize, #optional?, #required?

Constructor Details

This class inherits a constructor from CommandMapper::Arg

Instance Method Details

#format(value) ⇒ String

Formats a value using the options Arg#type.

Parameters:

  • value (Object)

    The given value to format.

Returns:

  • (String)

    The formatted value.



40
41
42
# File 'lib/command_mapper/option_value.rb', line 40

def format(value)
  @type.format(value)
end

#validate(value) ⇒ true, (false, String)

Validates whether a given value is compatible with the option Arg#type.

Parameters:

  • value (Object)

    The given value to validate.

Returns:

  • (true, (false, String))

    Returns true if the value is valid, or false and a validation error message if the value is not compatible.



21
22
23
24
25
26
27
# File 'lib/command_mapper/option_value.rb', line 21

def validate(value)
  if !required? && value == true
    return true
  else
    super(value)
  end
end