From 1daa85825c8606d5593692f54ef403bbcff997a0 Mon Sep 17 00:00:00 2001 From: weddingcakes Date: Sun, 27 Jan 2013 08:40:48 -0500 Subject: [PATCH 1/4] Extract `if` / `else` clause to a private method --- lib/pomo/task.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/pomo/task.rb b/lib/pomo/task.rb index 8b621c2..f6c71da 100644 --- a/lib/pomo/task.rb +++ b/lib/pomo/task.rb @@ -101,15 +101,8 @@ def foreground_progress(config) :format => format_message, :tokens => { :remaining => length }, :complete_message => complete_message - ) do |remaining| - if remaining == length / 2 - notifier.notify 'Half way there!', :header => "#{remaining} minutes remaining" - elsif remaining == 5 - notifier.notify 'Almost there!', :header => '5 minutes remaining' - end - sleep 60 unless ENV['POMO_ENV']=='test' - { :remaining => remaining } - end + ) { |remaining| notify_of_time_periods(remaining)} + notifier.notify "Hope you are finished #{self}", :header => 'Time is up!', :type => :warning @@ -178,5 +171,15 @@ def refresh_tmux_status_bar Process.detach(pid) end + private + def notify_of_time_periods(remaining) + if remaining == length / 2 + notifier.notify 'Half way there!', :header => "#{remaining} minutes remaining" + elsif remaining == 5 + notifier.notify 'Almost there!', :header => '5 minutes remaining' + end + sleep 60 unless ENV['POMO_ENV']=='test' + { :remaining => remaining } + end end end From 10bea9f01f8ab148bd72b624d40d8f440339b7ec Mon Sep 17 00:00:00 2001 From: weddingcakes Date: Sun, 27 Jan 2013 09:10:42 -0500 Subject: [PATCH 2/4] Extract more methods --- lib/pomo/task.rb | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/pomo/task.rb b/lib/pomo/task.rb index f6c71da..d854337 100644 --- a/lib/pomo/task.rb +++ b/lib/pomo/task.rb @@ -147,14 +147,7 @@ def background_progress(config) end def tmux_time(time) - case time - when 0 - "#{time}:00" - when 1..5 - "#[default]#[fg=red]#{time}:00#[default]" - when 6..100 - "#[default]#[fg=green]#{time}:00#[default]" - end + set_tmux_time end def write_tmux_time(time) @@ -181,5 +174,24 @@ def notify_of_time_periods(remaining) sleep 60 unless ENV['POMO_ENV']=='test' { :remaining => remaining } end + + def if_task_running + if task = list.running + task.running = false + task.complete = true + list.save + end + end + + def set_tmux_time + case time + when 0 + "#{time}:00" + when 1..5 + "#[default]#[fg=red]#{time}:00#[default]" + when 6..100 + "#[default]#[fg=green]#{time}:00#[default]" + end + end end end From df7c41f482e71c53c4823f01f158cdae7af473a3 Mon Sep 17 00:00:00 2001 From: weddingcakes Date: Sun, 27 Jan 2013 09:15:18 -0500 Subject: [PATCH 3/4] Fixed un-needed `private` --- lib/pomo/task.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/pomo/task.rb b/lib/pomo/task.rb index d854337..53fc1dc 100644 --- a/lib/pomo/task.rb +++ b/lib/pomo/task.rb @@ -163,8 +163,7 @@ def refresh_tmux_status_bar end Process.detach(pid) end - - private + def notify_of_time_periods(remaining) if remaining == length / 2 notifier.notify 'Half way there!', :header => "#{remaining} minutes remaining" @@ -193,5 +192,11 @@ def set_tmux_time "#[default]#[fg=green]#{time}:00#[default]" end end + + def write_pomodoro_stat + File.open(path, 'w') do |file| + file.write tmux_time(time) + end + end end end From 02574b455e15a499e153355a0c6774ad690edf5f Mon Sep 17 00:00:00 2001 From: weddingcakes Date: Sun, 27 Jan 2013 09:19:32 -0500 Subject: [PATCH 4/4] Extract even more methods --- lib/pomo/task.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pomo/task.rb b/lib/pomo/task.rb index 53fc1dc..c36937b 100644 --- a/lib/pomo/task.rb +++ b/lib/pomo/task.rb @@ -90,7 +90,7 @@ def start(config, options = {}) private def foreground_progress(config) - notifier = Pomo::Notifier.new(config) + new_notifier(config) say "Started #{self}, you have #{length} minutes :)" @@ -115,7 +115,7 @@ def foreground_progress(config) end def background_progress(config) - notifier = Pomo::Notifier.new(config) + new_notifier(config) notifier.notify "Started #{self}", :header => "You have #{length} minutes" @@ -198,5 +198,9 @@ def write_pomodoro_stat file.write tmux_time(time) end end + + def new_notifier(opts) + notifier = Pomo::Notifier.new(opts) + end end end