Class: OptParseValidator::OptArray

Inherits:
OptBase
  • Object
show all
Defined in:
lib/opt_parse_validator/opts/array.rb

Overview

Implementation of the Array Option

Direct Known Subclasses

OptMultiChoices

Instance Attribute Summary

Attributes inherited from OptBase

#attrs, #option, #required

Instance Method Summary collapse

Methods inherited from OptBase

#choices, #default, #initialize, #required?, #required_unless, #to_long, #to_s, #to_sym, #value_if_empty

Constructor Details

This class inherits a constructor from OptParseValidator::OptBase

Instance Method Details

#normalize(values) ⇒ Object

See OptBase#normalize

Parameters:

  • values (Array)


18
19
20
21
22
23
# File 'lib/opt_parse_validator/opts/array.rb', line 18

def normalize(values)
  values.each_with_index do |value, index|
    values[index] = super(value)
  end
  values
end

#separatorString

Returns The separator used to split the string into an array.

Returns:

  • (String)

    The separator used to split the string into an array



12
13
14
# File 'lib/opt_parse_validator/opts/array.rb', line 12

def separator
  attrs[:separator] || ','
end

#validate(value) ⇒ Array

Parameters:

  • value (String)

Returns:

  • (Array)


7
8
9
# File 'lib/opt_parse_validator/opts/array.rb', line 7

def validate(value)
  super(value).split(separator)
end