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, OptSmartList

Instance Attribute Summary

Attributes inherited from OptBase

#attrs, #option, #required

Instance Method Summary collapse

Methods inherited from OptBase

#advanced?, #alias?, #choices, #default, #help_message_for_default, #help_messages, #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

#append_help_messagesVoid

Returns:

  • (Void)


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

def append_help_messages
  option << "Separator to use between the values: '#{separator}'"

  super
end

#normalize(values) ⇒ Object

See OptBase#normalize

Parameters:

  • values (Array)


27
28
29
30
31
32
# File 'lib/opt_parse_validator/opts/array.rb', line 27

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



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

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

#validate(value) ⇒ Array

Parameters:

  • value (String)

Returns:

  • (Array)


16
17
18
# File 'lib/opt_parse_validator/opts/array.rb', line 16

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