one_inch_punch 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.3.3 2008-06-25
2
+
3
+ * 1 tiny enhancement:
4
+ * added 'short' status, which only displays what's currently punched in (or 'out' if nothing)
5
+ * punch command displays status as YAML if it's a hash, like it does for total
6
+
1
7
  == 0.3.2 2008-06-01
2
8
 
3
9
  * 1 tiny bugfix enhancement:
data/bin/punch CHANGED
@@ -35,6 +35,8 @@ BANNER
35
35
  "Add the given log message when punching in/out") { |message| OPTIONS[:message] = message }
36
36
  opts.on('--full',
37
37
  "Show full output for the command") { |full| OPTIONS[:full] = true }
38
+ opts.on('--short',
39
+ "Show short output for the command") { |full| OPTIONS[:short] = true }
38
40
  opts.on("-h", "--help",
39
41
  "Show this help message.") { puts opts; exit }
40
42
  opts.parse!(ARGV)
@@ -58,7 +60,7 @@ Punch.load
58
60
  commands = {
59
61
  'status' => lambda do |project|
60
62
  result = Punch.status(project, OPTIONS)
61
- if project.nil? or OPTIONS[:full]
63
+ if result.is_a?(Hash)
62
64
  puts result.to_yaml
63
65
  else
64
66
  puts result.inspect
data/lib/punch/version.rb CHANGED
@@ -2,7 +2,7 @@ class Punch
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/punch.rb CHANGED
@@ -45,7 +45,15 @@ class Punch
45
45
  project = nil
46
46
  end
47
47
 
48
- return projects.inject({}) { |hash, project| hash.merge(project => status(project, options)) } unless project
48
+ unless project
49
+ stats = {}
50
+ projects.each { |project| stats[project] = status(project, options) }
51
+ if options[:short]
52
+ stats.reject! { |k, v| v != 'in' }
53
+ stats = 'out' if stats.empty?
54
+ end
55
+ return stats
56
+ end
49
57
 
50
58
  project_data = data[project]
51
59
  time_data = (project_data || []).last
@@ -163,8 +163,8 @@ describe 'punch command' do
163
163
  run_command('status', @project)
164
164
  end
165
165
 
166
- it 'should output the status as YAML if no project given' do
167
- result = 'status data'
166
+ it "should output the status as YAML if the status data is a Hash" do
167
+ result = { 'status' => 'data' }
168
168
  Punch.stub!(:status).and_return(result)
169
169
  self.should.receive(:puts).with(result.to_yaml)
170
170
  run_command('status')
@@ -180,18 +180,14 @@ describe 'punch command' do
180
180
  run_command('status', '--full')
181
181
  end
182
182
 
183
- it 'should output the status as YAML if a full option is given' do
184
- result = 'status data'
185
- Punch.stub!(:status).and_return(result)
186
- self.should.receive(:puts).with(result.to_yaml)
187
- run_command('status', @project, '--full')
183
+ it 'should pass a true short option if specified on the command line (with --short)' do
184
+ Punch.should.receive(:status).with(@project, :short => true)
185
+ run_command('status', @project, '--short')
188
186
  end
189
187
 
190
- it 'should output the status as YAML if no project given even if a full option is given' do
191
- result = 'status data'
192
- Punch.stub!(:status).and_return(result)
193
- self.should.receive(:puts).with(result.to_yaml)
194
- run_command('status', '--full')
188
+ it 'should pass a true short option if specified on the command line (with --short) and no project given' do
189
+ Punch.should.receive(:status).with(nil, :short => true)
190
+ run_command('status', '--short')
195
191
  end
196
192
 
197
193
  it 'should not write the data' do
data/spec/punch_spec.rb CHANGED
@@ -235,12 +235,77 @@ describe Punch do
235
235
  }
236
236
  end
237
237
 
238
- it 'should return the full status if all projects if no project given' do
238
+ it 'should return the full status of all projects if no project given' do
239
239
  Punch.status(:full => true).should == {
240
240
  @projects['out'] => { :status => 'out', :time => @now + 12 },
241
241
  @projects['in'] => { :status => 'in', :time => @now }
242
242
  }
243
243
  end
244
+
245
+ describe 'when given a :short option' do
246
+ it "should return 'in' if the project is currently punched in" do
247
+ Punch.status(@projects['in'], :short => true).should == 'in'
248
+ end
249
+
250
+ it "should return 'out' if the project is currently punched out" do
251
+ Punch.status(@projects['out'], :short => true).should == 'out'
252
+ end
253
+
254
+ it 'should return nil if project does not exist' do
255
+ Punch.status('other project', :short => true).should.be.nil
256
+ end
257
+
258
+ describe 'handling multiple projects' do
259
+ before do
260
+ @projects['in2'] = 'bingbang'
261
+ @projects['out2'] = 'boopadope'
262
+ @data[@projects['in2']] = [ { 'in' => @now - 5 } ]
263
+ @data[@projects['out2']] = [ { 'in' => @now - 500, 'out' => @now - 20 } ]
264
+ Punch.data = @data
265
+ end
266
+
267
+ it 'should return just the punched-in projects if nil is given as the project' do
268
+ Punch.status(nil, :short => true).should == {
269
+ @projects['in'] => 'in',
270
+ @projects['in2'] => 'in'
271
+ }
272
+ end
273
+
274
+ it 'should return just the punched-in projects if no project given' do
275
+ Punch.status(:short => true).should == {
276
+ @projects['in'] => 'in',
277
+ @projects['in2'] => 'in'
278
+ }
279
+ end
280
+
281
+ it 'should not include empty projects' do
282
+ @data['empty_project'] = []
283
+ Punch.data = @data
284
+
285
+ Punch.status(:short => true).should == {
286
+ @projects['in'] => 'in',
287
+ @projects['in2'] => 'in'
288
+ }
289
+ end
290
+
291
+ it "should return 'out' if all projects are punched out" do
292
+ @data.delete(@projects['in'])
293
+ @data.delete(@projects['in2'])
294
+ Punch.data = @data
295
+
296
+ Punch.status(:short => true).should == 'out'
297
+ end
298
+
299
+ it "should return 'out' if all projects are punched out or empty" do
300
+ @data.delete(@projects['in'])
301
+ @data.delete(@projects['in2'])
302
+ @data['empty_project'] = []
303
+ Punch.data = @data
304
+
305
+ Punch.status(:short => true).should == 'out'
306
+ end
307
+ end
308
+ end
244
309
  end
245
310
 
246
311
  describe 'handling a sub-project' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one_inch_punch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yossef Mendelssohn
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-01 00:00:00 -05:00
12
+ date: 2009-06-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  requirements: []
106
106
 
107
107
  rubyforge_project: yomendel
108
- rubygems_version: 1.3.3
108
+ rubygems_version: 1.3.4
109
109
  signing_key:
110
110
  specification_version: 3
111
111
  summary: a simple time-tracking tool