Created
March 12, 2010 18:28
-
-
Save rafapolo/330592 to your computer and use it in GitHub Desktop.
entendedor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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