123456789_123456789_123456789_123456789_123456789_

Class: DidYouMean::PatternKeyNameChecker

Relationships & Source Files
Inherits: Object
Defined in: lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(no_matching_pattern_key_error) ⇒ PatternKeyNameChecker

[ GitHub ]

  
# File 'lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb', line 5

def initialize(no_matching_pattern_key_error)
  @key = no_matching_pattern_key_error.key
  @keys = no_matching_pattern_key_error.matchee.keys
end

Instance Method Details

#corrections

[ GitHub ]

  
# File 'lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb', line 10

def corrections
  @corrections ||= exact_matches.empty? ? SpellChecker.new(dictionary: @keys).correct(@key).map(&:inspect) : exact_matches
end

#exact_matches (private)

[ GitHub ]

  
# File 'lib/did_you_mean/spell_checkers/pattern_key_name_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) (private)

[ GitHub ]

  
# File 'lib/did_you_mean/spell_checkers/pattern_key_name_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