Skip to content

Instantly share code, notes, and snippets.

@rafapolo
Created March 12, 2010 18:28
Show Gist options
  • Save rafapolo/330592 to your computer and use it in GitHub Desktop.
Save rafapolo/330592 to your computer and use it in GitHub Desktop.
entendedor
#!ruby19
# encoding: utf8
# author: rafael polo
# created_at 11.mar.2010
# updated_at 12.mar.2010
require 'yaml'
class Entendedor
def self.naoVou?(msg, termo)
termo = termo.gsub('"', '')
msg = msg.text.gsub("a\243", "a")
if termo_position = msg.index(termo)
if nao_position = msg.index("nao") || nem_position = msg.index("nem")
return nao_position == termo_position-4 || nem_position == termo_position-4 ? true : false
end
end
end
def self.praOnde(msg, termo)
msg = msg.text
if position = msg.index(termo)
position += termo.length+1
if proximo_espaco = msg.index(" ", position)
proxima_palavra = limpa(msg[position..proximo_espaco-1])
return proxima_palavra.length >= 4 ? proxima_palavra : false
end
end
end
def self.limpa(str)
return str.gsub("?", "").gsub("!", "").gsub(".", "").gsub(",", "").strip
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment