one_inch_punch 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.4.2 2010-08-16
2
+
3
+ * 1 tiny enhancement:
4
+ * adding some date handling for list/total/summary:
5
+ * can now take an :on option, to restrict the operation to the given date
6
+ * option can be given on command-line with --on
7
+ * :before and :after can also take dates now, converting them to times
8
+
1
9
  == 0.4.1 2008-08-26
2
10
 
3
11
  * 1 tiny enhancement:
data/bin/punch CHANGED
@@ -29,6 +29,8 @@ BANNER
29
29
  "Restrict command to only after the given time") { |time| OPTIONS[:after] = Time.parse(time) }
30
30
  opts.on('--before [TIME]', String,
31
31
  "Restrict command to only before the given time") { |time| OPTIONS[:before] = Time.parse(time) }
32
+ opts.on('--on [DATE]', String,
33
+ "Restrict command to only on the given date") { |date| OPTIONS[:on] = Date.parse(date) }
32
34
  opts.on('--at [TIME]', '--time [TIME]', String,
33
35
  "Use the given time") { |time| OPTIONS[:time] = Time.parse(time) }
34
36
  opts.on('-m', '--message [MESSAGE]', String,
data/config/hoe.rb CHANGED
@@ -8,7 +8,7 @@ RUBYFORGE_PROJECT = 'yomendel' # The unix name for your project
8
8
  HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
9
  DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
10
  EXTRA_DEPENDENCIES = [
11
- # ['activesupport', '>= 1.3.1']
11
+ ['timely', '>= 0.0.1']
12
12
  ] # An array of rubygem dependencies [name, version]
13
13
  EXTRA_DEV_DEPENDENCIES = [
14
14
  ['bacon', '>= 1.1.0'],
data/lib/punch/version.rb CHANGED
@@ -2,7 +2,7 @@ class Punch
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/punch.rb CHANGED
@@ -3,6 +3,8 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
  require 'yaml'
5
5
  require 'time'
6
+ require 'date'
7
+ require 'timely'
6
8
  require 'enumerator'
7
9
  require 'punch/core_ext'
8
10
  require 'punch/instance'
@@ -193,6 +195,7 @@ class Punch
193
195
 
194
196
  def do_list_single(project, options)
195
197
  return nil unless project_data = data[project]
198
+ options = fix_range_options(options)
196
199
  project_data = project_data.select { |t| t['in'] > options[:after] } if options[:after]
197
200
  project_data = project_data.select { |t| (t['out'] || Time.now) < options[:before] } if options[:before]
198
201
  project_data
@@ -209,6 +212,16 @@ class Punch
209
212
  options[:time] || options[:at] || Time.now
210
213
  end
211
214
 
215
+ def fix_range_options(options)
216
+ if date = options[:on]
217
+ options[:after] = date
218
+ options[:before] = date + 1
219
+ end
220
+ [:after, :before].each { |k| options[k] = options[k].at_time(0) if options[k].respond_to?(:at_time) }
221
+
222
+ options
223
+ end
224
+
212
225
  def projects
213
226
  data.keys
214
227
  end
@@ -117,6 +117,16 @@ describe 'punch command' do
117
117
  run_command('total', '--before', time_option)
118
118
  end
119
119
 
120
+ it "should pass on an 'on' date option given by --on" do
121
+ date_option = '2008-08-23'
122
+ date = Date.new(2008, 8, 23)
123
+ Punch.should.receive(:total) do |proj, options|
124
+ proj.should == @project
125
+ options[:on].should == date
126
+ end
127
+ run_command('total', @project, '--on', date_option)
128
+ end
129
+
120
130
  it 'should also pass the formatting option' do
121
131
  time_option = '2008-08-26 09:47'
122
132
  Punch.should.receive(:total) do |proj, options|
@@ -722,6 +732,16 @@ describe 'punch command' do
722
732
  end
723
733
  run_command('list', '--before', time_option)
724
734
  end
735
+
736
+ it "should pass on an 'on' date option given by --on" do
737
+ date_option = '2008-08-23'
738
+ date = Date.new(2008, 8, 23)
739
+ Punch.should.receive(:list) do |proj, options|
740
+ proj.should == @project
741
+ options[:on].should == date
742
+ end
743
+ run_command('list', @project, '--on', date_option)
744
+ end
725
745
  end
726
746
 
727
747
  it 'should not write the data' do
@@ -785,6 +805,16 @@ describe 'punch command' do
785
805
  run_command('summary', @project, '--before', time_option)
786
806
  end
787
807
 
808
+ it "should pass on an 'on' date option given by --on" do
809
+ date_option = '2008-08-23'
810
+ date = Date.new(2008, 8, 23)
811
+ Punch.should.receive(:summary) do |proj, options|
812
+ proj.should == @project
813
+ options[:on].should == date
814
+ end
815
+ run_command('summary', @project, '--on', date_option)
816
+ end
817
+
788
818
  it 'should also pass the formatting option' do
789
819
  time_option = '2008-08-23'
790
820
  Punch.should.receive(:summary) do |proj, options|
@@ -816,7 +846,7 @@ describe 'punch command' do
816
846
  run_command('summary')
817
847
  end
818
848
 
819
- it 'should not punch in' do
849
+ it 'should not get a summary' do
820
850
  Punch.should.receive(:summary).never
821
851
  run_command('summary')
822
852
  end
data/spec/punch_spec.rb CHANGED
@@ -1085,6 +1085,48 @@ describe Punch do
1085
1085
  Punch.list(@project, :after => @now - 2001, :before => @now - 999).should == Punch.data[@project][1, 1]
1086
1086
  end
1087
1087
 
1088
+ describe 'handling date options' do
1089
+ before do
1090
+ # yay ugly setup!
1091
+ @date = Date.today - 4
1092
+ morning = Time.local(@date.year, @date.month, @date.day, 0, 0, 1)
1093
+ night = Time.local(@date.year, @date.month, @date.day, 23, 59, 59)
1094
+ earlier_date = @date - 2
1095
+ earlier_time = Time.local(earlier_date.year, earlier_date.month, earlier_date.day, 13, 43)
1096
+ early_date = @date - 1
1097
+ early_time = Time.local(early_date.year, early_date.month, early_date.day, 11, 25)
1098
+ later_date = @date + 1
1099
+ later_time = Time.local(later_date.year, later_date.month, later_date.day, 3, 12)
1100
+
1101
+ @data = { @project => [
1102
+ {'in' => earlier_time - 50, 'out' => earlier_time + 100},
1103
+ {'in' => early_time - 60, 'out' => early_time + 70},
1104
+ {'in' => morning, 'out' => morning + 200},
1105
+ {'in' => night - 500, 'out' => night},
1106
+ {'in' => later_time - 30, 'out' => later_time + 70}
1107
+ ]
1108
+ }
1109
+
1110
+ Punch.data = @data
1111
+ end
1112
+
1113
+ it 'should accept an :on shortcut option to restrict returned data to times only on a certain day' do
1114
+ Punch.list(@project, :on => @date).should == Punch.data[@project][2, 2]
1115
+ end
1116
+
1117
+ it 'should allow the :on option to override the before/after options' do
1118
+ Punch.list(@project, :on => @date, :before => @now - 2525, :after => @now - 7575).should == Punch.data[@project][2, 2]
1119
+ end
1120
+
1121
+ it 'should allow the :after option to be a date instead of time' do
1122
+ Punch.list(@project, :after => @date).should == Punch.data[@project][2..-1]
1123
+ end
1124
+
1125
+ it 'should allow the :before option to be a date instead of time' do
1126
+ Punch.list(@project, :before => @date).should == Punch.data[@project][0, 2]
1127
+ end
1128
+ end
1129
+
1088
1130
  describe 'and is punched in' do
1089
1131
  before do
1090
1132
  @data[@project].push({ 'in' => @now - 25 })
@@ -1242,6 +1284,48 @@ describe Punch do
1242
1284
  Punch.total(@project, :format => true).should == "1:05:00"
1243
1285
  end
1244
1286
 
1287
+ describe 'handling date options' do
1288
+ before do
1289
+ # yay ugly setup!
1290
+ @date = Date.today - 4
1291
+ morning = Time.local(@date.year, @date.month, @date.day, 0, 0, 1)
1292
+ night = Time.local(@date.year, @date.month, @date.day, 23, 59, 59)
1293
+ earlier_date = @date - 2
1294
+ earlier_time = Time.local(earlier_date.year, earlier_date.month, earlier_date.day, 13, 43)
1295
+ early_date = @date - 1
1296
+ early_time = Time.local(early_date.year, early_date.month, early_date.day, 11, 25)
1297
+ later_date = @date + 1
1298
+ later_time = Time.local(later_date.year, later_date.month, later_date.day, 3, 12)
1299
+
1300
+ @data = { @project => [
1301
+ {'in' => earlier_time - 50, 'out' => earlier_time + 100},
1302
+ {'in' => early_time - 60, 'out' => early_time + 70},
1303
+ {'in' => morning, 'out' => morning + 200},
1304
+ {'in' => night - 500, 'out' => night},
1305
+ {'in' => later_time - 30, 'out' => later_time + 70}
1306
+ ]
1307
+ }
1308
+
1309
+ Punch.data = @data
1310
+ end
1311
+
1312
+ it 'should accept an :on shortcut option to restrict returned amount to times only on a certain day' do
1313
+ Punch.total(@project, :on => @date).should == 700
1314
+ end
1315
+
1316
+ it 'should allow the :on option to override the before/after options' do
1317
+ Punch.total(@project, :on => @date, :before => @now - 2525, :after => @now - 7575).should == 700
1318
+ end
1319
+
1320
+ it 'should allow the :after option to be a date instead of time' do
1321
+ Punch.total(@project, :after => @date).should == 800
1322
+ end
1323
+
1324
+ it 'should allow the :before option to be a date instead of time' do
1325
+ Punch.total(@project, :before => @date).should == 280
1326
+ end
1327
+ end
1328
+
1245
1329
  describe 'and is punched in' do
1246
1330
  before do
1247
1331
  @data[@project].push({ 'in' => @now - 25 })
@@ -1599,6 +1683,48 @@ describe Punch do
1599
1683
  it 'should format the time spent if passed a format option' do
1600
1684
  Punch.summary(@project, :format => true).should == { 'unspecified' => '03:20', @message => '01:40', @other_message => '05:00' }
1601
1685
  end
1686
+
1687
+ describe 'handling date options' do
1688
+ before do
1689
+ # yay ugly setup!
1690
+ @date = Date.today - 4
1691
+ morning = Time.local(@date.year, @date.month, @date.day, 0, 0, 1)
1692
+ night = Time.local(@date.year, @date.month, @date.day, 23, 59, 59)
1693
+ earlier_date = @date - 2
1694
+ earlier_time = Time.local(earlier_date.year, earlier_date.month, earlier_date.day, 13, 43)
1695
+ early_date = @date - 1
1696
+ early_time = Time.local(early_date.year, early_date.month, early_date.day, 11, 25)
1697
+ later_date = @date + 1
1698
+ later_time = Time.local(later_date.year, later_date.month, later_date.day, 3, 12)
1699
+
1700
+ @data = { @project => [
1701
+ {'in' => earlier_time - 50, 'out' => earlier_time + 100},
1702
+ {'in' => early_time - 60, 'out' => early_time + 70},
1703
+ {'in' => morning, 'out' => morning + 200},
1704
+ {'in' => night - 500, 'out' => night},
1705
+ {'in' => later_time - 30, 'out' => later_time + 70}
1706
+ ]
1707
+ }
1708
+
1709
+ Punch.data = @data
1710
+ end
1711
+
1712
+ it 'should accept an :on shortcut option to restrict the summary to times only on a certain day' do
1713
+ Punch.summary(@project, :on => @date).should == { 'unspecified' => 700 }
1714
+ end
1715
+
1716
+ it 'should allow the :on option to override the before/after options' do
1717
+ Punch.summary(@project, :on => @date, :before => @now - 2525, :after => @now - 7575).should == { 'unspecified' => 700 }
1718
+ end
1719
+
1720
+ it 'should allow the :after option to be a date instead of time' do
1721
+ Punch.summary(@project, :after => @date).should == { 'unspecified' => 800 }
1722
+ end
1723
+
1724
+ it 'should allow the :before option to be a date instead of time' do
1725
+ Punch.summary(@project, :before => @date).should == { 'unspecified' => 280 }
1726
+ end
1727
+ end
1602
1728
  end
1603
1729
 
1604
1730
  describe 'when the project is currently punched in' do
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one_inch_punch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ hash: 11
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 2
10
+ version: 0.4.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - Yossef Mendelssohn
@@ -9,39 +15,73 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-08-26 00:00:00 -05:00
18
+ date: 2010-08-16 00:00:00 -05:00
13
19
  default_executable:
14
20
  dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: timely
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 29
30
+ segments:
31
+ - 0
32
+ - 0
33
+ - 1
34
+ version: 0.0.1
35
+ type: :runtime
36
+ version_requirements: *id001
15
37
  - !ruby/object:Gem::Dependency
16
38
  name: bacon
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
20
42
  requirements:
21
43
  - - ">="
22
44
  - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 1
48
+ - 1
49
+ - 0
23
50
  version: 1.1.0
24
- version:
51
+ type: :development
52
+ version_requirements: *id002
25
53
  - !ruby/object:Gem::Dependency
26
54
  name: facon
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
30
58
  requirements:
31
59
  - - ">="
32
60
  - !ruby/object:Gem::Version
61
+ hash: 13
62
+ segments:
63
+ - 0
64
+ - 4
65
+ - 1
33
66
  version: 0.4.1
34
- version:
67
+ type: :development
68
+ version_requirements: *id003
35
69
  - !ruby/object:Gem::Dependency
36
70
  name: hoe
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
40
74
  requirements:
41
75
  - - ">="
42
76
  - !ruby/object:Gem::Version
43
- version: 2.3.3
44
- version:
77
+ hash: 21
78
+ segments:
79
+ - 2
80
+ - 6
81
+ - 1
82
+ version: 2.6.1
83
+ type: :development
84
+ version_requirements: *id004
45
85
  description: a simple time-tracking tool
46
86
  email:
47
87
  - ymendel@pobox.com
@@ -91,21 +131,27 @@ rdoc_options:
91
131
  require_paths:
92
132
  - lib
93
133
  required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
94
135
  requirements:
95
136
  - - ">="
96
137
  - !ruby/object:Gem::Version
138
+ hash: 3
139
+ segments:
140
+ - 0
97
141
  version: "0"
98
- version:
99
142
  required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
100
144
  requirements:
101
145
  - - ">="
102
146
  - !ruby/object:Gem::Version
147
+ hash: 3
148
+ segments:
149
+ - 0
103
150
  version: "0"
104
- version:
105
151
  requirements: []
106
152
 
107
153
  rubyforge_project: yomendel
108
- rubygems_version: 1.3.5
154
+ rubygems_version: 1.3.7
109
155
  signing_key:
110
156
  specification_version: 3
111
157
  summary: a simple time-tracking tool