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)


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

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

  super
end

#normalize(values) ⇒ Object

See OptBase#normalize

Parameters:

  • values (Array)


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

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



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

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

#validate(value) ⇒ Array

Parameters:

  • value (String)

Returns:

  • (Array)


14
15
16
# File 'lib/opt_parse_validator/opts/array.rb', line 14

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