Class: Tempo::Views::ViewRecords::TimeRecord

Inherits:
Log
  • Object
show all
Defined in:
lib/tempo/views/view_records/time_record.rb

Overview

TimeRecord adds a description, project and end_time and running flag to the Log Record to represent any instance of the TimeRecord model. It also includes a Duration ViewRecord for presenting the total duration of the time record.

Instance Attribute Summary collapse

Attributes inherited from Log

#d_id, #start_time

Attributes inherited from Model

#id, #type

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options = {}) ⇒ TimeRecord

Returns a new instance of TimeRecord.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tempo/views/view_records/time_record.rb', line 25

def initialize(model, options={})
  super model, options
  @description = model.description
  @description ||= ""
  @duration = Duration.new model.duration
  @end_time = model.end_time == :running ? Time.now().round : model.end_time
  @project = model.project_title
  @running = model.running?
  self.class.max_description_length @description.length
  self.class.max_project_length @project.length
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/tempo/views/view_records/time_record.rb', line 11

def description
  @description
end

#durationObject

Returns the value of attribute duration.



11
12
13
# File 'lib/tempo/views/view_records/time_record.rb', line 11

def duration
  @duration
end

#end_timeObject

Returns the value of attribute end_time.



11
12
13
# File 'lib/tempo/views/view_records/time_record.rb', line 11

def end_time
  @end_time
end

#projectObject

Returns the value of attribute project.



11
12
13
# File 'lib/tempo/views/view_records/time_record.rb', line 11

def project
  @project
end

#runningObject

Returns the value of attribute running.



11
12
13
# File 'lib/tempo/views/view_records/time_record.rb', line 11

def running
  @running
end

Class Method Details

.max_description_length(len = 0) ⇒ Object



14
15
16
17
# File 'lib/tempo/views/view_records/time_record.rb', line 14

def max_description_length(len=0)
  @max_description_length ||= 0
  @max_description_length = @max_description_length > len ? @max_description_length : len
end

.max_project_length(len = 0) ⇒ Object



19
20
21
22
# File 'lib/tempo/views/view_records/time_record.rb', line 19

def max_project_length(len=0)
  @max_project_length ||= 0
  @max_project_length = @max_project_length > len ? @max_project_length : len
end

Instance Method Details

#format(&block) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/tempo/views/view_records/time_record.rb', line 37

def format(&block)
  block ||= lambda do |m|
    running = m.running ? "*" : " "
    description = @description ? "#{m.project}: #{m.description}" : "#{m.project}"
    "#{m.start_time.strftime('%H:%M')} - #{m.end_time.strftime('%H:%M')}#{running} [#{m.duration.format}] #{description}"
  end
  block.call self
end