class DidYouMean::KeyErrorChecker - Documentation for Ruby 4.0
Description: Documentation for the DidYouMean::KeyErrorChecker class
Keywords: ruby,class,DidYouMean::KeyErrorChecker

🔍

No recent searches

# class DidYouMean::KeyErrorChecker

### Public Class Methods

new (key_error)
Source

    # File lib/did_you_mean/spell_checkers/key_error_checker.rb, line 5
    def initialize(key_error)
      @key = key_error.key
      @keys = key_error.receiver.keys
    end

### Public Instance Methods

corrections ()
Source

    # File lib/did_you_mean/spell_checkers/key_error_checker.rb, line 10
    def corrections
      @corrections ||= exact_matches.empty? ? SpellChecker.new(dictionary: @keys).correct(@key).map(&:inspect) : exact_matches
    end

### Private Instance Methods

exact_matches ()
Source

    # File lib/did_you_mean/spell_checkers/key_error_checker.rb, line 16
    def exact_matches
      @exact_matches ||= @keys.select { |word| @key == word.to_s }.map { |obj| format_object(obj) }
    end

format_object (symbol_or_object)
Source

    # File lib/did_you_mean/spell_checkers/key_error_checker.rb, line 20
    def format_object(symbol_or_object)
      if symbol_or_object.is_a?(Symbol)
        ":#{symbol_or_object}"
      else
        symbol_or_object.to_s
      end
    end