Class: Eskimo::ASCII::DidYouMean
- Defined in:
- gems/eskimo-ascii/lib/eskimo/ascii/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
16 17 18 19 20 21 22 23 24 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/did_you_mean.rb', line 16 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
14 15 16 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/did_you_mean.rb', line 14 def corrections @corrections end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator
14 15 16 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/did_you_mean.rb', line 14 def separator @separator end |
Instance Method Details
#render ⇒ Object
26 27 28 29 30 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/did_you_mean.rb', line 26 def render(**) if corrections.any? "Did you mean? #{corrections.join(separator)}" end end |