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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 241b39acbe35ef74faa2c26862450110707d6e7f
4
- data.tar.gz: e8034b7b0ff1da83f69ce7a8543b4801ff4b560b
3
+ metadata.gz: 91fa9830d81f3444ceed62b779739f22631af3cd
4
+ data.tar.gz: 77acf5e415da7ffe0ed07181e906b5eda6540c90
5
5
  SHA512:
6
- metadata.gz: 791d4e86169ca723076c548a6e154c9267473cf5413a4ed0bf858d842706af447477a283902b16c636ce2ce5d68f461929f4b7b8588f8d157b31387e71f25737
7
- data.tar.gz: e3657439a1b06d7122b2c21ebc6b1fdc51da25955e4c15bfa6e0718e37fe3ab5b58c4f8ce965859cf15b9f6ffdacf2693cf9f0e80b617d54a13353f172db8c53
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
- puts "Current work session has been active for #{active_time}"
7
+ strings << "Current work session has been active for #{active_time}."
7
8
  else
8
- puts "Not currently working"
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(entries.last)
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: ['Weekday', 'Date', 'Start Time', 'End Time', 'Hour(s)']) {|t|
12
- formatted_entries.each {|entry| t << entry }
13
- t << :separator
14
- t << (formatted_entries.first.length - 1).times.map { '' } + [sprintf('%0.02f', total_hours)]
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
- formatted_entries.first.length.times {|i| t.align_column(i, :right) }
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.map {|entry| hours_in_entry(entry) }.reduce(:+)
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 formatted_entries
25
- @formatted_entries ||= entries.map {|entry|
41
+ def format_entries(entries)
42
+ entries.group_by {|entry|
43
+ entry.first.strftime('%B %e, %Y')
44
+ }.map {|day, entries|
26
45
  [
27
- entry.first.strftime('%A'),
28
- entry.first.strftime('%B %e, %Y'),
29
- entry.map {|time|
30
- time.strftime('%l:%M%p')
31
- },
32
- sprintf('%0.02f', hours_in_entry(entry))
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
@@ -1,3 +1,3 @@
1
1
  module Timesheets
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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.0.0
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-04 00:00:00.000000000 Z
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor