pomodoro_timer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,7 +6,7 @@ A simple project to count your pomodoros time.
6
6
  ### How use it ###
7
7
  First of all, install it...
8
8
 
9
- gem install pomodoro-timer
9
+ gem install pomodoro_timer
10
10
 
11
11
  After that you can open irb, require and include:
12
12
 
@@ -23,8 +23,8 @@ Now you have the methods:
23
23
 
24
24
 
25
25
  ### How it works ###
26
- *First:* Calling the start method, your 25 minutes of work will start counting.
27
- *Second:* When this time end a ding sound will be played and your 5 minutes of break will starts counting automaticaly.
26
+ *First:* Calling the start method, your 25 minutes of work will start counting.
27
+ *Second:* When this time end a ding sound will be played and your 5 minutes of break will starts counting automaticaly.
28
28
  *Third:* When break time ends you have to start another pomodoro manualy, using the start method.
29
29
 
30
30
 
@@ -0,0 +1,76 @@
1
+ module PomodoroTimer
2
+ class Cycle
3
+ attr_reader :name
4
+ attr_accessor :progress
5
+
6
+ BEEP_SOUND = "resources/ding.wav"
7
+ STOPPED = Cycle.new
8
+
9
+ WORK_NAME = :work
10
+ BREAK_NAME = :break
11
+
12
+ WARNINGS = {
13
+ WORK_NAME => "It's work time!",
14
+ BREAK_NAME => "It's break time!"
15
+ }
16
+
17
+ LIMITS = {
18
+ WORK_NAME => 25,#25.minutes,
19
+ BREAK_NAME => 5#5.minutes
20
+ }
21
+
22
+ class << self
23
+ def break
24
+ Cycle.new(BREAK_NAME)
25
+ end
26
+
27
+ def work
28
+ Cycle.new(WORK_NAME)
29
+ end
30
+ end
31
+
32
+ def initialize(name)
33
+ @name = name
34
+ @progress = 0.0
35
+ end
36
+
37
+ def start
38
+ started = Time.now
39
+
40
+ puts "#{WARNINGS[@name]} (#{format(started)})"
41
+
42
+ while @progress < LIMITS[@name]
43
+ @progress = Time.now - started
44
+ sleep 1
45
+ end
46
+
47
+ beep
48
+ end
49
+
50
+ def missing_progress
51
+ return LIMITS[@name] - @progress
52
+ end
53
+
54
+ def break?
55
+ return @name == :break
56
+ end
57
+
58
+ def work?
59
+ return @name == :work
60
+ end
61
+
62
+ def stopped?
63
+ return self == STOPPED
64
+ end
65
+
66
+ private
67
+
68
+ def format(time)
69
+ return time.strftime(PomodoroTimer::TIME_FORMAT)
70
+ end
71
+
72
+ def beep
73
+ system "aplay #{File.join(File.dirname(__FILE__),"../../#{BEEP_SOUND}")} --quiet"
74
+ end
75
+ end
76
+ end
@@ -1,68 +1,35 @@
1
1
  module PomodoroTimer
2
2
  class Pomodoro
3
- BEEP_SOUND = "resources/ding.wav"
4
- WORK_TIME = 25.minutes
5
- BREAK_TIME = 5.minutes
3
+ attr_reader :running
6
4
 
7
- def initialize(what)
8
- @start = Time.now
9
- @thread = Thread.new do
10
- @work_progress = Time.now
11
- if what.to_s != "break"
12
- puts "It's work time! (#{format(@work_progress)})"
13
- while @work_progress - @start < WORK_TIME
14
- @work_progress = Time.now
15
- sleep 1
16
- end
17
- beep
18
- end
19
-
20
- puts "It's break time!(#{format(@work_progress)})"
21
- @break_progress = Time.now
22
- while @break_progress - @work_progress < BREAK_TIME
23
- @break_progress = Time.now
24
- sleep 1
25
- end
26
-
27
- puts "Pomodoro finished!(#{format(@break_progress)})"
28
-
29
- beep
30
- @finished = true
31
- end
5
+ def initialize(will_work=false)
6
+ @running = RunningThread.new(will_work)
32
7
  return nil
33
8
  end
34
9
 
35
10
  def show_status
36
- if @finished
37
- puts "It's done"
38
- elsif @break_progress
39
- puts "It's break time! (#{format_seconds(BREAK_TIME - (@break_progress-@work_progress))})"
11
+ cycle = @running.cycle
12
+ if cycle.stopped?
13
+ puts "No pomodoro running."
14
+ elsif cycle.break?
15
+ puts "It's break time! (#{format_seconds(cycle.missing_progress)})"
40
16
  else
41
- puts "It's work time! (#{format_seconds(WORK_TIME - (@work_progress-@start))})"
17
+ puts "It's work time! (#{format_seconds(cycle.missing_progress)})"
42
18
  end
43
19
  end
44
20
 
45
21
  def cancel
46
- @thread.kill
47
- @finished = true
22
+ @running.kill
48
23
  end
49
24
 
50
25
  def finished?
51
- return @finished
26
+ return @running.cycle.stopped?
52
27
  end
53
28
 
54
29
  private
55
30
 
56
- def format(time)
57
- return time.strftime("%H:%M")
58
- end
59
-
60
31
  def format_seconds(seconds)
61
32
  return sprintf("%.2d:%.2d",seconds/60, seconds%60)
62
33
  end
63
-
64
- def beep
65
- system "aplay #{File.join(File.dirname(__FILE__),"../../#{BEEP_SOUND}")} --quiet"
66
- end
67
34
  end
68
35
  end
@@ -0,0 +1,38 @@
1
+ module PomodoroTimer
2
+ class RunningThread
3
+ attr_reader :cycle
4
+
5
+ def initialize(will_work=false)
6
+ @will_work = will_work
7
+ @cycle = Cycle::STOPPED
8
+
9
+ @thread = Thread.new do
10
+ run
11
+ end
12
+ end
13
+
14
+ def run
15
+ if @will_work
16
+ @cycle = Cycle.work
17
+ @cycle.start
18
+ end
19
+
20
+ @cycle = Cycle.break
21
+ @cycle.start
22
+
23
+ puts "Pomodoro finished!(#{format(Time.now)})"
24
+ @cycle = Cycle::STOPPED
25
+ end
26
+
27
+ def kill
28
+ @cycle = Cycle::STOPPED
29
+ @thread.kill
30
+ end
31
+
32
+ private
33
+
34
+ def format(time)
35
+ return time.strftime(PomodoroTimer::TIME_FORMAT)
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module PomodoroTimer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,14 +1,18 @@
1
1
  require 'fixnum'
2
2
  require 'pomodoro_timer/pomodoro'
3
+ require 'pomodoro_timer/running_thread'
4
+ require 'pomodoro_timer/cycle'
3
5
  require 'pomodoro_timer/version'
4
6
 
5
7
  module PomodoroTimer
6
8
  extend self
7
9
 
10
+ TIME_FORMAT = "%H:%M"
11
+
8
12
  def start(what=nil)
9
13
  @@pomodoro ||= nil
10
14
  if @@pomodoro.nil? || @@pomodoro.finished?
11
- @@pomodoro = Pomodoro.new(what)
15
+ @@pomodoro = Pomodoro.new(what!=Cycle::BREAK_NAME)
12
16
  else
13
17
  puts "Exist another pomodoro running!"
14
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pomodoro_timer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-30 00:00:00.000000000 Z
12
+ date: 2012-07-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Helps handle your pomodoro time.
15
15
  email:
@@ -23,10 +23,10 @@ files:
23
23
  - README.md
24
24
  - Rakefile
25
25
  - lib/fixnum.rb
26
- - lib/lib/pomodoro_timer.rb
27
- - lib/lib/pomodoro_timer/version.rb
28
26
  - lib/pomodoro_timer.rb
27
+ - lib/pomodoro_timer/cycle.rb
29
28
  - lib/pomodoro_timer/pomodoro.rb
29
+ - lib/pomodoro_timer/running_thread.rb
30
30
  - lib/pomodoro_timer/version.rb
31
31
  - pomodoro_timer.gemspec
32
32
  - resources/ding.wav
@@ -53,5 +53,5 @@ rubyforge_project:
53
53
  rubygems_version: 1.8.15
54
54
  signing_key:
55
55
  specification_version: 3
56
- summary: pomodoro_timer (0.0.2)
56
+ summary: pomodoro_timer (0.0.3)
57
57
  test_files: []
@@ -1,3 +0,0 @@
1
- module PomodoroTimer
2
- VERSION = "0.0.1"
3
- end
@@ -1,5 +0,0 @@
1
- require "pomodoro_timer/version"
2
-
3
- module PomodoroTimer
4
- # Your code goes here...
5
- end