timesheets 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/timesheets/commands/base.rb +8 -0
- data/lib/timesheets/commands/status.rb +11 -4
- data/lib/timesheets/commands/summary.rb +35 -14
- data/lib/timesheets/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91fa9830d81f3444ceed62b779739f22631af3cd
|
4
|
+
data.tar.gz: 77acf5e415da7ffe0ed07181e906b5eda6540c90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c39ed7579ec8decbf16c59d1fa04e8e69ef9e5faba32523f089f555db48fb112307fee5ce2cec80db9fff6465cf60e74d1dab474faadeb72896d584e2134e74
|
7
|
+
data.tar.gz: 84b8a4acc632c600efc2c4545c1e3abaab8a9a206543009929557372b5e1426cdc5c9273294c8baeba6eec412f9c90dec90d3a021b8330788356b646004125f1
|
@@ -19,6 +19,14 @@ module Timesheets
|
|
19
19
|
@entries ||= rows.map {|row| row.map {|dt| DateTime.parse(dt || Time.now.to_s).to_time } }
|
20
20
|
end
|
21
21
|
|
22
|
+
def todays_entries
|
23
|
+
entries.select {|entry| entry.first.strftime('%Y%m%d') == today }
|
24
|
+
end
|
25
|
+
|
26
|
+
def today
|
27
|
+
@today ||= Time.new.strftime('%Y%m%d')
|
28
|
+
end
|
29
|
+
|
22
30
|
def rows
|
23
31
|
@rows ||= CSV.read(filepath)[1..-1]
|
24
32
|
end
|
@@ -2,17 +2,20 @@ module Timesheets
|
|
2
2
|
module Commands
|
3
3
|
class Status < Base
|
4
4
|
def run
|
5
|
+
strings = []
|
5
6
|
if session_in_progress?
|
6
|
-
|
7
|
+
strings << "Current work session has been active for #{active_time}."
|
7
8
|
else
|
8
|
-
|
9
|
+
strings << "Not currently working."
|
9
10
|
end
|
11
|
+
strings << "Total time today is #{total_time_today}."
|
12
|
+
puts strings.join(' ')
|
10
13
|
end
|
11
14
|
|
12
15
|
private
|
13
16
|
|
14
|
-
def active_time
|
15
|
-
hoursf = hours_in_entry(
|
17
|
+
def active_time(the_entries = [entries.last])
|
18
|
+
hoursf = the_entries.map {|entry| hours_in_entry(entry) }.reduce(:+)
|
16
19
|
hours = hoursf.to_i
|
17
20
|
mins = ((hoursf - hours) * 60).to_i
|
18
21
|
|
@@ -21,6 +24,10 @@ module Timesheets
|
|
21
24
|
.join(', ')
|
22
25
|
end
|
23
26
|
|
27
|
+
def total_time_today
|
28
|
+
active_time(todays_entries)
|
29
|
+
end
|
30
|
+
|
24
31
|
def pluralize(word, n)
|
25
32
|
n == 1 && "#{n} #{word}" || "#{n} #{word}s"
|
26
33
|
end
|
@@ -8,28 +8,49 @@ module Timesheets
|
|
8
8
|
private
|
9
9
|
|
10
10
|
def summary_table
|
11
|
-
Terminal::Table.new(headings:
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
Terminal::Table.new(headings: heading) {|t|
|
12
|
+
entries_by_week.each_with_index {|entries, index|
|
13
|
+
format_entries(entries).each {|entry| t << entry }
|
14
|
+
t << :separator
|
15
|
+
t << (heading.length - 2).times.map { '' } + ['Weekly Total:', sprintf('%0.02f', hours_in_entries(entries))]
|
16
|
+
t << :separator
|
17
|
+
}
|
15
18
|
|
16
|
-
|
19
|
+
t << (heading.length - 2).times.map { '' } + ['Total:', sprintf('%0.02f', total_hours)]
|
20
|
+
|
21
|
+
heading.length.times {|i| t.align_column(i, :right) }
|
17
22
|
}
|
18
23
|
end
|
19
24
|
|
25
|
+
def heading
|
26
|
+
['Weekday', 'Date', 'Time', 'Hour(s)']
|
27
|
+
end
|
28
|
+
|
20
29
|
def total_hours
|
21
|
-
entries
|
30
|
+
hours_in_entries(entries)
|
31
|
+
end
|
32
|
+
|
33
|
+
def hours_in_entries(the_entries)
|
34
|
+
the_entries.map {|entry| hours_in_entry(entry) }.reduce(:+)
|
35
|
+
end
|
36
|
+
|
37
|
+
def entries_by_week
|
38
|
+
@entries_by_week ||= entries.group_by {|entry| entry.first.strftime('%U') }.values
|
22
39
|
end
|
23
40
|
|
24
|
-
def
|
25
|
-
|
41
|
+
def format_entries(entries)
|
42
|
+
entries.group_by {|entry|
|
43
|
+
entry.first.strftime('%B %e, %Y')
|
44
|
+
}.map {|day, entries|
|
26
45
|
[
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
time
|
31
|
-
|
32
|
-
|
46
|
+
entries.first.first.strftime('%A'),
|
47
|
+
day,
|
48
|
+
entries.map {|entry|
|
49
|
+
entry.map {|time|
|
50
|
+
time.strftime('%l:%M%p')
|
51
|
+
}.join(' - ')
|
52
|
+
}.join(', '),
|
53
|
+
sprintf('%0.02f', entries.map {|entry| hours_in_entry(entry) }.reduce(:+))
|
33
54
|
].flatten
|
34
55
|
}
|
35
56
|
end
|
data/lib/timesheets/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timesheets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bradley J. Spaulding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|