Permalink
Browse files

add lib/plugin.rb and use the module

  • Loading branch information...
1 parent a5d559e commit 3c2e007ea0e6bd3e861f7f5d881ea9570ee5fa7a @ujihisa ujihisa committed Jan 5, 2009
Showing with 20 additions and 12 deletions.
  1. +2 −0 lib/plugin.rb
  2. +6 −4 lib/plugin/english.rb
  3. +8 −6 lib/plugin/say.rb
  4. +4 −2 lib/plugin/stdout.rb
View
@@ -0,0 +1,2 @@
+module Termtter::Plugin
+end
View
@@ -1,8 +1,10 @@
Termtter::Client.clear_hooks # FIXME: not to clear all but to clear just stdout.rb
-# english? :: String -> Boolean
-def english?(message)
- /[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+|[a-zA-Z0-9]+/ !~ message
+module Termtter::Plugin
+ # english? :: String -> Boolean
+ def self.english?(message)
+ /[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+|[a-zA-Z0-9]+/ !~ message
+ end
end
# FIXME: The code below is a copy from stdout.rb so it's not DRY. DRY it.
@@ -15,7 +17,7 @@ def english?(message)
if event == :update_friends_timeline then statuses = statuses.reverse end
statuses.each do |s|
text = s.text.gsub("\n", '')
- next unless english?(text) # if you substitute "if" for "unless", this script will be "japanese.rb"
+ next unless Termtter::Plugin.english?(text) # if you substitute "if" for "unless", this script will be "japanese.rb"
color_num = colors[s.user_screen_name.hash % colors.size]
status = "#{s.user_screen_name}: #{text}"
if s.in_reply_to_status_id
View
@@ -1,18 +1,20 @@
raise 'say.rb runs only in OSX Leopard' if /darwin9/ !~ RUBY_PLATFORM
-# say :: String -> String -> IO ()
-def say(who, what)
- voices = %w(Alex Bruce Fred Junior Ralph Agnes Kathy Princess Vicki Victoria Albert Bad\ News Bahh Bells Boing Bubbles Cellos Deranged Good\ News Hysterical Pipe\ Organ Trinoids Whisper Zarvox)
- voice = voices[who.hash % voices.size]
- system 'say', '-v', voice, what
+module Termtter::Plugin
+ # say :: String -> String -> IO ()
+ def self.say(who, what)
+ voices = %w(Alex Bruce Fred Junior Ralph Agnes Kathy Princess Vicki Victoria Albert Bad\ News Bahh Bells Boing Bubbles Cellos Deranged Good\ News Hysterical Pipe\ Organ Trinoids Whisper Zarvox)
+ voice = voices[who.hash % voices.size]
+ system 'say', '-v', voice, what
+ end
end
module Termtter::Client
add_hook do |statuses, event, t|
if !statuses.empty? && event == :update_friends_timeline
statuses.reverse.each do |s|
text_without_uri = s.text.gsub(%r|https?://[^\s]+|, 'U.R.I.')
- say s.user_screen_name, text_without_uri
+ Termtter::Plugin.say s.user_screen_name, text_without_uri
end
end
end
@@ -1,5 +1,7 @@
-def color(str, num)
- "\e[#{num}m#{str}\e[0m"
+module Termtter::Plugin
+ def color(str, num)
+ "\e[#{num}m#{str}\e[0m"
+ end
end
Termtter::Client.add_hook do |statuses, event|

0 comments on commit 3c2e007

Please sign in to comment.