subunit 0.6.3 → 0.8.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7a64793ef4eba6cac4a1531741c33b7fa51aeda34b953aef7d9aa50ec5da41c
4
- data.tar.gz: b04dcb7003593336c817eda62f688bfea39ddc202f2ca475bfd7f90773692d80
3
+ metadata.gz: 807d54d4b08e3eedaacc7d9a9970d5cc8ee5c5e18bf75282a49c8ccf9ebcf7f6
4
+ data.tar.gz: a5e43fca0a05710ce581a25cceb13da735ad7b9e36102bf162a966ac4fcb9dae
5
5
  SHA512:
6
- metadata.gz: bd7d5da340137fe3d9f5e486f535df23693e16dfa4988e2e7716549623128bde2c8e17300dd2870cd96636061d007c44181256d952d5fc89022904f76ccc13eb
7
- data.tar.gz: 60c40f49bcb37b9dffa884978162eb633823df1f98c396772975aba91f0d1267d1403604df532ffd422832d2d4c74e2399a3b4c9c9dd8c421fea3e7c669a3825
6
+ metadata.gz: a43cd22965a80bbeda08484b5939c4cea4a96e89940f37b14867f15f4a4370b672593c559d8eb57ba3667da1cf8ca11cbfa110f82cce335cf3c786f0631bb1ca
7
+ data.tar.gz: 3b66e9c0bab9872d7738a896df2fbf7fd7492cc45ed0ac76b9cf12f633788fcd87a6fcc541d0b011bec5122a5aed6c3ff10b694168076ba9ac1dcb7d3d395cc9
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- Z���m�*v�@����jJQ*�w8�p\2��Ҩ�r�ݴ��. ����+B3��'qD��
2
- ��W_���#�u�q�?�v�3+TW?����Z�̃m+$lh}e�Ϛ����d��ŰZ���<��#��ۊ�L�"��_�tҤ��&�r��Z�8�� W�]��-��z��T0m)Q@5&����8����U0��#�tϬ������V6a�g�^�5�����P�SMJ �9���sgUI^�˝%�.xuD3�'M��)`ռ�ү���S٭��D�_ޞ4c~d������7t`�ٳ��9AC[�l�0f~�����6�:8(I��
1
+ ����|�=�^�گ�k Q`I`|��~(!.���& �6)�
2
+ 3<3a��Ţ�(��z"�S�����:$�9‘˺2v�|�T/���|�~.?�,�n�S�赆?��֔$�.7"⮹�=���ҩ�@Hύ�!m8;>7��!�ʡ~ƿ�ٽ�2�~q ��˓/���v�\��5C������~�/�^��j��#�،�bND�>�g�<t4��<�'6����D����OKO5iI9x�Kz�Ì&ھ
data.tar.gz.sig CHANGED
Binary file
data/lib/subunit.rb CHANGED
@@ -2,12 +2,31 @@
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
6
18
 
7
- def self.seconds(val)
8
- new(units={minutes:60, hours:60}, seconds: val)
19
+ def self.seconds(val, units: nil)
20
+ new(units={minutes:60, hours:60, days:24}, seconds: val)
9
21
  end
10
22
 
23
+ # e.g. Subunit.hms_to_seconds('5 minutes and 4 seconds')
24
+ # => 304
25
+ #
26
+ def self.hms_to_seconds(obj)
27
+ new(units={hours:60, minutes:60,seconds: 60, }, obj).to_i
28
+ end
29
+
11
30
  attr_reader :to_a, :to_h, :to_i
12
31
 
13
32
  def initialize(raw_units={}, obj)
@@ -15,14 +34,21 @@ class Subunit
15
34
  @debug = false
16
35
 
17
36
  @raw_units = raw_units
37
+
38
+ accumulate = ->(a) {
18
39
 
19
- if obj.is_a? Array then
20
-
21
- a = obj[0..-2]
22
40
  len = raw_units.to_a.length
23
41
  val = ([0]*(len-1) + a).slice(-(len), len).zip(raw_units.values)\
24
- .inject(0) {|r,x| r + x.inject(:*) }
25
- @to_i = val + obj[-1]
42
+ .inject(0) {|r,x| r * x[1] + x[0] }
43
+ }
44
+
45
+ if obj.is_a? String
46
+
47
+ @to_i = accumulate.call obj.split(/\D+/).map(&:to_i)
48
+
49
+ elsif obj.is_a? Array then
50
+
51
+ @to_i = accumulate.call obj
26
52
 
27
53
  else
28
54
 
@@ -39,6 +65,8 @@ class Subunit
39
65
  # %x e.g. 11m 1s
40
66
  # %X e.g. 11 minutes 1 second
41
67
  # %c e.g. 00:11:01
68
+ # %s e.g. 11m # returns the 1st most significant value while
69
+ # ignoring the remainder
42
70
  #
43
71
  def strfunit(s)
44
72
 
@@ -66,6 +94,11 @@ class Subunit
66
94
  fmt = a.map {|v| "%0" + v.to_s.length.to_s + "d"}.join(":")
67
95
  fmt % to_a
68
96
  end
97
+
98
+ s.sub!('%s') do |x|
99
+ label, val = to_h.first
100
+ val.to_s + label[0]
101
+ end
69
102
 
70
103
  s
71
104
  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.3
4
+ version: 0.8.3
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-14 00:00:00.000000000 Z
38
+ date: 2021-02-22 00:00:00.000000000 Z
39
39
  dependencies: []
40
40
  description:
41
41
  email: james@jamesrobertson.eu
@@ -63,7 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.0.3
66
+ rubyforge_project:
67
+ rubygems_version: 2.7.10
67
68
  signing_key:
68
69
  specification_version: 4
69
70
  summary: Input a raw unit and it returns the denomination.
metadata.gz.sig CHANGED
Binary file