lib/time_block/agent.rb in time_block-0.0.4 vs lib/time_block/agent.rb in time_block-0.1.0

- old
+ new

@@ -1,27 +1,31 @@ -class TimeBlock::Agent - def initialize(time) - fail 'No terminal-notifier, please install it, brew install terminal-notifier' unless terminal_notifier_exist? - @time = time - end +# frozen_string_literal: true - def run - pre_callback - sleep @time - post_callback - end +module TimeBlock + class Agent + def initialize(time) + raise 'No terminal-notifier, please install it, brew install terminal-notifier' unless terminal_notifier_exist? + @time = time + end - private + def run + pre_callback + sleep @time + post_callback + end - def terminal_notifier_exist? - `which terminal-notifier` - $? == 0 - end + private - def pre_callback - `terminal-notifier -message #{"Time is starting !!!".dump} -title "TimeBlock - #{@time}s" -sound "default"` - end + def terminal_notifier_exist? + `which terminal-notifier` + $CHILD_STATUS.zero? + end - def post_callback - `terminal-notifier -message #{"Time is out dude !!!".dump} -title "TimeBlock - #{@time}s" -sound "default"` + def pre_callback + `terminal-notifier -message #{'Time is starting !!!'.dump} -title "TimeBlock - #{@time}s" -sound "default"` + end + + def post_callback + `terminal-notifier -message #{'Time is out dude !!!'.dump} -title "TimeBlock - #{@time}s" -sound "default"` + end end end