Class: PomodoroTimer::Cycle
- Inherits:
-
Object
- Object
- PomodoroTimer::Cycle
- Defined in:
- lib/pomodoro_timer/cycle.rb
Constant Summary collapse
- BEEP_SOUND =
"resources/ding.wav"
- STOPPED =
Cycle.new
- WORK_NAME =
:work
- BREAK_NAME =
:break
- WARNINGS =
{ WORK_NAME => "It's work time!", BREAK_NAME => "It's break time!" }
- LIMITS =
{ WORK_NAME => 25.minutes, BREAK_NAME => 5.minutes }
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#progress ⇒ Object
Returns the value of attribute progress.
Class Method Summary collapse
Instance Method Summary collapse
- #break? ⇒ Boolean
-
#initialize(name) ⇒ Cycle
constructor
A new instance of Cycle.
- #missing_progress ⇒ Object
- #start ⇒ Object
- #stopped? ⇒ Boolean
- #work? ⇒ Boolean
Constructor Details
#initialize(name) ⇒ Cycle
Returns a new instance of Cycle.
32 33 34 35 |
# File 'lib/pomodoro_timer/cycle.rb', line 32 def initialize(name) @name = name @progress = 0.0 end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/pomodoro_timer/cycle.rb', line 3 def name @name end |
#progress ⇒ Object
Returns the value of attribute progress.
4 5 6 |
# File 'lib/pomodoro_timer/cycle.rb', line 4 def progress @progress end |
Class Method Details
.break ⇒ Object
23 24 25 |
# File 'lib/pomodoro_timer/cycle.rb', line 23 def break Cycle.new(BREAK_NAME) end |
Instance Method Details
#break? ⇒ Boolean
54 55 56 |
# File 'lib/pomodoro_timer/cycle.rb', line 54 def break? return @name == :break end |
#missing_progress ⇒ Object
50 51 52 |
# File 'lib/pomodoro_timer/cycle.rb', line 50 def missing_progress return LIMITS[@name] - @progress end |
#start ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pomodoro_timer/cycle.rb', line 37 def start started = Time.now puts "#{WARNINGS[@name]} (#{format(started)})" while @progress < LIMITS[@name] @progress = Time.now - started sleep 1 end beep end |
#stopped? ⇒ Boolean
62 63 64 |
# File 'lib/pomodoro_timer/cycle.rb', line 62 def stopped? return self == STOPPED end |
#work? ⇒ Boolean
58 59 60 |
# File 'lib/pomodoro_timer/cycle.rb', line 58 def work? return @name == :work end |