class InOurTime::PlayTime

Public Class Methods

new(dur) click to toggle source
# File lib/iot/iot.rb, line 97
def initialize(dur)
  @duration = dur
  @start_time = Time.now
  update
end

Public Instance Methods

changed?() click to toggle source
# File lib/iot/iot.rb, line 103
def changed?
  ! unchanged?
end
ended?() click to toggle source
# File lib/iot/iot.rb, line 112
def ended?
  (@duration + 20) < @seconds
end
format(x) click to toggle source
# File lib/iot/iot.rb, line 140
def format x
  x < 10 ? '0' + x.to_s : x.to_s
end
format_minutes() click to toggle source
# File lib/iot/iot.rb, line 144
def format_minutes
  format mins
end
format_remaining_time() click to toggle source
# File lib/iot/iot.rb, line 152
def format_remaining_time
  secs = @duration - @seconds
  format(secs/60) + ':' + format(secs%60)
end
format_secs() click to toggle source
# File lib/iot/iot.rb, line 148
def format_secs
  format secs
end
format_time() click to toggle source
# File lib/iot/iot.rb, line 157
def format_time
  ' (' + format_minutes + ':' + format_secs +
  ' / '  + format_remaining_time + ')'
end
forward() click to toggle source
# File lib/iot/iot.rb, line 179
def forward
  @start_time -= 1.5
end
mins() click to toggle source
# File lib/iot/iot.rb, line 132
def mins
  @seconds / 60
end
pause() click to toggle source
# File lib/iot/iot.rb, line 166
def pause
  @paused = Time.now
end
paused?() click to toggle source
# File lib/iot/iot.rb, line 170
def paused?
  @paused
end
plural(x) click to toggle source
# File lib/iot/iot.rb, line 128
def plural x
  x == 1 ? '' : 's'
end
read() click to toggle source
# File lib/iot/iot.rb, line 107
def read
  store
  format_time
end
rewind() click to toggle source
# File lib/iot/iot.rb, line 183
def rewind
  @start_time += 1.5
end
secs() click to toggle source
# File lib/iot/iot.rb, line 136
def secs
  @seconds % 60
end
store() click to toggle source
# File lib/iot/iot.rb, line 120
def store
  @stored = @seconds
end
stored() click to toggle source
# File lib/iot/iot.rb, line 124
def stored
  @stored
end
unchanged?() click to toggle source
# File lib/iot/iot.rb, line 116
def unchanged?
  (update == stored) || paused?
end
unpause() click to toggle source
# File lib/iot/iot.rb, line 174
def unpause
  @start_time = @start_time + (Time.now - @paused)
  @paused = false
end
update() click to toggle source
# File lib/iot/iot.rb, line 162
def update
  @seconds = (Time.now - @start_time).to_i
end