Class: Tomo::Error::Suggestions
- Inherits:
-
Object
- Object
- Tomo::Error::Suggestions
- Defined in:
- lib/tomo/error/suggestions.rb
Instance Method Summary collapse
- #any? ⇒ Boolean
-
#initialize(dictionary:, word:) ⇒ Suggestions
constructor
A new instance of Suggestions.
- #to_a ⇒ Object
- #to_console ⇒ Object
Constructor Details
#initialize(dictionary:, word:) ⇒ Suggestions
Returns a new instance of Suggestions.
6 7 8 9 |
# File 'lib/tomo/error/suggestions.rb', line 6 def initialize(dictionary:, word:) @dictionary = dictionary @word = word end |
Instance Method Details
#any? ⇒ Boolean
11 12 13 |
# File 'lib/tomo/error/suggestions.rb', line 11 def any? to_a.any? end |
#to_a ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/tomo/error/suggestions.rb', line 15 def to_a @_suggestions ||= if defined?(DidYouMean::SpellChecker) checker = DidYouMean::SpellChecker.new(dictionary:) suggestions = checker.correct(word) suggestions || [] else [] end end |
#to_console ⇒ Object
25 26 27 28 29 30 |
# File 'lib/tomo/error/suggestions.rb', line 25 def to_console return unless any? sentence = to_sentence(to_a.map { |word| Colors.blue(word) }) "\nDid you mean #{sentence}?\n" end |