class Pascoale::Edits
Constants
- LETTERS
Public Class Methods
new(word)
click to toggle source
# File lib/pascoale/edits.rb, line 4 def initialize(word) @splits = (0..(word.size)).map do |i| [word[0, i].to_s, word[(i)..-1]] end end
Public Instance Methods
deletions()
click to toggle source
# File lib/pascoale/edits.rb, line 10 def deletions @splits.map do |(a, b)| a + b[1..-1] if b.size > 0 end.compact end
editions()
click to toggle source
# File lib/pascoale/edits.rb, line 34 def editions Set.new(deletions + transpositions + substitutions + insertions) end
editions2()
click to toggle source
# File lib/pascoale/edits.rb, line 38 def editions2 editions.each_with_object(Set.new) do |it, result| result.merge(self.class.new(it).editions) end end
insertions()
click to toggle source
# File lib/pascoale/edits.rb, line 28 def insertions LETTERS.product(@splits).map do |(letter, (a, b))| (a + letter + b).strip end end
substitutions()
click to toggle source
# File lib/pascoale/edits.rb, line 22 def substitutions LETTERS.product(@splits).map do |(letter, (a, b))| (a + letter + b[1..-1]).strip if b.size > 0 end.compact end
transpositions()
click to toggle source
# File lib/pascoale/edits.rb, line 16 def transpositions @splits.map do |(a, b)| a + b[1] + b[0] + b[2..-1] if b.size > 1 end.compact end