class ClasslessMud::Commands::BadCommand::Suggestions

Attributes

word[R]

Public Class Methods

new(word) click to toggle source
# File lib/classless_mud/commands/bad_command.rb, line 23
def initialize(word)
  @word = word
end

Public Instance Methods

all() click to toggle source
# File lib/classless_mud/commands/bad_command.rb, line 35
def all
  deletions + transpositions + replacements
end
deletions() click to toggle source
# File lib/classless_mud/commands/bad_command.rb, line 39
def deletions
  (0..length).map { |i| "#{word[0...i]}#{word[i+1..-1]}" }
end
length() click to toggle source
# File lib/classless_mud/commands/bad_command.rb, line 27
def length
  word.length
end
matches(potentials) click to toggle source
# File lib/classless_mud/commands/bad_command.rb, line 31
def matches(potentials)
  potentials & all
end
replacements() click to toggle source
# File lib/classless_mud/commands/bad_command.rb, line 47
def replacements
  (0..length-1).inject([]) do |sum, i|
    sum += ('a'..'z').map { |c| "#{word[0...i]}#{c}#{word[i+1..-1]}" }
  end
end
transpositions() click to toggle source
# File lib/classless_mud/commands/bad_command.rb, line 43
def transpositions
  (0..length-1).map { |i| "#{word[0...i]}#{word[i+1, 1]}#{word[i,1]}#{word[i+2..-1]}" }
end