Skip to content

Instantly share code, notes, and snippets.

@bkerley
Created September 5, 2010 23:26
Show Gist options
  • Save bkerley/566430 to your computer and use it in GitHub Desktop.
Save bkerley/566430 to your computer and use it in GitHub Desktop.
# wrote it, didn't try it
module TWSS
class Body
def initialize(text)
@text = text
end
def sentences
@text.split(/\?|\.|\;/).map{ |s| Sentence.new(s) }
end
def filtered_sentences
sentences.map(&:filtered).join(' ')
end
end
class Sentence < String
DIRT = File.read('words.txt').split("\n")
THRESHOLD = 0.5
def words
split
end
def cuss_words
words.select{|w| DIRT.include? w }
end
def dirty_ratio
cuss_words.length.to_f / words.length.to_f
end
def dirty?
dirty_ratio >= THRESHOLD
end
def filtered
return self unless dirty?
"\n#{self} (THAT'S WHAT SHE SAID)\n"
end
end
end
body = TWSS::Body.new(File.read(ARGV[0]))
puts body.filtered_sentences
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment