punched 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/punched +13 -4
  3. data/lib/punchcard.rb +7 -3
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bed6547761121ad6c16979875ca50597e85489e
4
- data.tar.gz: 07cf3d880ead444c6acdf5779796c526f3d87c47
3
+ metadata.gz: c11e735e75e510009cdd02e3966362587174661a
4
+ data.tar.gz: 73395dc375aced17abbaad5698b26eb384ad3675
5
5
  SHA512:
6
- metadata.gz: cb9309efb628b620ce7e3d4a0ea6baa71bc3328283675e5031677966d77b124a98a5e9660a50236a2fc137ecf32c75d8b39a331f8ce2723ec0b6c7f5af87b5c9
7
- data.tar.gz: 353d7c5d5cdb0ce801f6025b80fe0657d80efcd7362e896ce9ab0aebcf7a0ee3f6cab5690a1716e4602006e3abde0f0a5c0d203a06e904ee9df481531843af7c
6
+ metadata.gz: 5ab915be0d34843bb5a588b49b88e9921ebfc21892d6bb3ab5350a1ce7f382935bff00393493956f049b434b507a5c59f722f6c61ef53d73a0cf175ba100e288
7
+ data.tar.gz: 51a5575c46bd9cc2e7e731de35fd0bdfdcf5408aa08c5108dafa3503791e553f05effa61da3c986aa776f2a6d95d46ed107eeedddc95ad52cc66722206c4caaa
data/bin/punched CHANGED
@@ -24,10 +24,19 @@ def usage
24
24
  end
25
25
 
26
26
  def all action
27
- puts('"project","status","last active on","total duration","hourly rate","earnings"') if action == 'csv'
28
- Dir[PunchCard::SETTINGS_DIR+'/*'].sort_by { |f| File.mtime(f) }.reverse.each do |file|
29
- puts `ruby #{__FILE__} #{action} '#{File.basename(file)}'`
30
- end
27
+ require 'csv'
28
+ require 'date'
29
+ puts ["project","status","last active on","total duration","hourly rate","earnings"].to_csv if action == 'csv'
30
+ puts Dir[PunchCard::SETTINGS_DIR+'/*'].map { |file|
31
+ data = CSV.parse(`ruby #{__FILE__} #{action} '#{File.basename(file)}'`).first
32
+ last_activity = !data[2].empty? ? DateTime.parse(data[2]).to_time.to_i : 0
33
+ data.push(last_activity)
34
+ data
35
+ }.sort { |a, b|
36
+ a.last <=> b.last
37
+ }.reverse.map { |row|
38
+ row[0...-1]
39
+ }.map(&:to_csv).join
31
40
  end
32
41
 
33
42
  if ARGV.first == 'all'
data/lib/punchcard.rb CHANGED
@@ -1,4 +1,6 @@
1
- # (c) 2017 by philipp staender
1
+ # (c) 2017-2018 by philipp staender
2
+
3
+ require 'date'
2
4
 
3
5
  class PunchCardError < StandardError;
4
6
  end
@@ -9,7 +11,7 @@ class PunchCard
9
11
  HOURLY_RATE_PATTERN = /^\s*(\d+)([^\d]+)*\s*/i
10
12
  TIME_POINT_PATTERN = /^(\d+)((\-)(\d+))*$/
11
13
  META_KEY_PATTERN = /^([a-zA-Z0-9]+)\:\s*(.*)$/
12
- VERSION = '0.1.3'
14
+ VERSION = '0.2.0'
13
15
 
14
16
  attr_accessor :project
15
17
 
@@ -87,18 +89,20 @@ class PunchCard
87
89
  project_exists_or_stop!
88
90
  find_or_make_file
89
91
  durations = []
92
+ last_activity = nil
90
93
  project_data.map do |line|
91
94
  points = line_to_time_points(line)
92
95
  if points
93
96
  starttime = points[0]
94
97
  endtime = points[1] || timestamp
98
+ last_activity = points[1] || points[0]
95
99
  durations.push duration(starttime, endtime)
96
100
  end
97
101
  end
98
102
  '"'+[
99
103
  @project,
100
104
  running_status,
101
- self.class.format_time(File.ctime(project_file)),
105
+ last_activity ? self.class.format_time(Time.at(last_activity).to_datetime) : '',
102
106
  humanized_total,
103
107
  hourly_rate ? hourly_rate[:hourlyRate].to_s + " #{hourly_rate[:currency]}" : '',
104
108
  hourly_rate ? (hourly_rate[:hourlyRate] * total / 3600.0).round(2).to_s + " #{hourly_rate[:currency]}" : '',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: punched
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipp Staender
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-20 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Minimal time tracking tool for cli
14
14
  email:
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  version: '0'
48
48
  requirements: []
49
49
  rubyforge_project: punched
50
- rubygems_version: 2.6.12
50
+ rubygems_version: 2.5.2
51
51
  signing_key:
52
52
  specification_version: 4
53
53
  summary: Punchcard Timetracker