Class: Toys::ToolNameSplitter

Inherits:
Object
  • Object
show all
Defined in:
core-docs/toys/tool_name_splitter.rb

Overview

Splits tool names into words, according to a set of delimiter characters.

A tool name is a series of words. On the command line, and in various places in the DSL, a name can be written as a single string with its words separated by delimiters. Whitespace is always a delimiter; additional characters can be configured when a splitter is created.

A splitter is immutable, and can be shared by any number of objects that need to interpret tool names the same way.

Defined in the toys-core gem

Constant Summary collapse

DEFAULT =

A splitter that recognizes only whitespace as a delimiter. This is the splitter used when no other is configured.

new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extra_delimiters = "") ⇒ ToolNameSplitter

Create a splitter.

Parameters:

  • extra_delimiters (String) (defaults to: "") —

    A string containing characters that can function as delimiters in a tool name, in addition to whitespace. Defaults to empty. Allowed characters are period, colon, and slash.



23
24
25
# File 'core-docs/toys/tool_name_splitter.rb', line 23

def initialize(extra_delimiters = "")
  # Source available in the toys-core gem
end

Instance Attribute Details

#extra_delimiters ⇒ String (readonly)

The extra delimiters this splitter was created with, as given. Whitespace is a delimiter whether or not it appears here.

Returns:

  • (String)


33
34
35
# File 'core-docs/toys/tool_name_splitter.rb', line 33

def extra_delimiters
  @extra_delimiters
end

Instance Method Details

#inspect ⇒ String

Returns a description of this splitter's delimiters.

Returns:

  • (String) —

    a description of this splitter's delimiters



70
71
72
# File 'core-docs/toys/tool_name_splitter.rb', line 70

def inspect
  # Source available in the toys-core gem
end

#split(name) ⇒ Array<String>

Splits the given tool name into words. You may pass either an array, whose elements are copied as strings without being split further, or a single string or symbol possibly delimited by this splitter's delimiters. Always returns a new array of strings.

Parameters:

  • name (String, Symbol, Array<String,Symbol>) —

    The name to split.

Returns:

  • (Array<String>)


44
45
46
# File 'core-docs/toys/tool_name_splitter.rb', line 44

def split(name)
  # Source available in the toys-core gem
end

#split_partial(str) ⇒ Array(String,String)

Splits a partially typed name, such as a fragment being completed, into the portion that names a path and the trailing partial word.

Returns a two-element array. The first element is the leading portion of the string through its final delimiter, or the empty string if there is none; pass it to #split to get the path words. The second element is the text following that delimiter.

A delimiter is recognized as a separator only if at least one character precedes it, so a string that begins with a delimiter is not split.

Parameters:

  • str (String) —

    The partial name to split.

Returns:

  • (Array(String,String))


63
64
65
# File 'core-docs/toys/tool_name_splitter.rb', line 63

def split_partial(str)
  # Source available in the toys-core gem
end