Class: ReportItem

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

Instance Method Summary collapse

Constructor Details

#initialize(report, time_entry) ⇒ ReportItem

Returns a new instance of ReportItem.



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

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

Instance Method Details

#<=>(other_time_entry) ⇒ Object



90
91
92
# File 'lib/timesheet/report_item.rb', line 90

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

#commentObject



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

def comment
  @time_entry.comment || ""
end

#durationObject



28
29
30
31
# File 'lib/timesheet/report_item.rb', line 28

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

#end_slice_indicationObject



42
43
44
# File 'lib/timesheet/report_item.rb', line 42

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

#end_timeObject



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

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

#end_time_sliced?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/timesheet/report_item.rb', line 34

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

#formatted_durationObject



84
85
86
87
88
# File 'lib/timesheet/report_item.rb', line 84

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

#formatted_end_timeObject



62
63
64
# File 'lib/timesheet/report_item.rb', line 62

def formatted_end_time
  end_time.strftime("%m/%d/%Y at %I:%M:%S %p")
end

#formatted_record_numberObject



54
55
56
# File 'lib/timesheet/report_item.rb', line 54

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

#formatted_start_timeObject



58
59
60
# File 'lib/timesheet/report_item.rb', line 58

def formatted_start_time
  start_time.strftime("%m/%d/%Y at %I:%M:%S %p")
end

#formatted_timesObject



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

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

#projectObject



16
17
18
# File 'lib/timesheet/report_item.rb', line 16

def project
  @time_entry.project
end

#record_numberObject



80
81
82
# File 'lib/timesheet/report_item.rb', line 80

def record_number
  @time_entry.record_number || "N/A"
end

#start_slice_indicationObject



38
39
40
# File 'lib/timesheet/report_item.rb', line 38

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

#start_timeObject



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

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

#start_time_sliced?Boolean

Returns:

  • (Boolean)


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

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