Class: ReportItem

Inherits:
TimeEntry show all
Includes:
Comparable
Defined in:
lib/timesheet/report_item.rb

Instance Attribute Summary

Attributes inherited from TimeEntry

#project, #record_number

Instance Method Summary collapse

Methods inherited from TimeEntry

#conflict?, #to_range, #to_s

Constructor Details

#initialize(report, time_entry) ⇒ ReportItem

Returns a new instance of ReportItem.



7
8
9
10
11
# File 'lib/timesheet/report_item.rb', line 7

def initialize( report, time_entry)
  @time_entry = time_entry
  super(@time_entry)
  @report = report
end

Instance Method Details

#<=>(other_time_entry) ⇒ Object



76
77
78
# File 'lib/timesheet/report_item.rb', line 76

def <=>(other_time_entry)
  self.start_time <=> other_time_entry.start_time
end

#commentObject



66
67
68
# File 'lib/timesheet/report_item.rb', line 66

def comment
  @time_entry.comment || ""
end

#durationObject



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

def duration
  return 0 if start_time == nil || end_time == nil
  RichUnits::Duration.new(end_time - start_time)
end

#end_slice_indicationObject



40
41
42
# File 'lib/timesheet/report_item.rb', line 40

def end_slice_indication
  (end_time_sliced?) ? '>' : ' '
end

#end_timeObject



44
45
46
47
48
49
50
# File 'lib/timesheet/report_item.rb', line 44

def end_time
  if end_time_sliced?
    @report.report_end
  else
    @time_entry.end_time
  end
end

#end_time_sliced?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/timesheet/report_item.rb', line 32

def end_time_sliced?
  @time_entry.to_range.include?(@report.report_end)
end

#formatted_durationObject



70
71
72
73
74
# File 'lib/timesheet/report_item.rb', line 70

def formatted_duration
  str = ""
  str << duration.strftime("%d Days ") if duration.days > 0
  str << duration.strftime("%hh %mm")
end

#formatted_record_numberObject



52
53
54
# File 'lib/timesheet/report_item.rb', line 52

def formatted_record_number
  sprintf("%5d", @time_entry.record_number)    
end

#formatted_timesObject



56
57
58
59
60
61
62
63
64
# File 'lib/timesheet/report_item.rb', line 56

def formatted_times
  str = ""
  str << start_slice_indication
  str << start_time.strftime("%m/%d/%Y at %I:%M %p")
  str << " to "
  str << end_time.strftime("%m/%d/%Y at ") if ((start_time.year != end_time.year) || (start_time.yday != end_time.yday))
  str << end_time.strftime("%I:%M %p")
  str << end_slice_indication
end

#start_slice_indicationObject



36
37
38
# File 'lib/timesheet/report_item.rb', line 36

def start_slice_indication
  (start_time_sliced?) ? '<' : ' '
end

#start_timeObject



18
19
20
21
22
23
24
# File 'lib/timesheet/report_item.rb', line 18

def start_time
  if start_time_sliced?
    @report.report_start
  else
    @time_entry.start_time
  end
end

#start_time_sliced?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/timesheet/report_item.rb', line 13

def start_time_sliced?
  @time_entry.to_range.include?(@report.report_start)
end