class Toys::Completion::Candidate
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.
Attributes
Get the candidate string. @return [String]
Get the candidate string. @return [String]
Public Class Methods
Create a new candidate @param string [String] The candidate string @param partial [Boolean] Whether the candidate is partial. Defaults
to `false`.
# File lib/toys/completion.rb, line 150 def initialize(string, partial: false) @string = string.to_s @partial = partial ? true : false end
Create an array of candidates given an array of strings.
@param array [Array<String>] @return [Array<Toys::Completion::Candidate]
# File lib/toys/completion.rb, line 199 def self.new_multi(array, partial: false) array.map { |s| new(s, partial: partial) } end
Public Instance Methods
@private
# File lib/toys/completion.rb, line 184 def <=>(other) string <=> other.string end
@private
# File lib/toys/completion.rb, line 179 def eql?(other) other.is_a?(Candidate) && other.string.eql?(string) && other.partial? == @partial end
Determine whether the candidate is a final completion. @return [Boolean]
# File lib/toys/completion.rb, line 174 def final? !@partial end
@private
# File lib/toys/completion.rb, line 189 def hash string.hash ^ (partial? ? 1 : 0) end
Determine whether the candidate is partial completion. @return [Boolean]
# File lib/toys/completion.rb, line 166 def partial? @partial end