Sha256: 82c123eea05d7c19418b3de9b26c5764dc79b78426112ce532faa6ccb3985a45

Contents?: true

Size: 494 Bytes

Versions: 6

Compression:

Stored size: 494 Bytes

Contents

# frozen_string_literal: true

module ActionPolicy
  # Adds `suggest` method which uses did_you_mean
  # to generate a suggestion message
  module SuggestMessage
    if defined?(::DidYouMean::SpellChecker)
      def suggest(needle, heystack)
        suggestion = ::DidYouMean::SpellChecker.new(
          dictionary: heystack
        ).correct(needle).first

        suggestion ? "\nDid you mean? #{suggestion}" : ""
      end
    else
      def suggest(*__rest__) ;  ""; end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
action_policy-0.7.3 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.7.2 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.7.1 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.7.0 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.6.9 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb
action_policy-0.6.8 lib/.rbnext/3.0/action_policy/utils/suggest_message.rb