Class: Argstring::Config
- Inherits:
-
Object
- Object
- Argstring::Config
- Defined in:
- lib/argstring/config.rb
Constant Summary collapse
- DEFAULT_ENCLOSERS =
[{ open: '"', close: '"' }, { open: "'", close: "'" }].freeze
- WHITESPACE_SEPARATOR_SENTINEL =
/\s/
Instance Attribute Summary collapse
-
#assignment ⇒ Object
readonly
Returns the value of attribute assignment.
-
#duplicates ⇒ Object
readonly
Returns the value of attribute duplicates.
-
#enclosers ⇒ Object
readonly
Returns the value of attribute enclosers.
-
#escape ⇒ Object
readonly
Returns the value of attribute escape.
-
#flags_enabled ⇒ Object
readonly
Returns the value of attribute flags_enabled.
-
#positional_enabled ⇒ Object
readonly
Returns the value of attribute positional_enabled.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Instance Method Summary collapse
- #encloser_open_pair_for(ch) ⇒ Object
- #escape_enabled? ⇒ Boolean
-
#initialize(separator: WHITESPACE_SEPARATOR_SENTINEL, escape: "\\", assignment: ["="], enclosers: DEFAULT_ENCLOSERS, duplicates: :last, flags: true, positional: true) ⇒ Config
constructor
A new instance of Config.
- #separator_boundary_at?(string, index) ⇒ Boolean
- #whitespace_char?(ch) ⇒ Boolean
- #whitespace_separator? ⇒ Boolean
Constructor Details
#initialize(separator: WHITESPACE_SEPARATOR_SENTINEL, escape: "\\", assignment: ["="], enclosers: DEFAULT_ENCLOSERS, duplicates: :last, flags: true, positional: true) ⇒ Config
Returns a new instance of Config.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/argstring/config.rb', line 10 def initialize(separator: WHITESPACE_SEPARATOR_SENTINEL, escape: "\\", assignment: ["="], enclosers: DEFAULT_ENCLOSERS, duplicates: :last, flags: true, positional: true) @separator = separator @escape = escape @assignment = assignment @enclosers = enclosers @duplicates = duplicates @flags_enabled = flags @positional_enabled = positional validate! end |
Instance Attribute Details
#assignment ⇒ Object (readonly)
Returns the value of attribute assignment.
8 9 10 |
# File 'lib/argstring/config.rb', line 8 def assignment @assignment end |
#duplicates ⇒ Object (readonly)
Returns the value of attribute duplicates.
8 9 10 |
# File 'lib/argstring/config.rb', line 8 def duplicates @duplicates end |
#enclosers ⇒ Object (readonly)
Returns the value of attribute enclosers.
8 9 10 |
# File 'lib/argstring/config.rb', line 8 def enclosers @enclosers end |
#escape ⇒ Object (readonly)
Returns the value of attribute escape.
8 9 10 |
# File 'lib/argstring/config.rb', line 8 def escape @escape end |
#flags_enabled ⇒ Object (readonly)
Returns the value of attribute flags_enabled.
8 9 10 |
# File 'lib/argstring/config.rb', line 8 def flags_enabled @flags_enabled end |
#positional_enabled ⇒ Object (readonly)
Returns the value of attribute positional_enabled.
8 9 10 |
# File 'lib/argstring/config.rb', line 8 def positional_enabled @positional_enabled end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
8 9 10 |
# File 'lib/argstring/config.rb', line 8 def separator @separator end |
Instance Method Details
#encloser_open_pair_for(ch) ⇒ Object
34 35 36 |
# File 'lib/argstring/config.rb', line 34 def encloser_open_pair_for(ch) @enclosers.find { |pair| pair[:open] == ch } end |
#escape_enabled? ⇒ Boolean
26 27 28 |
# File 'lib/argstring/config.rb', line 26 def escape_enabled? @escape && @escape != "" end |
#separator_boundary_at?(string, index) ⇒ Boolean
38 39 40 41 42 |
# File 'lib/argstring/config.rb', line 38 def separator_boundary_at?(string, index) ch = string[index] return whitespace_char?(ch) if whitespace_separator? ch == @separator end |
#whitespace_char?(ch) ⇒ Boolean
30 31 32 |
# File 'lib/argstring/config.rb', line 30 def whitespace_char?(ch) !!(ch =~ /\s/) end |
#whitespace_separator? ⇒ Boolean
22 23 24 |
# File 'lib/argstring/config.rb', line 22 def whitespace_separator? @separator.is_a?(Regexp) && @separator == WHITESPACE_SEPARATOR_SENTINEL end |