lib/bbiff.rb in bbiff-0.1.1 vs lib/bbiff.rb in bbiff-0.1.2
- old
+ new
@@ -1,9 +1,11 @@
-require 'shellwords'
-require_relative 'bbiff/bbs_reader'
-require_relative 'bbiff/res_format'
+require 'bundler'
+Bundler.require :default
+require 'bbiff/bbs_reader'
+require 'bbiff/res_format'
+
def parse_range(str)
if str == "all"
1..Float::INFINITY
elsif str =~ /^\d+$/
str.to_i..str.to_i
@@ -15,11 +17,12 @@
fail ArgumentError
end
end
def start_polling(thread, start_no)
- notify_send = ENV['BBIFF_NOTIFY_SEND'] || "notify-send"
+ default_notify_command = 'notify-send'
+ notify_send = ENV['BBIFF_NOTIFY_SEND'] || (system("which #{default_notify_command}") ? default_notify_command : 'echo')
loop do
thread.posts(parse_range("#{start_no}-")).each do |post|
system("#{notify_send} #{Shellwords.escape(render_post(post))}")
sleep 1
end
@@ -49,11 +52,9 @@
if url =~ %r{\Ah?ttp://jbbs.shitaraba.net/bbs/read.cgi/(\w+)/(\d+)/(\d+)/?\z}
ita = [$1, $2.to_i]
sure = $3.to_i
end
- thread = Bbs::C板.new(*ita).thread(sure)
+ thread = Bbs::C板.new(*ita).thread(sure)
start_no = ARGV[1] ? ARGV[1].to_i : thread.last + 1
start_polling(thread, start_no)
end
-
-main