Class: Tamarillo::Tomato
- Inherits:
-
Object
- Object
- Tamarillo::Tomato
- Defined in:
- lib/tamarillo/tomato.rb
Overview
Public: A unit of work.
A Tomato is a ‘pomodoro’, it keeps track of the amount of time you have focused on a single task. It can be interrupted or completed.
Defined Under Namespace
Modules: States
Instance Attribute Summary collapse
-
#duration ⇒ Object
Public: Gets/Sets the length of the tomato in seconds.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Public: Returns true if the Tomato has not been completed or interrupted.
-
#approx_minutes_remaining ⇒ Object
Public: Returns the approximate number of minutes until completetion.
-
#completed? ⇒ Boolean
Public: Returns true if the elapsed Time matches the duration.
-
#date ⇒ Object
Public: Returns the Date the Tomato was started on.
-
#elapsed ⇒ Object
Public: Returns the number of seconds elapsed since start.
-
#eql?(other) ⇒ Boolean
Public: Returns true if two Tomatoes share a start Time.
-
#initialize(duration, clock) ⇒ Tomato
constructor
Public: Initializes a new Tomato.
-
#interrupt! ⇒ Object
Public: Marks the tomato as interrupted.
-
#interrupted? ⇒ Boolean
Public: Returns true if the Tomato has been interrupted.
-
#remaining ⇒ Object
Public: Returns the number of seconds until completion.
-
#started_at ⇒ Object
Public: Returns the starting Time of the Tomato.
-
#state ⇒ Object
Public: Returns which state the Tomato is in.
Constructor Details
#initialize(duration, clock) ⇒ Tomato
Public: Initializes a new Tomato.
duration - The length of the Tomato in seconds. clock - A Clock instance to keep track of elapsed time.
23 24 25 26 |
# File 'lib/tamarillo/tomato.rb', line 23 def initialize(duration, clock) @duration = duration @clock = clock end |
Instance Attribute Details
#duration ⇒ Object
Public: Gets/Sets the length of the tomato in seconds.
17 18 19 |
# File 'lib/tamarillo/tomato.rb', line 17 def duration @duration end |
Instance Method Details
#active? ⇒ Boolean
Public: Returns true if the Tomato has not been completed or interrupted.
71 72 73 |
# File 'lib/tamarillo/tomato.rb', line 71 def active? States::ACTIVE == state end |
#approx_minutes_remaining ⇒ Object
Public: Returns the approximate number of minutes until completetion.
52 53 54 |
# File 'lib/tamarillo/tomato.rb', line 52 def approx_minutes_remaining (remaining / 60.0).round.to_i end |
#completed? ⇒ Boolean
Public: Returns true if the elapsed Time matches the duration.
76 77 78 |
# File 'lib/tamarillo/tomato.rb', line 76 def completed? States::COMPLETED == state end |
#date ⇒ Object
Public: Returns the Date the Tomato was started on.
34 35 36 |
# File 'lib/tamarillo/tomato.rb', line 34 def date @clock.start_date end |
#elapsed ⇒ Object
Public: Returns the number of seconds elapsed since start.
57 58 59 |
# File 'lib/tamarillo/tomato.rb', line 57 def elapsed @clock.elapsed end |
#eql?(other) ⇒ Boolean
Public: Returns true if two Tomatoes share a start Time.
39 40 41 42 |
# File 'lib/tamarillo/tomato.rb', line 39 def eql?(other) other.started_at == started_at || super(other) end |
#interrupt! ⇒ Object
Public: Marks the tomato as interrupted.
Returns the Tomato.
64 65 66 67 |
# File 'lib/tamarillo/tomato.rb', line 64 def interrupt! @interrupted = true self end |
#interrupted? ⇒ Boolean
Public: Returns true if the Tomato has been interrupted.
81 82 83 |
# File 'lib/tamarillo/tomato.rb', line 81 def interrupted? States::INTERRUPTED == state end |
#remaining ⇒ Object
Public: Returns the number of seconds until completion.
45 46 47 48 |
# File 'lib/tamarillo/tomato.rb', line 45 def remaining d = @duration - @clock.elapsed d > 0 ? d : 0 end |
#started_at ⇒ Object
Public: Returns the starting Time of the Tomato.
29 30 31 |
# File 'lib/tamarillo/tomato.rb', line 29 def started_at @clock.start_time end |
#state ⇒ Object
Public: Returns which state the Tomato is in.
I’d rather keep this internal, but the storage system needs to know what state the tamato was in when it was written.
89 90 91 92 93 94 95 96 97 |
# File 'lib/tamarillo/tomato.rb', line 89 def state if @interrupted States::INTERRUPTED elsif remaining == 0 States::COMPLETED else States::ACTIVE end end |