| 1 |
require_relative "../spell_checker" |
| 2 |
|
| 3 |
module DidYouMean |
| 4 |
class PatternKeyNameChecker |
| 5 |
def initialize(no_matching_pattern_key_error) |
| 6 |
@key = no_matching_pattern_key_error.key |
| 7 |
@keys = no_matching_pattern_key_error.matchee.keys |
| 8 |
end |
| 9 |
|
| 10 |
def corrections |
| 11 |
@corrections ||= exact_matches.empty? ? SpellChecker.new(dictionary: @keys).correct(@key).map(&:inspect) : exact_matches |
| 12 |
end |
| 13 |
|
| 14 |
private |
| 15 |
|
| 16 |
def exact_matches |
| 17 |
@exact_matches ||= @keys.select { |word| @key == word.to_s }.map(&:inspect) |
| 18 |
end |
| 19 |
end |
| 20 |
end |