Class: Toys::Completion::Candidate
- Inherits:
-
Object
- Object
- Toys::Completion::Candidate
- Includes:
- Comparable
- Defined in:
- toys-core/lib/toys/completion.rb
Overview
Defined in the toys-core gem
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.
Instance Attribute Summary collapse
-
#string ⇒ String
(also: #to_s)
readonly
Get the candidate string.
Class Method Summary collapse
-
.new_multi(array, partial: false) ⇒ Array<Toys::Completion::Candidate]
Create an array of candidates given an array of strings.
Instance Method Summary collapse
-
#final? ⇒ Boolean
Determine whether the candidate is a final completion.
-
#initialize(string, partial: false) ⇒ Candidate
constructor
Create a new candidate.
-
#partial? ⇒ Boolean
Determine whether the candidate is partial completion.
Constructor Details
#initialize(string, partial: false) ⇒ Candidate
Create a new candidate
156 157 158 159 |
# File 'toys-core/lib/toys/completion.rb', line 156 def initialize(string, partial: false) @string = string.to_s @partial = partial ? true : false end |
Instance Attribute Details
#string ⇒ String (readonly) Also known as: to_s
Get the candidate string.
165 166 167 |
# File 'toys-core/lib/toys/completion.rb', line 165 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.
205 206 207 |
# File 'toys-core/lib/toys/completion.rb', line 205 def self.new_multi(array, partial: false) array.map { |s| new(s, partial: partial) } end |
Instance Method Details
#final? ⇒ Boolean
Determine whether the candidate is a final completion.
180 181 182 |
# File 'toys-core/lib/toys/completion.rb', line 180 def final? !@partial end |
#partial? ⇒ Boolean
Determine whether the candidate is partial completion.
172 173 174 |
# File 'toys-core/lib/toys/completion.rb', line 172 def partial? @partial end |