Class: Pompom::Pomodoro

Inherits:
Object
  • Object
show all
Defined in:
lib/pompom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time_remaining = 1500, message = nil) ⇒ Pomodoro

Returns a new instance of Pomodoro.



103
104
105
106
107
108
109
# File 'lib/pompom.rb', line 103

def initialize(time_remaining=1500, message=nil)
  @time_remaining = time_remaining
  @message = message
  @system_clock = Kernel
  @observers = []
  @finished_early = true
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



100
101
102
# File 'lib/pompom.rb', line 100

def message
  @message
end

#system_clock=(value) ⇒ Object (writeonly)

Sets the attribute system_clock

Parameters:

  • value

    the value to set the attribute system_clock to.



101
102
103
# File 'lib/pompom.rb', line 101

def system_clock=(value)
  @system_clock = value
end

#time_remainingObject (readonly)

Returns the value of attribute time_remaining.



100
101
102
# File 'lib/pompom.rb', line 100

def time_remaining
  @time_remaining
end

Instance Method Details

#add_observer(object) ⇒ Object



111
112
113
# File 'lib/pompom.rb', line 111

def add_observer(object)
  @observers << object
end

#finish!Object



122
123
124
125
# File 'lib/pompom.rb', line 122

def finish!
  @time_remaining = 0
  notify_observers
end

#finished?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/pompom.rb', line 131

def finished?
  @time_remaining < 1
end

#finished_early?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/pompom.rb', line 127

def finished_early?
  @finished_early
end

#tickObject



115
116
117
118
119
120
# File 'lib/pompom.rb', line 115

def tick
  @system_clock.sleep 1
  @time_remaining -= 1
  @finished_early = false if @time_remaining == 0
  notify_observers
end