epitools 0.5.42 → 0.5.43
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/core_ext/numbers.rb +19 -17
- data/lib/epitools/core_ext/string.rb +6 -2
- data/spec/core_ext_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18aedb7dadd9b9a8cdfe9b619d228dc250ff2c0b
|
4
|
+
data.tar.gz: 41feba1a86b88e3f0790151ef815e5f1c1ebf680
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abf447f70c70e0b79f3b949a1faca4569f45325244dce43fffd1c139d94ff31c03151aec3368a6b18b8e528dec558572db31bc0385a993589297063fd7f6bf4f
|
7
|
+
data.tar.gz: 55c84b31bb1f3182ea56354649036df86add2c3d72c4a80aba726f8db7ee4ad01692fb523dd80d353fe3a0d10c0652f8b5a941f64f22cc642ead7a567a32e439
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.43
|
@@ -168,6 +168,25 @@ class Numeric
|
|
168
168
|
|
169
169
|
alias_method :human_size, :human_bytes
|
170
170
|
|
171
|
+
#
|
172
|
+
# Convert seconds to hours:minutes:seconds (hours is dropped if it's zero)
|
173
|
+
#
|
174
|
+
def to_hms
|
175
|
+
seconds = self
|
176
|
+
|
177
|
+
days, seconds = seconds.divmod(86400)
|
178
|
+
hours, seconds = seconds.divmod(3600)
|
179
|
+
minutes, seconds = seconds.divmod(60)
|
180
|
+
seconds, frac = seconds.divmod(1)
|
181
|
+
|
182
|
+
result = "%0.2d:%0.2d" % [minutes,seconds]
|
183
|
+
result = ("%0.2d:" % hours) + result if hours > 0 or days > 0
|
184
|
+
result = ("%0.2d:" % days) + result if days > 0
|
185
|
+
result += ("." + frac.round(2).to_s.split(".").last[0..1]) if frac > 0
|
186
|
+
|
187
|
+
result
|
188
|
+
end
|
189
|
+
|
171
190
|
end
|
172
191
|
|
173
192
|
|
@@ -252,23 +271,6 @@ class Integer
|
|
252
271
|
end
|
253
272
|
alias_method :fibonacci, :fib
|
254
273
|
|
255
|
-
#
|
256
|
-
# Convert seconds to hours:minutes:seconds (hours is dropped if it's zero)
|
257
|
-
#
|
258
|
-
def to_hms
|
259
|
-
seconds = self
|
260
|
-
|
261
|
-
days, seconds = seconds.divmod(86400)
|
262
|
-
hours, seconds = seconds.divmod(3600)
|
263
|
-
minutes, seconds = seconds.divmod(60)
|
264
|
-
|
265
|
-
result = "%0.2d:%0.2d" % [minutes,seconds]
|
266
|
-
result = ("%0.2d:" % hours) + result if hours > 0 or days > 0
|
267
|
-
result = ("%0.2d:" % days) + result if days > 0
|
268
|
-
|
269
|
-
result
|
270
|
-
end
|
271
|
-
|
272
274
|
end
|
273
275
|
|
274
276
|
#
|
@@ -336,11 +336,15 @@ class String
|
|
336
336
|
end
|
337
337
|
|
338
338
|
#
|
339
|
-
# Converts time duration strings (mm:ss, hh:mm:ss, or dd:hh:mm:ss) to seconds.
|
339
|
+
# Converts time duration strings (mm:ss, mm:ss.dd, hh:mm:ss, or dd:hh:mm:ss) to seconds.
|
340
340
|
# (The reverse of Integer#to_hms)
|
341
341
|
#
|
342
342
|
def from_hms
|
343
|
-
nums = split(':')
|
343
|
+
nums = split(':')
|
344
|
+
|
345
|
+
nums[-1] = nums[-1].to_f if nums[-1] =~ /\d+\.\d+/ # convert fractional seconds to a float
|
346
|
+
nums.map! { |n| n.is_a?(String) ? n.to_i : n } # convert the rest to integers
|
347
|
+
|
344
348
|
nums_and_units = nums.reverse.zip %w[seconds minutes hours days]
|
345
349
|
nums_and_units.map { |num, units| num.send(units) }.sum
|
346
350
|
end
|
data/spec/core_ext_spec.rb
CHANGED
@@ -764,6 +764,13 @@ end
|
|
764
764
|
describe "to_hms and from_hms" do
|
765
765
|
60.to_hms.should == "01:00"
|
766
766
|
60.to_hms.from_hms.should == 60
|
767
|
+
|
768
|
+
60.1.to_hms.should == "01:00.1"
|
769
|
+
60.1.to_hms.from_hms.should == 60.1
|
770
|
+
|
771
|
+
60.15.to_hms.should == "01:00.15"
|
772
|
+
60.2892.to_hms.should == "01:00.29"
|
773
|
+
|
767
774
|
"1:20:33".from_hms.to_hms.should == "01:20:33"
|
768
775
|
"5:01:20:33".from_hms.to_hms.should == "05:01:20:33"
|
769
776
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.43
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|