Class: Toys::Completion::Candidate

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
core-docs/toys/completion.rb

Overview

A candidate for completing a string fragment.

A candidate includes a string representing the potential completed word, as well as a flag indicating whether it is a partial completion (i.e. a prefix that could still be added to) versus a final word. Generally, tab completion systems should add a trailing space after a final completion but not after a partial completion.

Defined in the toys-core gem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, partial: false) ⇒ Candidate

Create a new candidate

Parameters:

  • string (String)

    The candidate string

  • partial (boolean) (defaults to: false)

    Whether the candidate is partial. Defaults to false.



136
137
138
# File 'core-docs/toys/completion.rb', line 136

def initialize(string, partial: false)
  # Source available in the toys-core gem
end

Instance Attribute Details

#stringString (readonly) Also known as: to_s

Get the candidate string.

Returns:

  • (String)


144
145
146
# File 'core-docs/toys/completion.rb', line 144

def string
  @string
end

Class Method Details

.new_multi(array, partial: false) ⇒ Array<Toys::Completion::Candidate>

Create an array of candidates given an array of strings.

Parameters:

  • array (Array<String>)

Returns:



182
183
184
# File 'core-docs/toys/completion.rb', line 182

def self.new_multi(array, partial: false)
  # Source available in the toys-core gem
end

Instance Method Details

#final?boolean

Determine whether the candidate is a final completion.

Returns:

  • (boolean)


159
160
161
# File 'core-docs/toys/completion.rb', line 159

def final?
  # Source available in the toys-core gem
end

#partial?boolean

Determine whether the candidate is partial completion.

Returns:

  • (boolean)


151
152
153
# File 'core-docs/toys/completion.rb', line 151

def partial?
  # Source available in the toys-core gem
end

#with_prefix(prefix) ⇒ Toys::Completion::Candidate

Returns a copy of this candidate with the given string prepended. Use this when a completion handles only the tail of the word being completed, and must restore the head to each candidate so that the candidate remains a replacement for the whole word.

Parameters:

  • prefix (String)

    The string to prepend

Returns:



172
173
174
# File 'core-docs/toys/completion.rb', line 172

def with_prefix(prefix)
  # Source available in the toys-core gem
end