Class: ClasslessMud::Commands::BadCommand::Suggestions
- Inherits:
-
Object
- Object
- ClasslessMud::Commands::BadCommand::Suggestions
- Defined in:
- lib/classless_mud/commands/bad_command.rb
Instance Attribute Summary collapse
-
#word ⇒ Object
readonly
Returns the value of attribute word.
Instance Method Summary collapse
- #all ⇒ Object
- #deletions ⇒ Object
-
#initialize(word) ⇒ Suggestions
constructor
A new instance of Suggestions.
- #length ⇒ Object
- #matches(potentials) ⇒ Object
- #replacements ⇒ Object
- #transpositions ⇒ Object
Constructor Details
#initialize(word) ⇒ Suggestions
Returns a new instance of Suggestions.
23 24 25 |
# File 'lib/classless_mud/commands/bad_command.rb', line 23 def initialize(word) @word = word end |
Instance Attribute Details
#word ⇒ Object (readonly)
Returns the value of attribute word.
21 22 23 |
# File 'lib/classless_mud/commands/bad_command.rb', line 21 def word @word end |
Instance Method Details
#all ⇒ Object
35 36 37 |
# File 'lib/classless_mud/commands/bad_command.rb', line 35 def all deletions + transpositions + replacements end |
#deletions ⇒ Object
39 40 41 |
# 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 ⇒ Object
27 28 29 |
# File 'lib/classless_mud/commands/bad_command.rb', line 27 def length word.length end |
#matches(potentials) ⇒ Object
31 32 33 |
# File 'lib/classless_mud/commands/bad_command.rb', line 31 def matches(potentials) potentials & all end |
#replacements ⇒ Object
47 48 49 50 51 |
# 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 ⇒ Object
43 44 45 |
# 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 |