subunit 0.6.1 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd028dea596b0b1c66609dfa8b77c2daa11276d89ad376341152e01be886c642
4
- data.tar.gz: 072c31bc3ac9aee1273a19f585b9b757d069d2fe4c365d513110f10998e8b342
3
+ metadata.gz: 04ff09dc79844ac6e631550fb7d3af0cd8a7253a6da25b37f4620f4ca2d0af2d
4
+ data.tar.gz: cdcb4a05cf28aef86d445e2abc3dedd9e735358e7b19ec27b272ba776dd6acc0
5
5
  SHA512:
6
- metadata.gz: 715c798c7d3f207060705728fb7e802e2184bc40ee3902d3bc2601214144f8ba27b839b9474b100a5fd5f956d6bdfb2399d48fb6b6e0936fcd798504fb9fb227
7
- data.tar.gz: adc7cfebc9b1e1eca8cf334d44d0137e09a675e43532e1293553581609fc8b6f6d4129b60b1a5f32cd4b9baa1796bdcb1c272b26be961c7718c42495e0ac38db
6
+ metadata.gz: f110323bf0bc4a33cbd62c43896fe6abc786320348ead1205a3422ffc827d25135681ce02300ee868e6f9ace6d69cc03bf2efa6010f992d33c76576778b37afd
7
+ data.tar.gz: b811c7fe06ecb53916f406a1d607ceb75b08345955d874cf754540d8b9e75c4de707a6f854932c9bed35a828141f96506e37dabb28f05a8e8fe544c44ffad91c
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,7 +2,27 @@
2
2
 
3
3
  # file: subunit.rb
4
4
 
5
+ module SubunitFracture
6
+
7
+ refine Integer do
8
+
9
+ def strfunit(s)
10
+ Subunit.seconds(self).strfunit(s)
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+
5
17
  class Subunit
18
+
19
+ def self.seconds(val)
20
+ new(units={minutes:60, hours:60}, seconds: val)
21
+ end
22
+
23
+ def self.hms_to_seconds(obj)
24
+ new(units={hours:60, minutes:60,seconds: 60, }, obj).to_i
25
+ end
6
26
 
7
27
  attr_reader :to_a, :to_h, :to_i
8
28
 
@@ -10,13 +30,22 @@ class Subunit
10
30
 
11
31
  @debug = false
12
32
 
13
- if obj.is_a? Array then
14
-
15
- a = obj[0..-2]
33
+ @raw_units = raw_units
34
+
35
+ accumulate = ->(a) {
36
+
16
37
  len = raw_units.to_a.length
17
38
  val = ([0]*(len-1) + a).slice(-(len), len).zip(raw_units.values)\
18
- .inject(0) {|r,x| r + x.inject(:*) }
19
- @to_i = val + obj[-1]
39
+ .inject(0) {|r,x| r * x[1] + x[0] }
40
+ }
41
+
42
+ if obj.is_a? String
43
+
44
+ @to_i = accumulate.call obj.split(' ').map(&:to_i)
45
+
46
+ elsif obj.is_a? Array then
47
+
48
+ @to_i = accumulate.call obj
20
49
 
21
50
  else
22
51
 
@@ -32,6 +61,7 @@ class Subunit
32
61
  #
33
62
  # %x e.g. 11m 1s
34
63
  # %X e.g. 11 minutes 1 second
64
+ # %c e.g. 00:11:01
35
65
  #
36
66
  def strfunit(s)
37
67
 
@@ -50,6 +80,15 @@ class Subunit
50
80
  end.compact.join(' ')
51
81
 
52
82
  end
83
+
84
+ s.sub!('%c') do |x|
85
+
86
+ a = @raw_units.values.reverse
87
+ a << a[-1]
88
+
89
+ fmt = a.map {|v| "%0" + v.to_s.length.to_s + "d"}.join(":")
90
+ fmt % to_a
91
+ end
53
92
 
54
93
  s
55
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subunit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  HowcHg4GymtLLITCF/QtA5tta5SmHAca1POGncsO9QiramFQ9S3Q4O4wcjboVJOp
36
36
  SSxk4InmYoY9Cl2GVQ+d9owo
37
37
  -----END CERTIFICATE-----
38
- date: 2020-09-12 00:00:00.000000000 Z
38
+ date: 2020-10-08 00:00:00.000000000 Z
39
39
  dependencies: []
40
40
  description:
41
41
  email: james@jamesrobertson.eu
metadata.gz.sig CHANGED
Binary file