class Romodoro

Public Class Methods

new(time = 15) click to toggle source
# File lib/romodoro.rb, line 2
def initialize(time = 15)
  @timer_time_in_seconds = time * 60
  @sound_path = "/System/Library/Sounds/Ping.aiff"
  @picture_path = "~/Dropbox/images/ERy2M_MXsAA835B.jpg"
  @how_many_times = 5
  # TODO add picture and sound directories. randomise
end

Public Instance Methods

open_picture() click to toggle source
# File lib/romodoro.rb, line 41
def open_picture
  system "open #{@picture_path}"
end
play_sound(path_to_sound) click to toggle source
# File lib/romodoro.rb, line 35
def play_sound(path_to_sound)
  # TODO check if system has afplay
  command = "afplay #{path_to_sound}"
  system command
end
start() click to toggle source
# File lib/romodoro.rb, line 10
def start
  start = Time.now
  puts "start: #{start}"
  seconds_passed = 0
  puts "Timer started"
  # do something every x seconds
  wait_time = 1 # second
  while true
    sleep wait_time
    seconds_passed += 1
    puts "a second passed. seconds passed: #{seconds_passed}"
    time_diff = Time.now - start
    puts "start time minus Time.now: #{time_diff}"
    puts "@timer_time_in_seconds: #{@timer_time_in_seconds}"
    if time_diff >= @timer_time_in_seconds
      open_picture
      play_sound(@sound_path)
      break
    end
  end
  puts "opertation done"
  elapse = Time.now - start
  puts "Took #{elapsed} seconds."
end