Class: Toys::ToolNameSplitter
- Inherits:
-
Object
- Object
- Toys::ToolNameSplitter
- 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
-
#extra_delimiters ⇒ String
readonly
The extra delimiters this splitter was created with, as given.
Instance Method Summary collapse
-
#initialize(extra_delimiters = "") ⇒ ToolNameSplitter
constructor
Create a splitter.
-
#inspect ⇒ String
A description of this splitter's delimiters.
-
#split(name) ⇒ Array<String>
Splits the given tool name into words.
-
#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.
Constructor Details
#initialize(extra_delimiters = "") ⇒ ToolNameSplitter
Create a splitter.
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.
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.
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.
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.
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 |