alib 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/a.rb CHANGED
@@ -1,12 +1,7 @@
1
- module M
2
- end
3
- class C
4
- end
1
+ require 'alib'
5
2
 
6
- p(M === C)
7
-
8
- class C
9
- include M
3
+ open __FILE__ do |fd|
4
+ alib.util.threadify fd, n_threads=5 do |line, lineno|
5
+ puts "#{ Thread.current.object_id} - #{ lineno }:#{ line }"
6
+ end
10
7
  end
11
- p(M === C)
12
-
data/b.rb ADDED
@@ -0,0 +1,92 @@
1
+ require 'alib'
2
+
3
+ this = open __FILE__
4
+
5
+ n_threads = 5
6
+
7
+ alib.util.threadify this, n_threads do |line, lineno|
8
+ puts line
9
+ end
10
+
11
+
12
+
13
+
14
+ __END__
15
+ class Time
16
+ class Distance < ::Hash
17
+ def method_missing m, *a, &b
18
+ super unless has_key? m.to_sym
19
+ self[m.to_sym]
20
+ end
21
+ end
22
+
23
+ def distance other, limit = :years
24
+ s = ( to_i - other.to_i ).abs
25
+ d = Distance.new
26
+ format = Array.new
27
+ values = Array.new
28
+
29
+ ops = [
30
+ [ :years, 31536000 ],
31
+ [ :months, 2592000 ],
32
+ [ :weeks, 604800 ],
33
+ [ :days, 86400 ],
34
+ [ :hours, 3600 ],
35
+ [ :minutes, 60 ],
36
+ [ :seconds, 1 ],
37
+ ]
38
+
39
+ index = 0
40
+
41
+ ops.each_with_index do |pair, i|
42
+ unit = pair.first
43
+ break(index = i) if limit == unit
44
+ end
45
+
46
+ ops[index .. -1].each do |pair|
47
+ unit, n = pair
48
+ if n > s
49
+ value = 0
50
+ d[unit] = value
51
+ else
52
+ value, s = s.divmod n
53
+ d[unit] = value
54
+ values << value
55
+ unit = value == 1 ? unit.to_s.chop : unit.to_s
56
+ format << "%d #{ unit }"
57
+ end
58
+
59
+ end
60
+
61
+ if format.size > 1
62
+ comma = ',' if format.size > 2
63
+ format[-2] = "#{ format[-2] }#{ comma } and #{ format[-1] }"
64
+ format.pop
65
+ end
66
+ format = format.join ', '
67
+
68
+ d[:formatted] = format % values
69
+
70
+ d
71
+ end
72
+ end
73
+
74
+ a = Time.now
75
+ b = a + 120 + 2
76
+ p a.distance(b, :days).formatted
77
+
78
+ a = Time.now
79
+ b = a + (2 * 3600)
80
+ p a.distance(b).formatted
81
+
82
+ a = Time.now
83
+ b = a + (31536000)
84
+ p a.distance(b).formatted
85
+
86
+ a = Time.now
87
+ b = a + (31536000 + 3600 + 60 + 42)
88
+ p a.distance(b).formatted
89
+
90
+ a = Time.now
91
+ b = a + (31536000 + 3600 + 60 + 42)
92
+ p a.distance(b, :weeks).formatted
@@ -3,7 +3,7 @@
3
3
  #
4
4
  module ALib
5
5
  #--{{{
6
- VERSION = '0.5.0'
6
+ VERSION = '0.5.1'
7
7
 
8
8
  require 'pathname'
9
9
  require 'socket'
File without changes
File without changes
File without changes
File without changes
@@ -976,6 +976,16 @@ module ALib::Util
976
976
  #--}}}
977
977
  end
978
978
  export 'hms'
979
+ def dhms s
980
+ #--{{{
981
+ s = s.to_i if Time === s
982
+ d, s = s.divmod 86400
983
+ h, s = s.divmod 3600
984
+ m, s = s.divmod 60
985
+ [d.to_i, h.to_i, m.to_i, s]
986
+ #--}}}
987
+ end
988
+ export 'dhms'
979
989
  #
980
990
  # expand variables in a string destructively (to the string)
981
991
  #
@@ -1457,9 +1467,7 @@ module ALib::Util
1457
1467
  consumers.map{|t| t.join}
1458
1468
  jobs.push done
1459
1469
 
1460
- #sleep 5
1461
-
1462
- ret = Array.new list.size
1470
+ ret = []
1463
1471
  while((job = jobs.pop) != done)
1464
1472
  elem, i, value = job
1465
1473
  ret[i] = value
@@ -3,7 +3,7 @@
3
3
  #
4
4
  module ALib
5
5
  #--{{{
6
- VERSION = '0.5.0'
6
+ VERSION = '0.5.1'
7
7
 
8
8
  require 'pathname'
9
9
  require 'socket'
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: alib
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.0
7
- date: 2007-02-18 00:00:00 -07:00
6
+ version: 0.5.1
7
+ date: 2007-10-14 00:00:00 -06:00
8
8
  summary: alib
9
9
  require_paths:
10
10
  - lib
@@ -30,33 +30,33 @@ authors:
30
30
  - Ara T. Howard
31
31
  files:
32
32
  - a.rb
33
+ - b.rb
33
34
  - gemspec.rb
34
- - alib-0.5.0.gem
35
35
  - install.rb
36
36
  - lib
37
+ - lib/alib-0.5.1
38
+ - lib/alib-0.5.1/attributes-3.2.0.rb
39
+ - lib/alib-0.5.1/attributes.rb
40
+ - lib/alib-0.5.1/autohash.rb
41
+ - lib/alib-0.5.1/binding_of_caller.rb
42
+ - lib/alib-0.5.1/bsearch.rb
43
+ - lib/alib-0.5.1/classmethods.rb
44
+ - lib/alib-0.5.1/configfile.rb
45
+ - lib/alib-0.5.1/find2.rb
46
+ - lib/alib-0.5.1/listfile.rb
47
+ - lib/alib-0.5.1/logging.rb
48
+ - lib/alib-0.5.1/main.rb
49
+ - lib/alib-0.5.1/main.rb.bak
50
+ - lib/alib-0.5.1/open4-0.9.1.rb
51
+ - lib/alib-0.5.1/open4.rb
52
+ - lib/alib-0.5.1/orderedautohash.rb
53
+ - lib/alib-0.5.1/orderedhash.rb
54
+ - lib/alib-0.5.1/prototype-0.3.0.rb
55
+ - lib/alib-0.5.1/prototype.rb
56
+ - lib/alib-0.5.1/stdext.rb
57
+ - lib/alib-0.5.1/util.rb
58
+ - lib/alib-0.5.1.rb
37
59
  - lib/alib.rb
38
- - lib/alib-0.5.0
39
- - lib/alib-0.5.0/logging.rb
40
- - lib/alib-0.5.0/bsearch.rb
41
- - lib/alib-0.5.0/open4-0.9.1.rb
42
- - lib/alib-0.5.0/stdext.rb
43
- - lib/alib-0.5.0/attributes.rb
44
- - lib/alib-0.5.0/util.rb
45
- - lib/alib-0.5.0/prototype.rb
46
- - lib/alib-0.5.0/listfile.rb
47
- - lib/alib-0.5.0/binding_of_caller.rb
48
- - lib/alib-0.5.0/prototype-0.3.0.rb
49
- - lib/alib-0.5.0/configfile.rb
50
- - lib/alib-0.5.0/main.rb.bak
51
- - lib/alib-0.5.0/attributes-3.2.0.rb
52
- - lib/alib-0.5.0/open4.rb
53
- - lib/alib-0.5.0/autohash.rb
54
- - lib/alib-0.5.0/orderedautohash.rb
55
- - lib/alib-0.5.0/classmethods.rb
56
- - lib/alib-0.5.0/main.rb
57
- - lib/alib-0.5.0/orderedhash.rb
58
- - lib/alib-0.5.0/find2.rb
59
- - lib/alib-0.5.0.rb
60
60
  test_files: []
61
61
 
62
62
  rdoc_options: []
File without changes