trak 0.0.2 → 0.0.3

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/CHANGELOG.md CHANGED
@@ -1,10 +1,24 @@
1
1
  # Change log
2
2
 
3
+ ## v0.0.3 (2012-04-30)
4
+
5
+ Changed:
6
+
7
+ * (3483255): Added exit_err helper method
8
+ * (0c0cbf7): Renamed TrackerUtil module to Trak
9
+ * (9528123): Restructured lib dir
10
+
11
+ Fixed:
12
+
13
+ * (1050905): Fix bug where all time args are truncated to int
14
+ * (328b276): Fixed debug wrapper method
15
+
3
16
  ## v0.0.2 (2012-04-26)
4
17
 
5
- Changed (8854df7):
18
+ Changed:
6
19
 
7
- * Refactored currentTimeInMintues to Time#to_minutes
20
+ * (8854df7) Refactored currentTimeInMintues to Time#to_minutes
21
+ * (d485e0f) Removed currentTimeFormatted and timeToMinutes
8
22
 
9
23
  ## v0.0.1 (2012-04-26)
10
24
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Trak: track chunks of time from the command line
2
2
 
3
- Trak, v0.0.2 (Apr 26, 2012)
3
+ Trak, v0.0.3 (Apr 30, 2012)
4
4
  Written by Adam Sharp
5
5
 
6
6
  ## Notice
data/lib/trak.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # command:
4
- # $ Tracker.pl 30 "I did stuff"
5
- # $ Tracker.pl 1h "I did twice as much stuff"
4
+ # $ trak 30 work on trak
5
+ # $ trak 1h work really hard on trak
6
6
  #
7
7
  # format:
8
8
  # - First arg is how much time spent
@@ -11,8 +11,9 @@
11
11
  require 'trollop'
12
12
  require 'debugger'
13
13
 
14
- require "trak/tracker_util"
15
- require 'trak/time'
14
+ require 'trak/trak'
15
+ require 'trak/exit'
16
+ require 'trak/core_ext/time'
16
17
 
17
18
  # place where data is stored
18
19
  datadir = "#{ENV['HOME']}/Documents/Tracker/"
@@ -28,7 +29,7 @@ end
28
29
 
29
30
  $g_opts = opts
30
31
  def debug(steps = 1)
31
- debugger if $g_opts[:debug]
32
+ debugger(steps) if $g_opts[:debug]
32
33
  end
33
34
 
34
35
  # all valid options have been processed, so figure out which mode
@@ -70,8 +71,7 @@ if MODE == 'report'
70
71
  begin
71
72
  file = File.open(filename).readlines.map &:chomp
72
73
  rescue
73
- STDERR.puts "#{__FILE__}: #{$!}"
74
- exit 1
74
+ Exit::exit_err "#{__FILE__}: #{$!}"
75
75
  end
76
76
 
77
77
  # The keys for each hash are the titles of the various tasks logged.
@@ -101,14 +101,14 @@ if MODE == 'report'
101
101
  puts "# Today's logged work"
102
102
  end
103
103
 
104
- workTotal = TrackerUtil::printSubReport(work, "Work")
105
- personalTotal = TrackerUtil::printSubReport(personal, "Personal")
104
+ workTotal = Trak::printSubReport(work, "Work")
105
+ personalTotal = Trak::printSubReport(personal, "Personal")
106
106
 
107
- newTimeString = TrackerUtil::to12HourTime(TrackerUtil::newTimeWithMinutes(startTime, workTotal + personalTotal))
108
- puts "Hours logged until #{newTimeString} (since #{TrackerUtil::to12HourTime(startTime)}). "
107
+ newTimeString = Trak::to12HourTime(Trak::newTimeWithMinutes(startTime, workTotal + personalTotal))
108
+ puts "Hours logged until #{newTimeString} (since #{Trak::to12HourTime(startTime)}). "
109
109
 
110
110
  # if we're reporting for today, print the current time
111
- puts "Currently #{TrackerUtil::to12HourTime(Time.now.strftime(TrackerUtil::TIME_FORMAT_24HOUR))}." unless opts[:date]
111
+ puts "Currently #{Trak::to12HourTime(Time.now.strftime(Trak::TIME_FORMAT_24HOUR))}." unless opts[:date]
112
112
  else
113
113
  if opts[:date]
114
114
  STDERR.puts "No time log for #{fdate}. Track some time first."
@@ -126,8 +126,7 @@ elsif MODE == 'edit'
126
126
  end
127
127
  exit
128
128
  else
129
- STDERR.puts "#{__FILE__}: #{filename} does not exist or unable to open."
130
- exit 1
129
+ Exit::exit_err "#{__FILE__}: #{filename} does not exist or unable to open."
131
130
  end
132
131
 
133
132
  elsif MODE == 'insert'
@@ -136,14 +135,13 @@ elsif MODE == 'insert'
136
135
  print "Continue? (y/n) "
137
136
  input = STDIN.readline.chomp
138
137
  unless input =~ /^y(es)?/i
139
- STDERR.puts "Timelog update cancelled."
140
- exit 1
138
+ Exit::exit_err "Timelog update cancelled."
141
139
  end
142
140
  end
143
141
 
144
142
  # process arguments
145
143
  debug
146
- minutes = TrackerUtil::processTimeArgument ARGV.shift
144
+ minutes = Trak::processTimeArgument ARGV.shift
147
145
  message = ARGV.join(" ")
148
146
 
149
147
  # open the output file
@@ -154,17 +152,15 @@ elsif MODE == 'insert'
154
152
  if first_time
155
153
  debug
156
154
  currentTimeInMinutes = Time.now.to_minutes
157
- startTime = TrackerUtil::minutesToTime((currentTimeInMinutes - minutes).round_to_nearest 15)
155
+ startTime = Trak::minutesToTime((currentTimeInMinutes - minutes).round_to_nearest 15)
158
156
  file.puts "#{fdate} #{startTime}"
159
157
  end
160
158
  file.puts "#{minutes}: #{message}"
161
159
  end
162
160
  rescue
163
- STDERR.puts "Couldn't open #{filename}: #{$!}"
164
- exit 1
161
+ Exit::exit_err "Couldn't open #{filename}: #{$!}"
165
162
  end
166
163
 
167
164
  else
168
- STDERR.puts "Couldn't determine the correct mode (I was given '#{MODE}'): #{$!}"
169
- exit 1
165
+ Exit::exit_err "Couldn't determine the correct mode (I was given '#{MODE}'): #{$!}"
170
166
  end
File without changes
@@ -7,3 +7,13 @@ class Integer
7
7
  end
8
8
  end
9
9
  end
10
+
11
+ class Float
12
+ def round_to_nearest(integer = 1)
13
+ if integer == 1
14
+ self.round
15
+ else
16
+ ((self / integer).round * integer).to_i
17
+ end
18
+ end
19
+ end
File without changes
data/lib/trak/exit.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Exit
2
+ EXIT_ERR = 1
3
+
4
+ def self.exit_err(message)
5
+ STDERR.puts message
6
+ exit EXIT_ERR
7
+ end
8
+ end
@@ -1,7 +1,7 @@
1
- require "trak/blank"
2
- require "trak/round_to_nearest"
1
+ require "trak/core_ext/blank"
2
+ require "trak/core_ext/round_to_nearest"
3
3
 
4
- module TrackerUtil
4
+ module Trak
5
5
  TIME_FORMAT_12HOUR = "%l:%M %p"
6
6
  TIME_FORMAT_24HOUR = "%k:%M"
7
7
 
@@ -63,7 +63,7 @@ module TrackerUtil
63
63
  # returns a number of minutes
64
64
  def self.processTimeArgument(time_string)
65
65
  if time_string =~ /^(\d*\.?\d+)((m|min|minute|minutes)|(h|hr|hour|hours))?$/i
66
- time = $1.to_i
66
+ time = $1.to_f
67
67
  modifier = $2
68
68
  minutes = (modifier =~ /h.*/) ? time * 60 : time
69
69
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-25 00:00:00.000000000 Z
12
+ date: 2012-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
@@ -49,10 +49,11 @@ executables:
49
49
  extensions: []
50
50
  extra_rdoc_files: []
51
51
  files:
52
- - lib/trak/blank.rb
53
- - lib/trak/round_to_nearest.rb
54
- - lib/trak/time.rb
55
- - lib/trak/tracker_util.rb
52
+ - lib/trak/core_ext/blank.rb
53
+ - lib/trak/core_ext/round_to_nearest.rb
54
+ - lib/trak/core_ext/time.rb
55
+ - lib/trak/exit.rb
56
+ - lib/trak/trak.rb
56
57
  - lib/trak.rb
57
58
  - bin/trak
58
59
  - CHANGELOG.md