Class: Shellissimo::CommandParam

Inherits:
Object
  • Object
show all
Defined in:
lib/shellissimo/command_param.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, validator = nil, description = "") ⇒ CommandParam

Returns a new instance of CommandParam.

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/shellissimo/command_param.rb', line 8

def initialize(name, validator = nil, description = "")
  @name, @description = String(name), String(description)
  raise ArgumentError, "command param name can't be blank" if @name.empty?
  @validator = validator || CommandParamValidator.noop
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/shellissimo/command_param.rb', line 6

def description
  @description
end

#validatorObject (readonly)

Returns the value of attribute validator.



6
7
8
# File 'lib/shellissimo/command_param.rb', line 6

def validator
  @validator
end

Instance Method Details

#nameObject



14
15
16
# File 'lib/shellissimo/command_param.rb', line 14

def name
  @name.to_sym
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/shellissimo/command_param.rb', line 18

def valid?(value)
  !!@validator[value]
end