Class: PomodoroTimer::Cycle

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/pomodoro_timer/cycle.rb', line 3

def name
  @name
end

#progressObject

Returns the value of attribute progress.



4
5
6
# File 'lib/pomodoro_timer/cycle.rb', line 4

def progress
  @progress
end

Class Method Details

.breakObject



23
24
25
# File 'lib/pomodoro_timer/cycle.rb', line 23

def break
  Cycle.new(BREAK_NAME)
end

.workObject



27
28
29
# File 'lib/pomodoro_timer/cycle.rb', line 27

def work
  Cycle.new(WORK_NAME)
end

Instance Method Details

#break?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/pomodoro_timer/cycle.rb', line 54

def break?
  return @name == :break
end

#missing_progressObject



50
51
52
# File 'lib/pomodoro_timer/cycle.rb', line 50

def missing_progress
  return LIMITS[@name] - @progress
end

#startObject



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

Returns:

  • (Boolean)


62
63
64
# File 'lib/pomodoro_timer/cycle.rb', line 62

def stopped?
  return self == STOPPED
end

#work?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/pomodoro_timer/cycle.rb', line 58

def work?
  return @name == :work
end