Sha256: 3d187768ab2c0b16d5998de1aea3398e046bc3ab36273b581439d3721008a4de

Contents?: true

Size: 539 Bytes

Versions: 3

Compression:

Stored size: 539 Bytes

Contents

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
did_you_mean-1.6.3 lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb
did_you_mean-1.6.2 lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb
did_you_mean-1.6.1 lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb