pretty_time 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -37,14 +37,14 @@ class PrettyTime
37
37
 
38
38
  # Creates a new configuration instance
39
39
  def self.config
40
- @config ||= PrettyTime::Configuration.new
40
+ @config ||= PrettyTime::Configuration.new
41
41
  end
42
-
42
+
43
43
  # Parent Class for unit's of time
44
44
  # for exaple: Hours, Minutes and Seconds
45
45
  class UnitOfTime
46
46
  attr_accessor :value
47
-
47
+
48
48
  def initialize(value)
49
49
  @value = value
50
50
  end
@@ -212,15 +212,16 @@ class PrettyTime
212
212
  # match_it("4 hrs 1 min")
213
213
  #
214
214
  def match_it(time_as_pretty_string)
215
- /^(\d+) (hours?) (\d+) (minutes?) (\d+) (seconds?)/.match(time_as_pretty_string) ||
216
- /^(\d+) (hours?) (\d+) (minutes?)/.match(time_as_pretty_string) ||
217
- /^(\d+) (minutes?) (\d+) (seconds?)/.match(time_as_pretty_string) ||
218
- /^(\d+) (hours?) (\d+) (seconds?)/.match(time_as_pretty_string) ||
215
+ /^(\d+) (hours?|hrs?|h) (\d+) (minutes?|mins?|m) (\d+) (seconds?|secs?|s)/.match(time_as_pretty_string) ||
216
+ /^(\d+) (hours?|hrs?|h) (\d+) (minutes?|mins?|m)/.match(time_as_pretty_string) ||
217
+ /^(\d+) (minutes?|mins?|m) (\d+) (seconds?|secs?|s)/.match(time_as_pretty_string) ||
218
+ /^(\d+) (hours?|hrs?|h) (\d+) (seconds?|secs?|s)/.match(time_as_pretty_string) ||
219
+
219
220
  /^(\d+)( h| m| s)/.match(time_as_pretty_string) ||
220
221
  /^(\d+)( hours?| minutes?| seconds?)/.match(time_as_pretty_string) ||
221
222
  /^(\d+)( hrs?| mins?| secs?)/.match(time_as_pretty_string)
222
223
  end
223
-
224
+
224
225
  alias :has_hours? :non_zero?
225
226
  alias :has_minutes? :non_zero?
226
227
  alias :has_seconds? :non_zero?
data/pretty_time.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pretty_time}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Anuj Dutta"]
12
- s.date = %q{2011-05-15}
12
+ s.date = %q{2011-05-29}
13
13
  s.description = %q{Serializes time to pretty time string and vica-versa}
14
14
  s.email = %q{anuj@andhapp.com}
15
15
  s.extra_rdoc_files = [
@@ -4,108 +4,216 @@ describe "PrettyTime" do
4
4
 
5
5
  context "On request to #dump" do
6
6
 
7
- it 'should convert A hours to X seconds' do
8
- PrettyTime.dump("4 hours").should == 4.hours.to_i
9
- end
7
+ context "with hours, minutes and seconds as suffixes" do
8
+ it 'should convert A hours to X seconds' do
9
+ PrettyTime.dump("4 hours").should == 4.hours.to_i
10
+ end
10
11
 
11
- it 'should convert B minutes to X seconds' do
12
- PrettyTime.dump("40 minutes").should == 40.minutes.to_i
13
- end
12
+ it 'should convert B minutes to X seconds' do
13
+ PrettyTime.dump("40 minutes").should == 40.minutes.to_i
14
+ end
14
15
 
15
- it 'should return X seconds as X seconds' do
16
- PrettyTime.dump("40 seconds").should == 40
17
- end
16
+ it 'should return X seconds as X seconds' do
17
+ PrettyTime.dump("40 seconds").should == 40
18
+ end
18
19
 
19
- it 'should convert A hours B minutes to X seconds' do
20
- PrettyTime.dump("4 hours 40 minutes").should == 4.hours.to_i + 40.minutes.to_i
21
- end
20
+ it 'should convert A hours B minutes to X seconds' do
21
+ PrettyTime.dump("4 hours 40 minutes").should == 4.hours.to_i + 40.minutes.to_i
22
+ end
22
23
 
23
- it 'should convert B minutes C seconds to X seconds' do
24
- PrettyTime.dump("40 minutes 30 seconds").should == 40.minutes.to_i + 30
25
- end
24
+ it 'should convert B minutes C seconds to X seconds' do
25
+ PrettyTime.dump("40 minutes 30 seconds").should == 40.minutes.to_i + 30
26
+ end
26
27
 
27
- it 'should convert A hours C seconds to X seconds' do
28
- PrettyTime.dump("4 hours 30 seconds").should == 4.hours.to_i + 30
29
- end
28
+ it 'should convert A hours C seconds to X seconds' do
29
+ PrettyTime.dump("4 hours 30 seconds").should == 4.hours.to_i + 30
30
+ end
30
31
 
31
- it 'should convert A hours B minutes C seconds to X seconds' do
32
- PrettyTime.dump("4 hours 40 minutes 30 seconds").should == 4.hours.to_i + 40.minutes.to_i + 30
32
+ it 'should convert A hours B minutes C seconds to X seconds' do
33
+ PrettyTime.dump("4 hours 40 minutes 30 seconds").should == 4.hours.to_i + 40.minutes.to_i + 30
34
+ end
33
35
  end
34
36
 
35
- it 'should convert A hrs to X seconds' do
36
- PrettyTime.dump("4 hrs").should == 4.hours.to_i
37
- end
37
+ context "with hrs, mins and secs as suffixes" do
38
+ it 'should convert A hrs to X seconds' do
39
+ PrettyTime.dump("4 hrs").should == 4.hours.to_i
40
+ end
38
41
 
39
- it 'should convert B mins to X seconds' do
40
- PrettyTime.dump("4 mins").should == 4.minutes.to_i
41
- end
42
-
43
- it 'should convert C secs to X seconds' do
44
- PrettyTime.dump("4 secs").should == 4
45
- end
42
+ it 'should convert B mins to X seconds' do
43
+ PrettyTime.dump("4 mins").should == 4.minutes.to_i
44
+ end
46
45
 
47
- it 'should convert A h to X seconds' do
48
- PrettyTime.dump("4 h").should == 4.hours.to_i
49
- end
46
+ it 'should convert C secs to X seconds' do
47
+ PrettyTime.dump("4 secs").should == 4
48
+ end
50
49
 
51
- it 'should convert B m to X seconds' do
52
- PrettyTime.dump("4 m").should == 4.minutes.to_i
53
- end
54
-
55
- it 'should convert C s to X seconds' do
56
- PrettyTime.dump("4 s").should == 4
50
+ it 'should convert A hrs B mins to X seconds' do
51
+ PrettyTime.dump("4 hrs 40 mins").should == 4.hours.to_i + 40.minutes.to_i
52
+ end
53
+
54
+ it 'should convert B mins C secs to X seconds' do
55
+ PrettyTime.dump("4 mins 40 secs").should == 4.minutes.to_i + 40
56
+ end
57
+
58
+ it 'should convert A hrs C secs to X seconds' do
59
+ PrettyTime.dump("4 hrs 40 secs").should == 4.hours.to_i + 40
60
+ end
61
+
62
+ it 'should convert A hrs B mins C secs to X seconds' do
63
+ PrettyTime.dump("4 hrs 40 mins 30 secs").should == 4.hours.to_i + 40.minutes.to_i + 30
64
+ end
57
65
  end
58
-
59
- context "with fence post cases" do
60
66
 
61
- it 'should convert 1 hour to 3600 seconds' do
62
- PrettyTime.dump("1 hour").should == 3600
67
+ context "with h, m and s as suffixes" do
68
+ it 'should convert A h to X seconds' do
69
+ PrettyTime.dump("4 h").should == 4.hours.to_i
63
70
  end
64
71
 
65
- it 'should convert 1 minute to 60 seconds' do
66
- PrettyTime.dump("1 minute").should == 60
72
+ it 'should convert B m to X seconds' do
73
+ PrettyTime.dump("4 m").should == 4.minutes.to_i
67
74
  end
68
75
 
69
- it 'should return 1 second as 1 second' do
70
- PrettyTime.dump("1 second").should == 1
76
+ it 'should convert C s to X seconds' do
77
+ PrettyTime.dump("4 s").should == 4
71
78
  end
72
79
 
73
- it 'should convert 1 hour 1 minute to 3660 seconds' do
74
- PrettyTime.dump("1 hour 1 minute").should == 3660
80
+ it 'should convert A h B m to X seconds' do
81
+ PrettyTime.dump("4 h 40 m").should == 4.hours.to_i + 40.minutes.to_i
75
82
  end
76
83
 
77
- it 'should convert 1 minute 1 second to 61 seconds' do
78
- PrettyTime.dump("1 minute 1 second").should == 61
84
+ it 'should convert B m C s to X seconds' do
85
+ PrettyTime.dump("4 m 40 s").should == 4.minutes.to_i + 40
79
86
  end
80
87
 
81
- it 'should convert 1 hour 1 minute 1 second to 3661 seconds' do
82
- PrettyTime.dump("1 hour 1 minute 1 second").should == 3661
88
+ it 'should convert A h C s to X seconds' do
89
+ PrettyTime.dump("4 h 40 s").should == 4.hours.to_i + 40
83
90
  end
84
91
 
85
- it 'should convert 1 hr to 3600 seconds' do
86
- PrettyTime.dump("1 hr").should == 1.hours.to_i
92
+ it 'should convert A h B m C s to X seconds' do
93
+ PrettyTime.dump("4 h 40 m 30 s").should == 4.hours.to_i + 40.minutes.to_i + 30
87
94
  end
95
+ end
88
96
 
89
- it 'should convert 1 min to 60 seconds' do
90
- PrettyTime.dump("1 min").should == 1.minutes.to_i
97
+ context "with mix-n-match suffixes like A hours B mins | A hrs B minutes" do
98
+ it 'should convert A hrs B minutes to X seconds' do
99
+ PrettyTime.dump("4 hrs 40 minutes").should == 4.hours.to_i + 40.minutes.to_i
91
100
  end
92
-
93
- it 'should convert 1 sec to 1 second' do
94
- PrettyTime.dump("1 sec").should == 1
101
+
102
+ it 'should convert A hrs B m to X seconds' do
103
+ PrettyTime.dump("4 hrs 40 m").should == 4.hours.to_i + 40.minutes.to_i
95
104
  end
96
105
 
97
- it 'should convert 1 hr to 3600 seconds' do
98
- PrettyTime.dump("1 h").should == 1.hours.to_i
106
+ it 'should convert A h B minutes to X seconds' do
107
+ PrettyTime.dump("4 h 40 minutes").should == 4.hours.to_i + 40.minutes.to_i
99
108
  end
109
+ end
110
+
111
+ context "with fence post cases" do
112
+
113
+ context "with hour, minute and second as suffixes" do
114
+ it 'should convert 1 hour to 3600 seconds' do
115
+ PrettyTime.dump("1 hour").should == 3600
116
+ end
100
117
 
101
- it 'should convert 1 min to 60 seconds' do
102
- PrettyTime.dump("1 m").should == 1.minutes.to_i
118
+ it 'should convert 1 minute to 60 seconds' do
119
+ PrettyTime.dump("1 minute").should == 60
120
+ end
121
+
122
+ it 'should return 1 second as 1 second' do
123
+ PrettyTime.dump("1 second").should == 1
124
+ end
125
+
126
+ it 'should convert 1 hour 1 minute to 3660 seconds' do
127
+ PrettyTime.dump("1 hour 1 minute").should == 3660
128
+ end
129
+
130
+ it 'should convert 1 minute 1 second to 61 seconds' do
131
+ PrettyTime.dump("1 minute 1 second").should == 61
132
+ end
133
+
134
+ it 'should convert 1 hour 1 second to 3601 seconds' do
135
+ PrettyTime.dump("1 hour 1 second").should == 3601
136
+ end
137
+
138
+ it 'should convert 1 hour 1 minute 1 second to 3661 seconds' do
139
+ PrettyTime.dump("1 hour 1 minute 1 second").should == 3661
140
+ end
103
141
  end
104
142
 
105
- it 'should convert 1 sec to 1 second' do
106
- PrettyTime.dump("1 s").should == 1
143
+ context "with hr, min and sec as suffixes" do
144
+ it 'should convert 1 hr to 3600 seconds' do
145
+ PrettyTime.dump("1 hr").should == 1.hours.to_i
146
+ end
147
+
148
+ it 'should convert 1 min to 60 seconds' do
149
+ PrettyTime.dump("1 min").should == 1.minutes.to_i
150
+ end
151
+
152
+ it 'should convert 1 sec to 1 second' do
153
+ PrettyTime.dump("1 sec").should == 1
154
+ end
155
+
156
+ it 'should convert 1 hr 1 min to 3660 seconds' do
157
+ PrettyTime.dump("1 hr 1 min").should == 3660
158
+ end
159
+
160
+ it 'should convert 1 min 1 sec to 61 seconds' do
161
+ PrettyTime.dump("1 min 1 sec").should == 61
162
+ end
163
+
164
+ it 'should convert 1 hr 1 sec to 3601 seconds' do
165
+ PrettyTime.dump("1 hr 1 sec").should == 3601
166
+ end
167
+
168
+ it 'should convert 1 hr 1 min 1 sec to 3661 seconds' do
169
+ PrettyTime.dump("1 hr 1 min 1 sec").should == 3661
170
+ end
107
171
  end
172
+
173
+ context "with h, m and s as suffixes" do
174
+ it 'should convert 1 h to 3600 seconds' do
175
+ PrettyTime.dump("1 h").should == 1.hours.to_i
176
+ end
177
+
178
+ it 'should convert 1 m to 60 seconds' do
179
+ PrettyTime.dump("1 m").should == 1.minutes.to_i
180
+ end
108
181
 
182
+ it 'should convert 1 s to 1 second' do
183
+ PrettyTime.dump("1 s").should == 1
184
+ end
185
+
186
+ it 'should convert 1 h 1 m to 3660 seconds' do
187
+ PrettyTime.dump("1 h 1 m").should == 3660
188
+ end
189
+
190
+ it 'should convert 1 m 1 s to 61 seconds' do
191
+ PrettyTime.dump("1 m 1 s").should == 61
192
+ end
193
+
194
+ it 'should convert 1 h 1 s to 3601 seconds' do
195
+ PrettyTime.dump("1 h 1 s").should == 3601
196
+ end
197
+
198
+ it 'should convert 1 h 1 m 1 s to 3661 seconds' do
199
+ PrettyTime.dump("1 h 1 m 1 s").should == 3661
200
+ end
201
+ end
202
+
203
+ context "with mix-n-match suffixes like A hours B mins | A hrs B minutes" do
204
+ it 'should convert 1 hr 10 minutes to 4200 seconds' do
205
+ PrettyTime.dump("1 hr 10 minutes").should == 1.hours.to_i + 10.minutes.to_i
206
+ end
207
+
208
+ it 'should convert 1 hrs 1 m to X seconds' do
209
+ PrettyTime.dump("1 hrs 1 m").should == 1.hour.to_i + 1.minute.to_i
210
+ end
211
+
212
+ it 'should convert 1 h 1 minutes to X seconds' do
213
+ PrettyTime.dump("1 h 1 minutes").should == 1.hour.to_i + 1.minute.to_i
214
+ end
215
+ end
216
+
109
217
  end
110
218
  end
111
219
 
@@ -206,7 +314,7 @@ describe "PrettyTime" do
206
314
  end
207
315
 
208
316
  context "with configuration defined" do
209
-
317
+
210
318
  it 'with hours_suffix as hrs and minutes and seconds as default should convert 3610 seconds to 1 hr 10 minutes' do
211
319
  PrettyTime.configuration do |config|
212
320
  config.hours_suffix = "hrs"
@@ -230,9 +338,9 @@ describe "PrettyTime" do
230
338
  end
231
339
  PrettyTime.load(2.hours.to_i + 10.minutes.to_i + 1).should == "2 hours 10 minutes 1 sec"
232
340
  end
233
-
341
+
234
342
  end
235
-
343
+
236
344
  end
237
345
 
238
346
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pretty_time
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Anuj Dutta
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-15 00:00:00 +01:00
13
+ date: 2011-05-29 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- hash: 423849249
119
+ hash: -716218381
120
120
  segments:
121
121
  - 0
122
122
  version: "0"