Class: Eskimo::Components::DidYouMean
- Inherits:
-
Eskimo::Component
- Object
- Eskimo::Component
- Eskimo::Components::DidYouMean
- Defined in:
- lib/eskimo/components/did_you_mean.rb
Overview
Present the user with the closest possible correction, if any.
DidYouMean.new(dictionary: [ 'abc', 'bca' ], item: 'abd')
# => "hint: Did you mean? abc"
DidYouMean.new(dictionary: [ 'abc', 'bca' ], item: 'asdfasdf')
# => ""
See github.com/yuki24/did_you_mean#using-the-didyoumeanspellchecker
Instance Attribute Summary collapse
-
#corrections ⇒ Object
readonly
Returns the value of attribute corrections.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Instance Method Summary collapse
-
#initialize(dictionary:, item:, separator: " or ", &children) ⇒ DidYouMean
constructor
A new instance of DidYouMean.
- #render ⇒ Object
Constructor Details
#initialize(dictionary:, item:, separator: " or ", &children) ⇒ DidYouMean
Returns a new instance of DidYouMean
17 18 19 20 21 22 23 24 25 |
# File 'lib/eskimo/components/did_you_mean.rb', line 17 def initialize(dictionary:, item:, separator: " or ", &children) @corrections = ::DidYouMean::SpellChecker.new( dictionary: dictionary ).correct(item) @separator = separator super end |
Instance Attribute Details
#corrections ⇒ Object (readonly)
Returns the value of attribute corrections
15 16 17 |
# File 'lib/eskimo/components/did_you_mean.rb', line 15 def corrections @corrections end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator
15 16 17 |
# File 'lib/eskimo/components/did_you_mean.rb', line 15 def separator @separator end |
Instance Method Details
#render ⇒ Object
27 28 29 30 31 |
# File 'lib/eskimo/components/did_you_mean.rb', line 27 def render(**) if corrections.any? "Did you mean? #{corrections.join(separator)}" end end |