Top Level Namespace
Defined Under Namespace
Modules: Readline, Termtter, Yharian
Classes: Array, Rubytter, Symbol
Constant Summary
collapse
- URL_SHORTTERS =
[
{ :host => "tinyurl.com", :pattern => %r'(http://tinyurl\.com(/[\w/]+))' },
{ :host => "is.gd", :pattern => %r'(http://is\.gd(/[\w/]+))' },
]
- URI_RE =
URI.regexp(%w(http https ftp))
Instance Method Summary
collapse
Instance Method Details
#april_fool ⇒ Object
4
|
# File 'lib/plugins/april_fool.rb', line 4
def april_fool;april_fool? ? "今日はエイプリルフールではありません。" : "今日はエイプリルフールです。";end
|
#april_fool? ⇒ Boolean
3
|
# File 'lib/plugins/april_fool.rb', line 3
def april_fool?;true;end
|
#config ⇒ Object
60
61
62
|
# File 'lib/termtter/config.rb', line 60
def config
Termtter::Config.instance
end
|
#configatron ⇒ Object
64
65
66
67
68
|
# File 'lib/termtter/config.rb', line 64
def configatron
warn "configatron method will be removed. Use config instead. (#{caller.first})"
Termtter::Config.instance
end
|
#create_highline ⇒ Object
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/termtter/system_extensions.rb', line 149
def create_highline
HighLine.track_eof = false
if $stdin.respond_to?(:getbyte) require 'delegate'
stdin_for_highline = SimpleDelegator.new($stdin)
def stdin_for_highline.getc
getbyte
end
else
stdin_for_highline = $stdin
end
HighLine.new(stdin_for_highline)
end
|
#expand_url(host, path) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/plugins/expand-tinyurl.rb', line 22
def expand_url(host, path)
http_class = Net::HTTP
unless config.proxy.host.nil? or config.proxy.host.empty?
http_class = Net::HTTP::Proxy(config.proxy.host,
config.proxy.port,
config.proxy.user_name,
config.proxy.password)
end
res = http_class.new('tinyurl.com').head(path)
return nil unless res.code == "301" or res.code == "302"
res['Location']
end
|
#fib(n) ⇒ Object
3
|
# File 'lib/plugins/fib.rb', line 3
def fib(n)i=0;j=1;n.times{j=i+i=j};i end
|
#filter(name, init = {}) ⇒ Object
14
15
16
17
|
# File 'lib/termtter/system_extensions.rb', line 14
def filter(name, init = {})
warn "filter method will be removed. Use plugin instead."
plugin(name, init)
end
|
#get_icon_path(s) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/plugins/growl.rb', line 19
def get_icon_path(s)
Dir.mkdir_p(config.plugins.growl.icon_cache_dir) unless File.exists?(config.plugins.growl.icon_cache_dir)
cache_file = "%s/%s%s" % [ config.plugins.growl.icon_cache_dir,
s.user.screen_name,
File.extname(s.user.profile_image_url) ]
if !File.exist?(cache_file) || (File.atime(cache_file) + 24*60*60) < Time.now
File.open(cache_file, "wb") do |f|
begin
f << open(URI.escape(s.user.profile_image_url)).read
rescue OpenURI::HTTPError
return nil
end
end
end
cache_file
end
|
#get_priority(s, priority_keys) ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/plugins/growl2.rb', line 75
def get_priority(s,priority_keys)
priority = 2
5.times {|n|
return priority.to_s if priority_keys['user'][n].include?(s.user.screen_name) ||
priority_keys['keyword'][n] =~ s.text
priority -= 1
}
return '0'
end
|
#is_growl(s, growl_keys) ⇒ Object
85
86
87
88
89
|
# File 'lib/plugins/growl2.rb', line 85
def is_growl(s,growl_keys)
return true if (growl_keys['user'].empty? && growl_keys['keyword'] == /(?!)/) ||
(growl_keys['user'].include?(s.user.screen_name) || growl_keys['keyword'] =~ s.text)
return false
end
|
#is_sticky(s, sticky_keys) ⇒ Object
91
92
93
94
|
# File 'lib/plugins/growl2.rb', line 91
def is_sticky(s,sticky_keys)
return true if sticky_keys['user'].include?(s.user.screen_name) || sticky_keys['keyword'] =~ s.text
return false
end
|
#make_termtter_http(host) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/plugins/shorturl_on_update.rb', line 27
def make_termtter_http(host)
http_class = Net::HTTP
unless config.proxy.host.nil? || config.proxy.host.empty?
http_class = Net::HTTP::Proxy(config.proxy.host,
config.proxy.port,
config.proxy.user_name,
config.proxy.password )
end
http_class.new(host)
end
|
#out_put_status(status, color) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/plugins/system_status.rb', line 10
def out_put_status(status, color)
formatted_status = ERB.new(config.plugins.system_status.format).result(binding)
colored_status = color(formatted_status, color)
print "\e[s\e[1000G\e[#{status.size - 1}D#{colored_status}\e[u"
$stdout.flush
end
|
#plugin(name, init = {}) ⇒ Object
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/termtter/system_extensions.rb', line 3
def plugin(name, init = {})
unless init.empty?
init.each do |key, value|
config.plugins.__refer__(name.to_sym).__assign__(key.to_sym, value)
end
end
load "plugins/#{name}.rb"
rescue Exception => e
Termtter::Client.handle_error(e)
end
|
#primes(n) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/plugins/primes.rb', line 3
def primes(n)
return "" if n < 3
table = []
(2 .. n).each do |i|
table << i
end
prime = []
loop do
prime << table[0]
table = table.delete_if {|x| x % prime.max == 0 }
break if table.max < (prime.max ** 2)
end
r = (table+prime).sort {|a, b| a<=>b }
r.join(', ')
end
|
#print(str) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/termtter/system_extensions.rb', line 106
def print(str)
str.to_s.gsub("\xef\xbd\x9e", "\xe3\x80\x9c").split(/(\e\[\d*[a-zA-Z])/).each do |token|
case token
when /\e\[(\d+)m/
$wSetConsoleTextAttribute.call $hStdOut, $colorMap[$1.to_i].to_i
when /\e\[\d*[a-zA-Z]/
else
loop do
begin
STDOUT.print $iconv_u8_to_sj.iconv(token)
break
rescue Iconv::Failure
STDOUT.print "#{$!.success}?"
token = $!.failed[1..-1]
end
end
end
end
$wSetConsoleTextAttribute.call $hStdOut, $oldColor
$iconv_u8_to_sj.iconv(nil)
end
|
#puts(str) ⇒ Object
128
129
130
131
|
# File 'lib/termtter/system_extensions.rb', line 128
def puts(str)
print str
STDOUT.puts
end
|
#quicklook(url) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/plugins/quicklook.rb', line 12
def quicklook(url)
tmpdir = Pathname.new(config.plugins.quicklook.quicklook_tmpdir)
path = tmpdir + Pathname.new(url).basename
Thread.new do
open(path, 'w') do |f|
f.write(open(url).read)
end
system("qlmanage -p #{path} > /dev/null 2>&1")
end
end
|
#say(who, what) ⇒ Object
- say
-
String -> String -> IO ()
6
7
8
9
10
|
# File 'lib/plugins/say.rb', line 6
def say(who, what)
voices = %w(Alex Alex Bruce Fred Ralph Agnes Kathy Vicki)
voice = voices[who.hash % voices.size]
system 'say', '-v', voice, what
end
|
#translate(text, langpair) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/plugins/translation.rb', line 8
def translate(text, langpair)
req = Net::HTTP::Post.new('/translate_t')
req.add_field('Content-Type', 'application/x-www-form-urlencoded')
req.add_field('User-Agent', 'Mozilla/5.0')
Net::HTTP.version_1_2 Net::HTTP.start('translate.google.co.jp', 80) {|http|
response = http.request(req, "langpair=#{langpair}&text=#{URI.escape(text)}")
doc = Nokogiri::HTML.parse(response.body, nil, 'utf-8')
return doc.css('#result_box').text
}
end
|
#win? ⇒ Boolean
45
46
47
|
# File 'lib/termtter/system_extensions.rb', line 45
def win?
RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
end
|