subunit 0.1.4 → 0.2.0

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.
Files changed (2) hide show
  1. data/lib/subunit.rb +7 -17
  2. metadata +2 -2
data/lib/subunit.rb CHANGED
@@ -3,30 +3,20 @@
3
3
 
4
4
  class Subunit
5
5
 
6
- def initialize(raw_units=[], subunit=0)
7
- units = multiply_units(raw_units.clone).reverse
8
- @a = scan_units(units, subunit)
6
+ def initialize(raw_units=[], raw_subunit=0)
7
+ units = multiply_units(raw_units).reverse
8
+ @a = scan_units(units, raw_subunit)
9
9
  end
10
10
 
11
- def to_a()
12
- @a.map{|x| x >= 1 ? x : 0}
13
- end
11
+ def to_a() @a.map{|x| x >= 1 ? x.to_i : 0} end
14
12
 
15
13
  private
16
14
 
17
- def multiply_units(x)
18
- if x.length > 1 then
19
- y, k = x.shift 2
20
- r = y.to_i * k.to_i
21
- [r] + multiply_units([r] + x)
22
- else
23
- []
24
- end
25
- end
15
+ def multiply_units(x) x.inject([]){|r,x| r + [x * (r[-1] || 1)]} end
26
16
 
27
- def scan_units(unit_list,seconds)
17
+ def scan_units(unit_list,raw_subunit)
28
18
  n = unit_list.shift
29
- unit, subunit = [:/,:%].map{|x| seconds.send x, n}
19
+ unit, subunit = [:/,:%].map{|x| raw_subunit.send x, n}
30
20
  unit_list.length > 0 ? [unit] + scan_units(unit_list, subunit) : [unit, subunit]
31
21
  end
32
22
  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.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-06-12 00:00:00 +01:00
12
+ date: 2010-06-13 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15