subunit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/subunit.rb +32 -0
  2. metadata +55 -0
data/lib/subunit.rb ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby
2
+ # file: subunit.rb
3
+
4
+ class Subunit
5
+
6
+ def initialize(raw_units, subunit)
7
+ units = multiply_units(raw_units).reverse
8
+ @a = scan_units(units, raw_seconds)
9
+ end
10
+
11
+ def to_a()
12
+ @a
13
+ end
14
+
15
+ private
16
+
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
26
+
27
+ def scan_units(unit_list,seconds)
28
+ n = unit_list.shift
29
+ unit, subunit = [:/,:%].map{|x| seconds.send x, n}
30
+ unit_list.length > 0 ? [unit] + scan_units(unit_list, subunit) : [unit, subunit]
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subunit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors: []
7
+
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-06-12 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email:
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/subunit.rb
26
+ has_rdoc: true
27
+ homepage:
28
+ licenses: []
29
+
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.5
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: subunit
54
+ test_files: []
55
+