Class: TomatoHarvest::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Task

Returns a new instance of Task.



7
8
9
10
# File 'lib/tomatoharvest/task.rb', line 7

def initialize(name)
  @name = name
  @pomodoros = []
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/tomatoharvest/task.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/tomatoharvest/task.rb', line 4

def name
  @name
end

#pomodorosObject

Returns the value of attribute pomodoros.



5
6
7
# File 'lib/tomatoharvest/task.rb', line 5

def pomodoros
  @pomodoros
end

Instance Method Details

#log_pomodoro(seconds) ⇒ Object



12
13
14
15
# File 'lib/tomatoharvest/task.rb', line 12

def log_pomodoro(seconds)
  finished_at = DateTime.now
  self.pomodoros << Pomodoro.new(seconds, finished_at)
end

#logged_minutesObject



17
18
19
20
21
22
23
# File 'lib/tomatoharvest/task.rb', line 17

def logged_minutes
  sum = pomodoros.inject(0) do |sum, pomodoro|
    sum + pomodoro.seconds
  end

  sum / 60.0
end