class Wordbot::Bot
Public Class Methods
compress(list)
click to toggle source
# File lib/wordbot/bot.rb, line 7 def self.compress list a = [] buffer = '' list.each do |i| if is_word i unless buffer == '' a.push buffer buffer = '' end a.push i else buffer << i end end unless buffer == '' a.push buffer end a end
is_letter(char)
click to toggle source
# File lib/wordbot/bot.rb, line 52 def self.is_letter char 'abcdefghijklmnopqrstuvwxyz'.index char.downcase end
is_word(string)
click to toggle source
# File lib/wordbot/bot.rb, line 47 def self.is_word string return false if string == '' string.split('').all? { |c| is_letter c } end
mutilate(string)
click to toggle source
# File lib/wordbot/bot.rb, line 43 def self.mutilate string split(string).map { |i| scramble i}.join '' end
scramble(word)
click to toggle source
# File lib/wordbot/bot.rb, line 30 def self.scramble word return word unless is_word word word = word.split '' front = word.shift back = word.pop '%s%s%s' % [ front, word.shuffle.join(''), back ] end
split(string)
click to toggle source
# File lib/wordbot/bot.rb, line 3 def self.split string compress string.split /([^A-Za-z])/ end