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