Class: ShellOpts::Grammar::EnumArgument

Inherits:
ArgumentType show all
Defined in:
lib/shellopts/argument_type.rb

Instance Attribute Summary collapse

Attributes inherited from ArgumentType

#message

Instance Method Summary collapse

Methods inherited from ArgumentType

#convert, #name, #to_s

Constructor Details

#initialize(values) ⇒ EnumArgument

Returns a new instance of EnumArgument.



185
# File 'lib/shellopts/argument_type.rb', line 185

def initialize(values) @values = values.dup end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



184
185
186
# File 'lib/shellopts/argument_type.rb', line 184

def values
  @values
end

Instance Method Details

#match?(name, literal) ⇒ Boolean

Returns:

  • (Boolean)


186
# File 'lib/shellopts/argument_type.rb', line 186

def match?(name, literal) value?(literal) or set_message "Illegal value in #{name}: '#{literal}'" end

#value?(value) ⇒ Boolean

Returns:

  • (Boolean)


187
# File 'lib/shellopts/argument_type.rb', line 187

def value?(value) @values.include?(value) end