Class: Toys::Completion::Enum
Overview
A Completion whose candidates come from a static list of strings.
Instance Attribute Summary collapse
-
#prefix_constraint ⇒ String, Regexp
readonly
Constraint on the fragment prefix.
-
#values ⇒ Array<String>
readonly
The array of completion candidates.
Instance Method Summary collapse
-
#call(context) ⇒ Array<Toys::Completion::Candidate>
Returns candidates for the current completion.
-
#initialize(values, prefix_constraint: "") ⇒ Enum
constructor
Create a completion from a list of values.
Constructor Details
Instance Attribute Details
#prefix_constraint ⇒ String, Regexp (readonly)
Constraint on the fragment prefix.
366 367 368 |
# File 'lib/toys/completion.rb', line 366 def prefix_constraint @prefix_constraint end |
#values ⇒ Array<String> (readonly)
The array of completion candidates.
360 361 362 |
# File 'lib/toys/completion.rb', line 360 def values @values end |
Instance Method Details
#call(context) ⇒ Array<Toys::Completion::Candidate>
Returns candidates for the current completion.
375 376 377 378 379 |
# File 'lib/toys/completion.rb', line 375 def call(context) return [] unless @prefix_constraint === context.fragment_prefix fragment = context.fragment @values.find_all { |val| val.string.start_with?(fragment) } end |