Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created April 2, 2011 13:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jugyo/899506 to your computer and use it in GitHub Desktop.
Save jugyo/899506 to your computer and use it in GitHub Desktop.
keyword
# keyword plugin
# ====
#
# config example:
#
# Earthquake.config[:keyword] = {
# :pattern => /ruby|rails|earthquake/i,
# :ignore => %w(jugyo yukihiro_matz),
# :filter => true,
# :notify => true
# }
#
Earthquake.init do
_ = config[:keyword] ||= {}
_[:ignore] ||= []
_[:notify] = true if _[:notify].nil?
_[:filter] = false if _[:filter].nil?
# to filter
output_filter do |item|
next unless _[:pattern] && item["text"]
words = item["text"].scan(_[:pattern])
unless words.empty?
item["_highlights"] ||= []
item["_highlights"] += words
true
else
if item["_stream"]
if _[:filter] && _[:ignore].exclude?(item["user"]["screen_name"])
false
else
true
end
else
true
end
end
end
# to notify
output do |item|
next unless _[:pattern] && _[:notify] && item["_stream"] && item["text"]
text = item["text"].u
if text =~ _[:pattern] && item["user"]["screen_name"] != twitter.info["screen_name"]
notify text, :title => item["user"]["screen_name"]
end
end
end
@cheeyeo
Copy link

cheeyeo commented Mar 9, 2012

test comment

@cheeyeo
Copy link

cheeyeo commented Mar 9, 2012

test comment 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment