Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/ruby

require ENV["TM_SUPPORT_PATH"]+"/lib/web_preview"

content = STDIN.read

swear_words = {
    "foock" => /foock(er|ing)?/,
    "bar" => /bar/,
    "baz" => /baz/
}

swear_counts = Hash.new

swear_words.keys.each do |key|
    matches = content.scan(swear_words[key])
    swear_counts[key] = matches.length
end


html_header("Swear Words")
puts "<table>"
swear_counts.keys.each do |key|
    puts "<tr><td>#{key.to_s}</td><td>#{swear_counts[key].to_s}</td></tr>"
end
puts "</table>"
html_footer()