Parent

Files

Object

Public Instance Methods

__dir__() click to toggle source
# File lib/plugins/source.rb, line 1
def __dir__
  File.dirname(File.expand_path(__FILE__))
end
addr?(arg) click to toggle source
# File lib/plugins/whois.rb, line 40
def addr?(arg)
  Resolv::AddressRegex =~ arg
end
config() click to toggle source
# File lib/termtter/config.rb, line 94
def config
  Termtter::Config.instance
end
confirm(message) click to toggle source
# File lib/plugins/defaults/confirm.rb, line 3
def confirm(message)
  if config.confirm && !Termtter::Client.confirm(message)
    raise Termtter::CommandCanceled
  end
end
copy_to_clipboard(str) click to toggle source
# File lib/plugins/copy.rb, line 3
def copy_to_clipboard(str)
  if /darwin/ =~ RUBY_PLATFORM
    IO.popen("pbcopy", "w") do |io|
      io.print str
    end
  else
    puts "Sorry, this plugin is only in Mac OS X."
  end
  str
end
decrypt(msg, salt) click to toggle source
# File lib/plugins/crypt.rb, line 13
def decrypt(msg, salt)
  decoder = OpenSSL::Cipher::DES.new
  decoder.decrypt
  decoder.pkcs5_keyivgen(salt)
  decoder.update([msg].pack('H*')) + decoder.final
end
encrypt(msg, salt) click to toggle source
# File lib/plugins/crypt.rb, line 6
def encrypt(msg, salt)
  encoder = OpenSSL::Cipher::DES.new
  encoder.encrypt
  encoder.pkcs5_keyivgen(salt)
  (encoder.update(msg) + encoder.final).unpack('H*').to_s
end
expand_url(host, path) click to toggle source
# File lib/plugins/expand-tinyurl.rb, line 44
def expand_url(host, path)
  res = Termtter::HTTPpool.start(host) do |h|
    h.get(path, { 'User-Agent' => 'Mozilla' })
  end
  return nil unless res.code =~ /\A30/
  newurl = res['Location']
  newurl.respond_to?(:force_encoding) ? newurl.force_encoding(Encoding::UTF_8) : newurl
rescue Exception => e
  Termtter::Client.handle_error(e)
  nil
end
fib(n) click to toggle source
# File lib/plugins/defaults/fib.rb, line 1
def fib(n)i=0;j=1;n.times{j=i+i=j};i end
filter(name, init = {}) click to toggle source
# File lib/termtter/system_extensions/termtter_compatibles.rb, line 14
def filter(name, init = {})
  warn "filter method will be removed. Use plugin instead."
  plugin(name, init)
end
get_draft_index(arg) click to toggle source
# File lib/plugins/draft.rb, line 9
def get_draft_index(arg)
  case arg
  when /^\d+$/
    arg.to_i
  when ''
    -1
  else
    nil
  end
end
get_icon_path(s) click to toggle source
# File lib/plugins/growl.rb, line 67
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
let(o) click to toggle source
# File lib/plugins/source.rb, line 5
def let(o)
  yield o
end
list_drafts(drafts) click to toggle source
# File lib/plugins/draft.rb, line 3
def list_drafts(drafts)
  drafts.each_with_index do |draft, index|
    puts "#{index}: #{draft}"
  end
end
load_keywords() click to toggle source
# File lib/plugins/defaults/keyword.rb, line 29
def load_keywords
  public_storage[:keywords] += config.plugins.keyword.keywords
  file = File.expand_path(config.plugins.keyword.file)
  if File.exists?(file)
    public_storage[:keywords] += File.read(file).split(/\n/)
  end
end
multibyte_string(text) click to toggle source
# File lib/plugins/truncate.rb, line 2
def multibyte_string(text)
  text.unpack('U*')
end
out_put_status(status, color) click to toggle source
# File lib/plugins/system_status.rb, line 9
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 = {}) click to toggle source
# File lib/termtter/system_extensions/termtter_compatibles.rb, line 2
def plugin(name, init = {})
  warn "plugin method will be removed. Use Termtter::Client.plug instead."
  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
post_gyazo() click to toggle source
# File lib/plugins/gyazo.rb, line 3
def post_gyazo
  browser_cmd = 'firefox'
  gyazo_url = ""

  idfile = ENV['HOME'] + "/.gyazo.id"

  id = nil
  if File.exist?(idfile)
    id = File.read(idfile).chomp
  else
    id = Time.new.strftime("%Y%m%d%H%M%S")
    File.open(idfile,"w").print(id+"\n")
  end

  tmpfile = "/tmp/image_upload#{$$}.png"

  system import, tmpfile

  imagedata = File.read(tmpfile)
  File.delete(tmpfile)

  boundary = '----BOUNDARYBOUNDARY----'

  data = --#{boundary}\rcontent-disposition: form-data; name="id"\r\r#{id}\r--#{boundary}\rcontent-disposition: form-data; name="imagedata"\r\r#{imagedata}\r\r--#{boundary}--\r

  header = {
    'Content-Length' => data.length.to_s,
    'Content-type' => "multipart/form-data; boundary=#{boundary}"
  }

  Net::HTTP.start("gyazo.com", 80){|http|
    res = http.post("/upload.cgi", data, header)
    url = res.response.to_ary[1]
    puts url
    system "#{browser_cmd} #{url}"
    gyazo_url = url
  }
  gyazo_url
end
primes(n) click to toggle source
# File lib/plugins/primes.rb, line 2
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
puts(str) click to toggle source
# File lib/termtter/system_extensions/windows.rb, line 81
def puts(str)
  print str
  STDOUT.puts
end
quicklook(url) click to toggle source
# File lib/plugins/quicklook.rb, line 11
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 :: String → String → IO () click to toggle source
# File lib/plugins/say.rb, line 6
def say(who, what)
  voices = %(Alex Alex Bruce Fred Ralph Agnes Kathy Vicki)
  voice = voices[who.hash % voices.size]
  system 'say', '-v', voice, what
end
select_matched(statuses) click to toggle source
# File lib/plugins/defaults/keyword.rb, line 21
def select_matched(statuses)
  regexp = Regexp.union(*public_storage[:keywords].map(&:to_s))
  statuses.select do |status|
    /#{regexp}/ =~ status.text ||
      (config.plugins.keyword.apply_user_name == true && /#{regexp}/ =~ status[:user][:screen_name])
  end
end
source(pluginname) click to toggle source
# File lib/plugins/source.rb, line 9
def source(pluginname)
  File.read(
    let(
      Pathname(__dir__) + "#{pluginname}.rb") {|a|
        File.exist?(a) ? a : Pathname(__dir__) + "defaults/#{pluginname}.rb" })
end
translate_by_google(text,o={}) click to toggle source
# File lib/plugins/translate_tweet.rb, line 8
def translate_by_google(text,o={})
  opt = {:from => "",:to => "en"}.merge(o)
  j = JSON.parse(open(
    "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="     +"#{CGI.escape(text)}&langpair=#{CGI.escape("#{opt[:from]}|#{opt[:to]}")}").read)
  j["responseData"]["translatedText"] rescue nil
end
truncate(s) click to toggle source
# File lib/plugins/source.rb, line 16
def truncate(s)
  s.each_char.take(140).join
end
url_by_tweet(t) click to toggle source
# File lib/plugins/url.rb, line 1
def url_by_tweet(t)
  "http://twitter.com/#{t.user.screen_name}/status/#{t.id}"
end
whois?(arg) click to toggle source
# File lib/plugins/whois.rb, line 24
def whois?(arg)
  if addr? arg 
    begin
      Resolv.getname(arg)
    rescue => e
      e.message
    end
  else
    begin
      Resolv.getaddress(arg)
    rescue => e
      e.message
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.