Skip to content

Instantly share code, notes, and snippets.

@sss
Forked from jugyo/keyword.rb
Created April 21, 2011 14:11
Show Gist options
  • Save sss/934599 to your computer and use it in GitHub Desktop.
Save sss/934599 to your computer and use it in GitHub Desktop.
keyword
# keyword plugin
# ====
#
# config example:
#
# Earthquake.config[:keyword] = {:pattern => /ruby|rails|earthquake/i}
#
Earthquake.init do
config[:keyword] ||= {}
config[:keyword][:pattern] ||= /ruby|rails|earthquake/i
config[:keyword][:notify] = true if config[:keyword][:notify].nil?
output_filter do |item|
next unless item["text"]
words = item["text"].scan(config[:keyword][:pattern])
unless words.empty?
item["_highlights"] ||= []
item["_highlights"] += words
end
end
output do |item|
next unless config[:keyword][:notify] && item["_stream"] && item["text"]
text = item["text"].u
if text =~ config[:keyword][:pattern] && item["user"]["screen_name"] != twitter.info["screen_name"]
notify text, :title => item["user"]["screen_name"]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment