Class: Task

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

Constant Summary collapse

TIME_FORMAT =
"%Y-%m-%d %H:%M"
DEFAULT_PROJECT =
'<project-name>'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, started_at = nil, finished_at = nil, project = nil) ⇒ Task

Returns a new instance of Task.



19
20
21
22
23
24
# File 'lib/task.rb', line 19

def initialize(description, started_at = nil, finished_at = nil, project = nil)
  @started_at  = started_at || Time.now
  @finished_at = finished_at
  @project     = project || DEFAULT_PROJECT
  @description = description
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/task.rb', line 9

def description
  @description
end

#finished_atObject (readonly)

Returns the value of attribute finished_at.



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

def finished_at
  @finished_at
end

#projectObject

Returns the value of attribute project.



9
10
11
# File 'lib/task.rb', line 9

def project
  @project
end

#started_atObject (readonly)

Returns the value of attribute started_at.



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

def started_at
  @started_at
end

Class Method Details

.from_array(task_data) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/task.rb', line 11

def self.from_array(task_data)
  description = task_data[3]
  started_at  = Time.parse(task_data[0]) if task_data[0]
  finished_at = Time.parse(task_data[1]) if task_data[1]
  project     = task_data[2]
  new(description, started_at, finished_at, project)
end

Instance Method Details

#finish!Object



31
32
33
# File 'lib/task.rb', line 31

def finish!
  @finished_at = Time.now unless finished?
end

#restart!Object



26
27
28
29
# File 'lib/task.rb', line 26

def restart!
  @started_at  = Time.now
  @finished_at = nil
end

#to_aObject



35
36
37
# File 'lib/task.rb', line 35

def to_a
  [formatted_started_at, formatted_finished_at, @project, @description]
end