Class: TTY::Shell::Suggestion
- Inherits:
-
Object
- Object
- TTY::Shell::Suggestion
- Defined in:
- lib/tty/shell/suggestion.rb
Overview
A class representing a suggestion
Constant Summary collapse
- DEFAULT_INDENT =
8
- SINGLE_TEXT =
'Did you mean this?'
- PLURAL_TEXT =
'Did you mean one of these?'
Instance Attribute Summary collapse
-
#indent ⇒ Object
readonly
Number of spaces.
-
#plural_text ⇒ Object
readonly
Text for multiple suggestions.
-
#single_text ⇒ Object
readonly
Text for a single suggestion.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Suggestion
constructor
Initialize a Suggestion.
-
#suggest(message, possibilities) ⇒ Object
Suggest matches out of possibile strings.
Constructor Details
#initialize(options = {}) ⇒ Suggestion
Initialize a Suggestion
32 33 34 35 36 37 38 |
# File 'lib/tty/shell/suggestion.rb', line 32 def initialize( = {}) @indent = .fetch(:indent) { DEFAULT_INDENT } @single_text = .fetch(:single_text) { SINGLE_TEXT } @plural_text = .fetch(:plural_text) { PLURAL_TEXT } @suggestions = [] @comparator = Distance.new end |
Instance Attribute Details
#indent ⇒ Object (readonly)
Number of spaces
17 18 19 |
# File 'lib/tty/shell/suggestion.rb', line 17 def indent @indent end |
#plural_text ⇒ Object (readonly)
Text for multiple suggestions
27 28 29 |
# File 'lib/tty/shell/suggestion.rb', line 27 def plural_text @plural_text end |
#single_text ⇒ Object (readonly)
Text for a single suggestion
22 23 24 |
# File 'lib/tty/shell/suggestion.rb', line 22 def single_text @single_text end |
Instance Method Details
#suggest(message, possibilities) ⇒ Object
Suggest matches out of possibile strings
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tty/shell/suggestion.rb', line 47 def suggest(, possibilities) distances = measure_distances(, possibilities) minimum_distance = distances.keys.min max_distance = distances.keys.max if minimum_distance < max_distance @suggestions = distances[minimum_distance].sort end evaluate end |