timesheet 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/timesheet.rb +4 -1
- data/lib/timesheet/report_item.rb +12 -0
- data/lib/timesheet/time_report.rb +18 -0
- data/lib/timesheet/timesheet_parser.rb +4 -0
- data/spec/time_report_spec.rb +15 -0
- data/spec/timesheet_spec.rb +6 -1
- metadata +1 -1
data/lib/timesheet.rb
CHANGED
@@ -17,7 +17,7 @@ require 'timesheet/timesheet_parser'
|
|
17
17
|
|
18
18
|
class Timesheet
|
19
19
|
|
20
|
-
VERSION = '0.2.
|
20
|
+
VERSION = '0.2.7'
|
21
21
|
|
22
22
|
def self.run(params)
|
23
23
|
command_hash = {}
|
@@ -64,6 +64,9 @@ class Timesheet
|
|
64
64
|
def process_edit_command(command_opts)
|
65
65
|
record_number = command_opts.delete(:record_number)
|
66
66
|
@timelog.update(record_number, command_opts)
|
67
|
+
entries = [@timelog.find(record_number)]
|
68
|
+
time_report = TimeReport.new(entries)
|
69
|
+
time_report.report({:dump => true})
|
67
70
|
end
|
68
71
|
|
69
72
|
def process_delete_command(command_opts)
|
@@ -53,6 +53,14 @@ class ReportItem < DelegateClass(TimeEntry)
|
|
53
53
|
sprintf("%5d", @time_entry.record_number)
|
54
54
|
end
|
55
55
|
|
56
|
+
def formatted_start_time
|
57
|
+
start_time.strftime("%m/%d/%Y at %I:%M:%S %p")
|
58
|
+
end
|
59
|
+
|
60
|
+
def formatted_end_time
|
61
|
+
end_time.strftime("%m/%d/%Y at %I:%M:%S %p")
|
62
|
+
end
|
63
|
+
|
56
64
|
def formatted_times
|
57
65
|
str = ""
|
58
66
|
str << start_slice_indication
|
@@ -67,6 +75,10 @@ class ReportItem < DelegateClass(TimeEntry)
|
|
67
75
|
@time_entry.comment || ""
|
68
76
|
end
|
69
77
|
|
78
|
+
def record_number
|
79
|
+
@time_entry.record_number || "N/A"
|
80
|
+
end
|
81
|
+
|
70
82
|
def formatted_duration
|
71
83
|
str = ""
|
72
84
|
str << duration.strftime("%d Days ") if duration.days > 0
|
@@ -22,6 +22,7 @@ class TimeReport
|
|
22
22
|
else
|
23
23
|
constrain(command_options[:start], command_options[:end])
|
24
24
|
|
25
|
+
dump_report(outstream) if command_options[:dump]
|
25
26
|
detail_report(outstream) if command_options[:detail]
|
26
27
|
summary_report(outstream) if command_options[:summary]
|
27
28
|
byday_report(outstream) if command_options[:byday]
|
@@ -30,6 +31,23 @@ class TimeReport
|
|
30
31
|
|
31
32
|
private
|
32
33
|
|
34
|
+
def dump_report(outstream)
|
35
|
+
fields = [
|
36
|
+
{:name => "Record:", :method => :record_number },
|
37
|
+
{:name => "Project:", :method => :project},
|
38
|
+
{:name => "Start:", :method => :formatted_start_time},
|
39
|
+
{:name => "End:", :method => :formatted_end_time},
|
40
|
+
{:name => "Hours:", :method => :formatted_duration},
|
41
|
+
{:name => "Comment:", :method => :comment}
|
42
|
+
]
|
43
|
+
|
44
|
+
item = @entries.first
|
45
|
+
|
46
|
+
label_width = fields.inject(0) { |max, field| max = [max, field[:name].length].max }
|
47
|
+
fields.each { |field| outstream.puts "#{field[:name].ljust(label_width)} #{item.send(field[:method])}" }
|
48
|
+
|
49
|
+
end
|
50
|
+
|
33
51
|
def detail_report(outstream)
|
34
52
|
|
35
53
|
fields = [
|
data/spec/time_report_spec.rb
CHANGED
@@ -40,6 +40,21 @@ describe TimeReport do
|
|
40
40
|
stream.string.should eql("No data available.\n")
|
41
41
|
end
|
42
42
|
|
43
|
+
it "should be able to produce a dump report" do
|
44
|
+
command_options = {:dump => true}
|
45
|
+
stream = StringIO.new
|
46
|
+
@time_report.report(command_options, stream)
|
47
|
+
stream.string.should eql( <<EOS
|
48
|
+
Record: N/A
|
49
|
+
Project: ProjectA
|
50
|
+
Start: 12/01/2009 at 09:00:00 AM
|
51
|
+
End: 12/01/2009 at 12:00:00 PM
|
52
|
+
Hours: 3h 0m
|
53
|
+
Comment: comment 1
|
54
|
+
EOS
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
43
58
|
it "should be able to produce a detail report" do
|
44
59
|
command_options = {:detail => true, :start => Time.local(2009, 12, 1), :end => Time.local(2009, 12, 6)}
|
45
60
|
stream = StringIO.new
|
data/spec/timesheet_spec.rb
CHANGED
@@ -136,12 +136,17 @@ describe Timesheet do
|
|
136
136
|
context "when processing edit command" do
|
137
137
|
|
138
138
|
it "should perform an edit" do
|
139
|
-
command = mock("
|
139
|
+
command = mock("dump command")
|
140
140
|
timelog = mock("timelog")
|
141
141
|
timesheet = Timesheet.new(timelog)
|
142
|
+
time_report = mock("time report")
|
143
|
+
entries = mock("entries")
|
142
144
|
|
143
145
|
command.should_receive(:delete).with(:record_number).once.and_return(100)
|
144
146
|
timelog.should_receive(:update).with(100, command)
|
147
|
+
timelog.should_receive(:find).with(100).once.and_return(entries)
|
148
|
+
TimeReport.should_receive(:new).with([entries]).once.and_return(time_report)
|
149
|
+
time_report.should_receive(:report).with({:dump => true})
|
145
150
|
|
146
151
|
timesheet.process_edit_command(command)
|
147
152
|
end
|