sixarm_ruby_ramp 4.0.0 → 4.1.0

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
  SHA1:
3
- metadata.gz: 15836defff39ae99045d8296deb36ef351e6029c
4
- data.tar.gz: 7182b4e6c8df8418d04960e4a8d2d52bd2da9492
3
+ metadata.gz: a60c19644a07626f66aae272432fb95dc384d5f3
4
+ data.tar.gz: 289def436e9f4683c32d22baad4e42567aa69dbf
5
5
  SHA512:
6
- metadata.gz: 288170ce6181ac89d943ec7abe6065ea67a6b64df274efb2038cb1db16566e88d84d861aef98ae19ee9a12888d3b8ca0e0b36d9df10dfb8a4e984bd3a4da8dd4
7
- data.tar.gz: 8aa243bfb866ae9470bbb6bcb9cbbebb69466263bbded9be671cef88ff3ca2e9efaff35f788359418e2e69a2388114c98c781158388c2cfe30f586e9b504d570
6
+ metadata.gz: 3ba91da4fcfc8e1bfba53b6375623f2e9849c0f97f0629da4cecc6d29e7b96d38594709d82b117593566d8125cf61ab725dbb22f2949cd7880f5de1c3713e3cb
7
+ data.tar.gz: b8af5a9742251db4518c10fec767c61ee9e9ec1910e3e203aa9615b6a0c146efdfb18aa79d0793925a43ba4cc5b796b16cdbc87871465e2b7e5363fe1710e66d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # SixArm.com » Ruby » <br> Ramp gem is a toolkit of Ruby base class extensions
1
+ # SixArm.com » Ruby » <br> Ramp is a toolkit of Ruby base class extensions
2
2
 
3
3
  [![Code Climate](https://codeclimate.com/github/SixArm/sixarm_ruby_ramp.png)](https://codeclimate.com/github/SixArm/sixarm_ruby_ramp)
4
4
  [![Build Status](https://travis-ci.org/SixArm/sixarm_ruby_ramp.png)](https://travis-ci.org/SixArm/sixarm_ruby_ramp)
@@ -28,7 +28,7 @@ Install:
28
28
 
29
29
  Bundler:
30
30
 
31
- gem "sixarm_ruby_ramp", "~>4.0.0"
31
+ gem "sixarm_ruby_ramp", ">=4.1.0", "<5"
32
32
 
33
33
  Require:
34
34
 
@@ -45,7 +45,7 @@ To enable high security for all our gems:
45
45
 
46
46
  To install with high security:
47
47
 
48
- gem install sixarm_ruby_ramp --test --trust-policy HighSecurity
48
+ gem install sixarm_ruby_ramp --trust-policy HighSecurity
49
49
 
50
50
 
51
51
  ## Array
@@ -88,9 +88,11 @@ To install with high security:
88
88
  ## Enumerable
89
89
 
90
90
  * cartesian_product: return an array of all possible ordered tuples from arrays.
91
- * hash_by: convert the array to a hash by mapping each item to a key=>value pair.
92
- * index_by: convert the array to a hash by mapping each ite to a key=>item pair.
91
+ * hash_by: convert the object to a hash by mapping each item to a key=>value pair.
92
+ * index_by: convert the object to a hash by mapping each item to a key=>item pair.
93
93
  * join: forwards to self.to_a.join
94
+ * to_h: convert the object to a hash by mapping each item to a key=>value pair.
95
+ * to_h_merge: convert the object to a hash by mapping each item to a key=>value pair, merging any duplicate keys.
94
96
  * map_id: return the id of an Enumerable object; *requires* that the object respond to an 'id' message
95
97
  * map_to_a, map_to_f, map_to_i, map_to_s, map_to_sym: convert each object to a specific type by calling its respective method to_a, to_i, to_f, to_s, to_sym
96
98
  * map_with_index: for each item, yield to a block with the item and its incrementing index
@@ -227,7 +229,9 @@ Extensions that help debug Ruby programs.
227
229
 
228
230
  ## Changes
229
231
 
230
- * 2014-12-17 4.0.0 Add `Pairable` methods; change semantics of `Hash#map_pair`
232
+ * 2015-01-13 4.1.0 Fix Enumerable `to_h` and add `to_h_merge`
233
+ * 2015-01-13 4.0.1 Fix for Process.ps keys
234
+ * 2014-12-17 4.0.0 Add `Pairable` methods; change semantics of `Hash#map_pair`; change `to_h` for Ruby 2.2.0
231
235
  * 2013-08-19 3.0.1 Update for Code Climate, Travis CI, gem dependencies
232
236
  * 2013-08-18 3.0.0 Update to Ruby 2
233
237
  * 2012-09-01 2.1.7 Add Numeric#floor_precision
@@ -272,4 +276,4 @@ This license is for the included software that is created by SixArm;
272
276
  some of the included software may have its own licenses, copyrights,
273
277
  authors, etc. and these do take precedence over the SixArm license.
274
278
 
275
- Copyright (c) 2005-2012 Joel Parker Henderson
279
+ Copyright (c) 2005-2015 Joel Parker Henderson
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.0
1
+ 4.1.0
@@ -2,13 +2,13 @@
2
2
 
3
3
  # Enumberable extensions
4
4
 
5
+ require 'set'
5
6
  module Enumerable
6
7
 
7
-
8
8
  ########################################################################
9
9
  #
10
10
  # typecast
11
- #
11
+ #
12
12
  ########################################################################
13
13
 
14
14
  # Convert an enumerable to a hash.
@@ -19,24 +19,42 @@ module Enumerable
19
19
  # array=[[:a, :b],[:c, :d],[:e, :f]]
20
20
  # array.to_h => {:a=>:b, :c=>:d, :e=>:f}
21
21
  #
22
- # If a key occurs more than once, then this will automatically
23
- # convert the value to an array of the keys' values.
22
+ if !Enumerable.instance_methods.include?:to_h
23
+ def to_h
24
+ hash={}
25
+ each{|key,val|
26
+ hash[key]=val
27
+ }
28
+ return hash
29
+ end
30
+ end
31
+
32
+ # Convert an enumerable to a hash and merge values.
33
+ #
34
+ # @return [Hash<Object,Object>] a hash of the enumerable's items
35
+ #
36
+ # @example
37
+ # array=[[:a, :b],[:c, :d],[:e, :f]]
38
+ # array.to_h => {:a=>:b, :c=>:d, :e=>:f}
39
+ #
40
+ # If a key occurs more than once, then this will automatically
41
+ # merge the values to an array of the keys' values.
24
42
  #
25
43
  # @example
26
44
  # array=[[:a,:b],[:a,:c],[:a,:d]]
27
45
  # array.to_h => {:a=>[:b, :c, :d]}
28
-
29
- def to_h
46
+ #
47
+ def to_h_merge
30
48
  hash={}
31
- dupe={}
49
+ seen=Set.new
32
50
  each{|key,val|
33
51
  if hash.key? key
34
- if dupe.key? key
52
+ if seen.include? key
35
53
  hash[key] << val
36
54
  else
37
55
  hash[key]=[hash[key]]
38
56
  hash[key] << val
39
- dupe[key]=true
57
+ seen << key
40
58
  end
41
59
  else
42
60
  hash[key]=val
@@ -45,7 +63,6 @@ module Enumerable
45
63
  return hash
46
64
  end
47
65
 
48
-
49
66
  # Convert the enumerable to a hash by mapping each item to a pair [index ,item]
50
67
  #
51
68
  # @return [Hash<Integer,Object>] a hash of the enumerable's items
@@ -60,36 +77,32 @@ module Enumerable
60
77
  # From http://stackoverflow.com/questions/412771/cleanest-way-to-create-a-hash-from-an-array
61
78
  #
62
79
  # @see #hash_by
63
-
80
+ #
64
81
  def index_by
65
82
  inject({}) {|hash, elem| hash.merge!(yield(elem) => elem) }
66
83
  end
67
84
 
68
-
69
85
  # Convert the enumerable to a hash by mapping each item to a pair [item, new item]
70
86
  #
71
87
  # @return [Hash<Object,Object>] a hash of the enumerable's items
72
- #
88
+ #
73
89
  # @example
74
90
  # strings = ["red","blue","green"]
75
91
  # strings.hash_by{|a| [a.size, a.upcase]}
76
92
  # => {3 => "RED", 4 => "BLUE", 5 => "GREEN"}
77
93
  #
78
94
  # @see #index_by
79
-
95
+ #
80
96
  def hash_by
81
97
  map{|item| yield(item)}.to_h
82
98
  end
83
99
 
84
-
85
-
86
100
  ########################################################################
87
101
  #
88
102
  # map_to_xxx
89
- #
103
+ #
90
104
  ########################################################################
91
105
 
92
-
93
106
  # Map each item => item.id
94
107
  #
95
108
  # @return [Enumerable<Object>] an list of each item.id
@@ -101,12 +114,11 @@ module Enumerable
101
114
  # A typical use is to convert a list of ActiveRecord items to a list of id items.
102
115
  #
103
116
  # This method is a fast way to get the same results as items.map(&:id)
104
-
117
+ #
105
118
  def map_id
106
119
  map{|item| item.id}
107
120
  end
108
121
 
109
-
110
122
  # Map each item => item.to_a
111
123
  #
112
124
  # @return [Enumberable<Array<Object>>] a list of each item.to_a
@@ -122,12 +134,11 @@ module Enumerable
122
134
  # so you can more easily iterate over the the Array items.
123
135
  #
124
136
  # See http://www.ruby-doc.org/core/classes/Enumerable.html#M003148
125
-
137
+ #
126
138
  def map_to_a
127
139
  map{|item| [item]}
128
140
  end
129
141
 
130
-
131
142
  # Map each item => item.to_f
132
143
  #
133
144
  # @return [Enumerable<Float>] a list of each item.to_f
@@ -139,46 +150,43 @@ module Enumerable
139
150
  # A typical use is to convert a list of String items to a list of float items.
140
151
  #
141
152
  # This method is a fast way to get the same results as items.map(&:to_f)
142
-
153
+ #
143
154
  def map_to_f
144
155
  map{|item| item.to_f}
145
156
  end
146
157
 
147
-
148
158
  # Map each item => item.to_i
149
159
  #
150
160
  # @return [Enumerable<Integer>] a list of each item.to_i
151
161
  #
152
162
  # @example
153
163
  # strings = ["1","2","3"]
154
- # strings.map_to_i => [1, 2, 3]
164
+ # strings.map_to_i => [1, 2, 3]
155
165
  #
156
166
  # A typical use is to convert a list of String items to a list of integer items.
157
167
  #
158
168
  # This method is a fast way to get the same results as items.map(&:to_i)
159
-
169
+ #
160
170
  def map_to_i
161
171
  map{|item| item.to_i}
162
172
  end
163
173
 
164
-
165
174
  # Map each item => item.to_s
166
175
  #
167
176
  # @return [Enumerable<String>] a list of each item.to_s
168
177
  #
169
178
  # @example
170
179
  # numbers = [1, 2, 3]
171
- # numbers.map_to_s => ["1", "2", "3"]
180
+ # numbers.map_to_s => ["1", "2", "3"]
172
181
  #
173
182
  # A typical use is to convert a list of Numeric items to a list of String items.
174
183
  #
175
184
  # This method is a fast way to get the same results as items.map(&:to_s)
176
-
185
+ #
177
186
  def map_to_s
178
187
  map{|item| item.to_s}
179
188
  end
180
189
 
181
-
182
190
  # Map each item => item.to_sym
183
191
  #
184
192
  # @return [Enumerable<Symbol>] a list of each item.to_sym
@@ -190,12 +198,11 @@ module Enumerable
190
198
  # A typical use is to convert a list of Object items to a list of Symbol items.
191
199
  #
192
200
  # This method is a fast way to get the same results as items.map(&:to_sym)
193
-
201
+ #
194
202
  def map_to_sym
195
203
  map{|item| item.to_sym}
196
204
  end
197
205
 
198
-
199
206
  # Map each item and its index => a new output
200
207
  #
201
208
  # @return [Enumerable<Object>] an list of each item transformed by the block
@@ -206,58 +213,54 @@ module Enumerable
206
213
  # strings = ["a", "b", "c"]
207
214
  # strings.map_with_index{|string,index| "#{string}#{index}"}
208
215
  # => ["a0, "b1", "c3"]
209
-
216
+ #
210
217
  def map_with_index
211
218
  index=-1
212
219
  map{|item| index+=1; yield(item,index)}
213
220
  end
214
221
 
215
-
216
222
  ########################################################################
217
223
  #
218
224
  # select
219
- #
225
+ #
220
226
  ########################################################################
221
-
222
-
227
+
223
228
  # @example
224
229
  # enum.select_while {|obj| block }
225
230
  # => array
226
231
  #
227
232
  # @return [Array<Object>] the leading elements for which block is not false or nil.
228
-
233
+ #
229
234
  def select_while
230
235
  arr = []
231
236
  each{|item| yield(item) ? (arr << item) : break}
232
237
  return arr
233
238
  end
234
239
 
235
-
236
240
  # @example
237
241
  # enum.select_until {|obj| block }
238
242
  # => array
239
243
  #
240
244
  # @return [Array<Object>] the leading elements for which block is false or nil.
241
-
245
+ #
242
246
  def select_until
243
247
  arr = []
244
248
  each{|item| yield(item) ? break : (arr << item)}
245
249
  return arr
246
250
  end
247
251
 
248
-
249
252
  # Calls block with two arguments, the item and its index, for each item in enum.
250
253
  #
251
254
  # @example
252
- # enum.select_with_index {|obj,i| block }
255
+ # enum.select_with_index {|obj,i| block }
253
256
  # => array
254
257
  #
255
258
  # @return [Array<Object> the leading elements for which block is not false or nil.
256
-
259
+ #
257
260
  def select_with_index
258
261
  index = 0
259
262
  arr = []
260
- each{|item|
263
+ each{|item|
261
264
  if yield(item,index)
262
265
  arr << item
263
266
  index+=1
@@ -268,25 +271,24 @@ module Enumerable
268
271
  return arr
269
272
  end
270
273
 
271
-
272
274
  ########################################################################
273
275
  #
274
276
  # bisect
275
- #
277
+ #
276
278
  ########################################################################
277
279
 
278
280
  # @example
279
281
  # enum.bisect {|obj| block}
280
282
  # => array of positives, array of negatives
281
- #
283
+ #
282
284
  # @return [Array<Array<Object>] an array of two arrays:
283
285
  # the first array is the elements for which block is true,
284
286
  # the second array is the elements for which block is false or nil.
285
-
287
+ #
286
288
  def bisect
287
289
  accept=[]
288
290
  reject=[]
289
- each{|item|
291
+ each{|item|
290
292
  if yield(item)
291
293
  accept << item
292
294
  else
@@ -296,19 +298,18 @@ module Enumerable
296
298
  return accept,reject
297
299
  end
298
300
 
299
-
300
301
  ########################################################################
301
302
  #
302
303
  # mutually exclusive?
303
- #
304
+ #
304
305
  ########################################################################
305
306
 
306
307
  # @example
307
308
  # enum.mutex? {|obj| block}
308
309
  # => true iff block is not false or nil, zero or one time
309
310
  #
310
- # @return boolean true iff block is not false or nil, zero or one time
311
-
311
+ # @return boolean true iff block is not false or nil, zero or one time
312
+ #
312
313
  def mutex?
313
314
  num = 0
314
315
  each{|item|
@@ -320,20 +321,18 @@ module Enumerable
320
321
  return true
321
322
  end
322
323
 
323
-
324
324
  ########################################################################
325
325
  #
326
326
  # nitems
327
- #
327
+ #
328
328
  ########################################################################
329
-
330
-
329
+
331
330
  # @example
332
331
  # enum.nitems?(n) {| obj | block }
333
332
  # => true iff the block is not false or nil num times
334
- #
333
+ #
335
334
  # @return [Boolean] true iff the block is not false or nil num times
336
-
335
+ #
337
336
  def nitems?(n)
338
337
  num = 0
339
338
  each{|item|
@@ -345,30 +344,28 @@ module Enumerable
345
344
  return num==n
346
345
  end
347
346
 
348
-
349
347
  # @example
350
348
  # enum.nitems_while {| obj | block }
351
349
  # => number of items
352
- #
350
+ #
353
351
  # @return [Integer] the number of leading elements for which block is not false or nil.
354
-
352
+ #
355
353
  def nitems_while
356
354
  num = 0
357
355
  each{|item| yield(item) ? (num+=1) : break}
358
356
  return num
359
357
  end
360
358
 
361
-
362
359
  # @example
363
360
  # enum.nitems_until {| obj | block }
364
361
  # => number of items
365
362
  #
366
363
  # @return [Integer] the number of leading elements for which block is false.
367
-
364
+ #
368
365
  def nitems_until
369
366
  num = 0
370
367
  each{|item|
371
- if yield(item)
368
+ if yield(item)
372
369
  break
373
370
  else
374
371
  num+=1
@@ -385,7 +382,7 @@ module Enumerable
385
382
  # => number of items
386
383
  #
387
384
  # @return [Integer] the number of leading elements for which block is true.
388
-
385
+ #
389
386
  def nitems_with_index
390
387
  index = 0
391
388
  each{|item| yield(item,index) ? (index+=1) : break}
@@ -402,19 +399,17 @@ module Enumerable
402
399
  # @return [String] concatenated string
403
400
  #
404
401
  # @see Array#join
405
-
402
+ #
406
403
  def join(*op)
407
404
  to_a.join(*op)
408
405
  end
409
406
 
410
-
411
407
  ########################################################################
412
408
  #
413
409
  # set math
414
- #
410
+ #
415
411
  ########################################################################
416
412
 
417
-
418
413
  # @return [Boolean] true if this _enum_ intersects another _enum_.
419
414
  #
420
415
  # A developer may want to optimize this implementation for
@@ -429,7 +424,6 @@ module Enumerable
429
424
  return enum.any?{|item| self.include?(item)}
430
425
  end
431
426
 
432
-
433
427
  # @return [Array] the cartesian product of the enumerations.
434
428
  #
435
429
  # @see http://en.wikipedia.org/wiki/Cartesian_product
@@ -443,7 +437,7 @@ module Enumerable
443
437
  # For our benchmarks, we also compared these:
444
438
  # - By William James, http://www.ruby-forum.com/topic/95519
445
439
  # - By Brian Schröäer, http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/151857
446
-
440
+ #
447
441
  def self.cartesian_product(*enums)
448
442
  result = [[]]
449
443
  while [] != enums
@@ -458,12 +452,12 @@ module Enumerable
458
452
  result
459
453
  end
460
454
 
461
-
455
+ # Calculate the cartesian product.
456
+ #
462
457
  def cartesian_product(*enums)
463
458
  Enumerable.cartesian_product(self,*enums)
464
459
  end
465
460
 
466
-
467
461
  # Calculate the power set.
468
462
  #
469
463
  # @return [Array<Array<Object>>] the power set: an array with all subsets of the enum's elements.
@@ -475,7 +469,7 @@ module Enumerable
475
469
  # @example
476
470
  # [1,2,3].power_set.sort
477
471
  # => [[], [1], [1, 2], [1, 2, 3], [1, 3], [2], [2, 3], [3]]
478
-
472
+ #
479
473
  def power_set
480
474
  inject([[]]){|c,y|r=[];c.each{|i|r<<i;r<<i+[y]};r}
481
475
  end
@@ -19,7 +19,6 @@
19
19
 
20
20
  module Process
21
21
 
22
-
23
22
  # Get the 'ps' command as one long text string.
24
23
  #
25
24
  # This is typically useful for logging to a text file.
@@ -30,12 +29,11 @@ module Process
30
29
  # => "0.0 bfd86194 21:14:51 ..."
31
30
  #
32
31
  # @return [String] lots of data about the process
33
-
32
+ #
34
33
  def self.ps(pid=Process.pid)
35
34
  `#{self.ps_command} #{pid.to_i}`
36
35
  end
37
36
 
38
-
39
37
  # Get the 'ps' command as a hash of keys and values.
40
38
  #
41
39
  # @return [Hash<String,String>] the ps command options as keys and values
@@ -46,7 +44,7 @@ module Process
46
44
  # => {"cp"=>0.0, "esp"=>"bfd86194", "etime"=>"21:14:51", ... }
47
45
  # -
48
46
  # OPTIMIZE: add dates, times
49
-
47
+ #
50
48
  PS_TO_I = %w(c egid egroup uid fgid lwp ni nlwp pgid pid ppid rgid rss ruid sid sgid suid)
51
49
  PS_TO_F = %w(cp pcpu pmem)
52
50
 
@@ -59,17 +57,16 @@ module Process
59
57
  return h
60
58
  end
61
59
 
62
-
63
60
  # Get the list of process alias keywords as typically defined by the shell.
64
61
  #
65
62
  # For example, a shell may consider "%cpu" and "pcpu" to be identical.
66
63
  #
67
64
  # @example
68
65
  # Process::PS_ALIASES_DEFAULT
69
- # => {"%cpu"=>"pcpu", "sigmask"=>"blocked", "cls"=>"policy", ... }
66
+ # => {"%cpu"=>"pcpu", "sigmask"=>"blocked", "class"=>"cls", ... }
70
67
  #
71
68
  # @return [Hash<String,String>] process keyword aliases
72
-
69
+ #
73
70
  PS_ALIASES_DEFAULT={
74
71
  '%cpu'=>'pcpu',
75
72
  '%mem'=>'pmem',
@@ -77,8 +74,8 @@ module Process
77
74
  'sigmask'=>'blocked',
78
75
  'sig_catch'=>'caught',
79
76
  'sigcatch'=>'caught',
80
- 'cls'=>'class',
81
- 'cls'=>'policy',
77
+ 'class'=>'cls',
78
+ 'policy'=>'pol',
82
79
  'cputime'=>'time',
83
80
  'gid'=>'egid',
84
81
  'group'=>'egroup',
@@ -104,46 +101,42 @@ module Process
104
101
  'session'=>'sid',
105
102
  'svgid'=>'sgid',
106
103
  'tt'=>'tname',
107
- 'tty'=>'tname',
104
+ 'tty'=>'tname',
108
105
  'vsz'=>'vsize'
109
106
  }
110
107
 
111
-
112
108
  # Get the list of process alias keywords as typically defined by the shell.
113
109
  #
114
110
  # For example, a shell may consider "%cpu" and "pcpu" to be identical.
115
111
  #
116
- # @example
112
+ # @example
117
113
  # Process.ps_aliases
118
- # => {"%cpu"=>"pcpu", "sigmask"=>"blocked", "cls"=>"policy", ... }
119
- #
120
- # @return [Hash<String,String>] process keyword aliases
121
-
114
+ # => {"%cpu"=>"pcpu", "sigmask"=>"blocked", "class"=>"cls", ... }
115
+ #
116
+ # @return [Hash<String,String>] process keyword aliases
117
+ #
122
118
  def self.ps_aliases
123
119
  @@ps_aliases||=PS_ALIASES_DEFAULT
124
120
  end
125
121
 
126
-
127
122
  # Set the list of process alias keywords.
128
123
  #
129
124
  # For example, a shell may consider "%cpu" and "pcpu" to be identical.
130
125
  #
131
- # @example
132
- # Process::ps_aliases={ {"%cpu"=>"pcpu", "sigmask"=>"blocked", "cls"=>"policy" }
133
- # => {"%cpu"=>"pcpu", "sigmask"=>"blocked", "cls"=>"policy"}
134
- #
135
- # @param [Hash<String,String>] aliases
126
+ # @example
127
+ # Process::ps_aliases={ {"%cpu"=>"pcpu", "sigmask"=>"blocked", "class"=>"cls" }
128
+ # => {"%cpu"=>"pcpu", "sigmask"=>"blocked", "class"=>"cls"}
129
+ #
130
+ # @param [Hash<String,String>] aliases
136
131
  # @return [Hash<String,String>] aliases
137
-
132
+ #
138
133
  def self.ps_aliases=(aliases)
139
134
  @@ps_aliases=aliases
140
135
  end
141
136
 
142
-
143
137
  # The list of process keywords.
144
138
 
145
- PS_KEYS_DEFAULT=%w'blocked bsdtime c caught class cp egid egroup eip esp etime euid euser f fgid fgroup fuid fuser group ignored label lwp ni nlwp nwchan pending pcpu pgid pid pmem ppid pri psr rgid rgroup rss rtprio ruid ruser s sched sgi_p sgid sgroup sid sig size stackp start_time stat suid suser sz time tname tpgid vsize wchan'
146
-
139
+ PS_KEYS_DEFAULT=%w'%cpu %mem acflag acflg args blocked comm command cpu cputime etime f flags gid group inblk inblock jobc ktrace ktracep lim login logname lstart majflt minflt msgrcv msgsnd ni nice nivcsw nsignals nsigs nswap nvcsw nwchan oublk oublock p_ru paddr pagein pcpu pending pgid pid pmem ppid pri pstime putime re rgid rgroup rss ruid ruser sess sig sigmask sl start stat state stime svgid svuid tdev time tpgid tsess tsiz tt tty ucomm uid upr user usrpri utime vsize vsz wchan wq wqb wql wqr xstat'
147
140
 
148
141
  # Get the list of process keywords.
149
142
  #
@@ -152,30 +145,26 @@ module Process
152
145
  # => ["blocked","group","pending","size"]
153
146
  #
154
147
  # @return [Array<String>] the list of process keywords.
155
-
156
-
148
+ #
157
149
  def self.ps_keys
158
150
  @@ps_keys||=PS_KEYS_DEFAULT
159
151
  end
160
152
 
161
-
162
153
  # Set the list of process keywords.
163
154
  #
164
- # @example
155
+ # @example
165
156
  # Process.ps_keys = ["blocked","group","pending","size"]
166
157
  #
167
158
  # @param [Array<String>] keywords
168
159
  # @return [Array<String>] keywords
169
-
160
+ #
170
161
  def self.ps_keys=(keys)
171
162
  @@ps_keys=keys
172
163
  end
173
164
 
174
-
175
165
  # The process command, i.e. what the sytem will call for the "ps" command.
176
166
 
177
- PS_COMMAND_DEFAULT='ps h ww -o "'+self.ps_keys.join(',')+'"'
178
-
167
+ PS_COMMAND_DEFAULT="ps hww -o #{ps_keys.join(',')}"
179
168
 
180
169
  # Get the process command, i.e. what the sytem will call for the "ps" command.
181
170
  #
@@ -184,23 +173,21 @@ module Process
184
173
  # => "ps h ww -o blocked,group,pending,size"
185
174
  #
186
175
  # @return [String] the process command
187
-
176
+ #
188
177
  def self.ps_command
189
178
  @@ps_command||=PS_COMMAND_DEFAULT
190
179
  end
191
180
 
192
-
193
181
  # Set the process command, i.e. what the sytem will call for the "ps" command.
194
182
  #
195
183
  # @example
196
184
  # Process.ps_command = "ps h ww -o blocked,group,pending,size"
197
185
  #
198
186
  # @param [String] the process command
199
- # @return [String] the process command
200
-
187
+ # @return [String] the process command
188
+ #
201
189
  def self.ps_command=(command)
202
190
  @@ps_command=command
203
191
  end
204
192
 
205
-
206
193
  end
@@ -19,13 +19,23 @@ class EnumerableTest < Minitest::Test
19
19
 
20
20
 
21
21
  def test_to_h_with_unique_keys
22
- a=[[:a,:b],[:c,:d],[:e,:f]]
22
+ a=[[:a,:b],[:c,:d],[:e,:f]]
23
23
  assert_equal({:a=>:b, :c=>:d, :e=>:f}, a.to_h)
24
24
  end
25
25
 
26
26
  def test_to_h_with_duplicate_keys
27
- a=[[:a,:b],[:a,:c],[:a,:d]]
28
- assert_equal({:a=>[:b, :c, :d]}, a.to_h)
27
+ a=[[:a,:b],[:a,:c],[:a,:d]]
28
+ assert_equal({:a=>:d}, a.to_h)
29
+ end
30
+
31
+ def test_to_h_merge_with_unique_keys
32
+ a=[[:a,:b],[:c,:d],[:e,:f]]
33
+ assert_equal({:a=>:b, :c=>:d, :e=>:f}, a.to_h_merge)
34
+ end
35
+
36
+ def test_to_h_merge_with_duplicate_keys
37
+ a=[[:a,:b],[:a,:c],[:a,:d]]
38
+ assert_equal({:a=>[:b, :c, :d]}, a.to_h_merge)
29
39
  end
30
40
 
31
41
  def test_index_by
@@ -36,7 +46,7 @@ class EnumerableTest < Minitest::Test
36
46
  assert_equal({3=>"RED",4=>"BLUE",5=>"GREEN"},RGB.hash_by{|x| [x.size,x.upcase]})
37
47
  end
38
48
 
39
-
49
+
40
50
  ########################################################################
41
51
  #
42
52
  # map
@@ -58,11 +68,11 @@ class EnumerableTest < Minitest::Test
58
68
  end
59
69
 
60
70
 
61
- A = Mock.new('a')
62
- B = Mock.new('b')
63
- C = Mock.new('c')
71
+ A = Mock.new('a')
72
+ B = Mock.new('b')
73
+ C = Mock.new('c')
74
+
64
75
 
65
-
66
76
  def test_map_id
67
77
  assert_equal(['a','b','c'],[A,B,C].map_id)
68
78
  end
@@ -173,7 +183,7 @@ class EnumerableTest < Minitest::Test
173
183
  end
174
184
 
175
185
 
176
- def test_nitems_while
186
+ def test_nitems_while
177
187
  assert_equal(0,ITEMS.nitems_while{|x| x < 'a' },'< a')
178
188
  assert_equal(1,ITEMS.nitems_while{|x| x < 'b' },'< b')
179
189
  assert_equal(2,ITEMS.nitems_while{|x| x < 'c' },'< c')
@@ -190,7 +200,7 @@ class EnumerableTest < Minitest::Test
190
200
  assert_equal(3,ITEMS.nitems_until{|x| x == 'e' },'e')
191
201
  end
192
202
 
193
-
203
+
194
204
  def test_nitems_with_index
195
205
  assert_equal(0,ITEMS.nitems_with_index{|x,i| i < 0 },'i < 0')
196
206
  assert_equal(1,ITEMS.nitems_with_index{|x,i| i < 1 },'i < 1')
@@ -297,7 +307,3 @@ class EnumerableTest < Minitest::Test
297
307
  end
298
308
 
299
309
  end
300
-
301
-
302
-
303
-
@@ -19,132 +19,6 @@ class HashTest < Minitest::Test
19
19
  assert_equal({'a' => 'x', 'b' => 'y', 'c' => 'z'}, h.sort_by_keys)
20
20
  end
21
21
 
22
- def test_each_sort
23
- out = []
24
- h = {'c' => 'z', 'b' => 'y', 'a' => 'x'}
25
- h.each_sort{|key,val| out << key.upcase; out << val.upcase}
26
- assert_equal(['A','X','B','Y','C','Z'], out)
27
- end
28
-
29
- def test_each_sort_with_empty
30
- out = []
31
- h = {}
32
- h.each_sort{|key,val| out << key.upcase; out << val.upcase}
33
- assert_equal([], out)
34
- end
35
-
36
- def test_each_key_bang
37
- actual = { "a" => "b", "c" => "d" }
38
- expect = { "A" => "b", "C" => "d" }
39
- actual.each_key! {|key| key.upcase }
40
- assert_equal(expect,actual)
41
- end
42
-
43
- def test_each_key_bang_with_empty
44
- actual = {}
45
- expect = {}
46
- actual.each_key! {|key| key.upcase }
47
- assert_equal(expect,actual)
48
- end
49
-
50
- def test_each_pair_bang
51
- actual = { "a" => "b", "c" => "d" }
52
- expect = { "A" => "B", "C" => "D" }
53
- actual.each_pair! {|key,value| [key.upcase, value.upcase] }
54
- assert_equal(expect,actual)
55
- end
56
-
57
- def test_each_pair_bang_with_empty
58
- actual = {}
59
- expect = {}
60
- actual.each_pair! {|key,value| [key.upcase, value.upcase] }
61
- assert_equal(expect,actual)
62
- end
63
-
64
- def test_each_pair_bang_with_same_key_different_value
65
- actual = { "a" => "b", "c" => "d" }
66
- expect = { "a" => "B", "c" => "D" }
67
- actual.each_pair! {|key,value| [key, value.upcase] }
68
- assert_equal(expect,actual)
69
- end
70
-
71
- def test_each_pair_bang_with_same_key_same_value
72
- actual = { "a" => "b", "c" => "d" }
73
- expect = { "a" => "b", "c" => "d" }
74
- actual.each_pair! {|key,value| [key, value] }
75
- assert_equal(expect,actual)
76
- end
77
-
78
- def test_each_value_bang
79
- actual = { "a" => "b", "c" => "d" }
80
- expect = { "a" => "B", "c" => "D" }
81
- actual.each_value! {|value| value.upcase }
82
- assert_equal(expect,actual)
83
- end
84
-
85
- def test_each_value_bang_with_empty
86
- actual = {}
87
- expect = {}
88
- actual.each_value! {|value| value.upcase }
89
- assert_equal(expect,actual)
90
- end
91
-
92
- def test_map_key
93
- h = {"a"=>"b"}
94
- expect = {"A" => "b"}
95
- actual = h.map_key{|key| key.upcase }.sort
96
- assert_equal(expect,actual,h.inspect)
97
- end
98
-
99
- def test_map_value
100
- h = {"a"=>"b"}
101
- expect = {"a" => "B"}
102
- actual = h.map_value{|value| value.upcase }.sort
103
- assert_equal(expect,actual,h.inspect)
104
- end
105
-
106
- def test_map_value
107
- h = {"a"=>"b"}
108
- expect = {"A" => "B"}
109
- actual = h.map_value{|key, value| key.upcase, value.upcase }.sort
110
- assert_equal(expect,actual,h.inspect)
111
- end
112
-
113
- def test_yield_pair
114
- h = {"a"=>"b", "c"=>"d", "e"=>"f" }
115
- expect=["ab","cd","ef"]
116
- actual=h.yield_pair{|key,value| key+value }.sort
117
- assert_equal(expect,actual,h.inspect)
118
- end
119
-
120
- def test_yield_pair_with_empty
121
- h = {}
122
- expect=[]
123
- actual=h.yield_pair{|key,value| key+value }.sort
124
- assert_equal(expect,actual,h.inspect)
125
- end
126
-
127
- def test_map_key
128
- h={"a"=>"b", "c"=>"d", "e"=>"f" }
129
- expect={"a1"=>"b", "c1"=>"d", "e1"=>"f" }
130
- actual=h.map_pair{|key,value| "#{key}1" }.sort
131
- assert_equal(expect,actual,h.inspect)
132
- end
133
-
134
- def test_map_value
135
- h={"a"=>"b", "c"=>"d", "e"=>"f" }
136
- expect={"a"=>"b2", "c"=>"d2", "e"=>"f2" }
137
- actual=h.map_pair{|key,value| "#{value}2" }.sort
138
- assert_equal(expect,actual,h.inspect)
139
- end
140
-
141
- def test_map_pair
142
- h={"a"=>"b", "c"=>"d", "e"=>"f" }
143
- expect={"a1"=>"b2", "c1"=>"d2", "e1"=>"f2" }
144
- actual=h.map_pair{|key,value| ["#{key}1", "#{value}2" }.sort
145
- assert_equal(expect,actual,h.inspect)
146
- end
147
-
148
22
  def test_merge_recurse
149
23
  # Test with three kinds of items:
150
24
  # * same key => same value #=> must stay the same
@@ -62,6 +62,5 @@ class ProcessTest < Minitest::Test
62
62
  assert_equal(['a','b','c'], Process.ps_keys)
63
63
  Process.ps_keys=Process::PS_KEYS_DEFAULT
64
64
  end
65
-
66
- end
67
65
 
66
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sixarm_ruby_ramp
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SixArm
@@ -30,7 +30,7 @@ cert_chain:
30
30
  sWRVEyjnjnNuAeLP9zv43IDXjS22L2efhap7IOinYjcecpfXJgQaU+6BFAY4sdkQ
31
31
  S1STYSfs3qySBxxAeEyZTw==
32
32
  -----END CERTIFICATE-----
33
- date: 2014-12-18 00:00:00.000000000 Z
33
+ date: 2015-01-13 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: sixarm_ruby_rexml
@@ -174,10 +174,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  requirements: []
176
176
  rubyforge_project:
177
- rubygems_version: 2.2.2
177
+ rubygems_version: 2.4.5
178
178
  signing_key:
179
179
  specification_version: 4
180
- summary: SixArm.com » Ruby » Ramp gem provides base extensions to ruby classes.
180
+ summary: SixArm.com » Ruby » Ramp provides base extensions to ruby classes.
181
181
  test_files:
182
182
  - test/sixarm_ruby_ramp_test.rb
183
183
  - test/sixarm_ruby_ramp_test/array_test.rb
@@ -203,3 +203,4 @@ test_files:
203
203
  - test/sixarm_ruby_ramp_test/xml_test.rb
204
204
  - test/sixarm_ruby_ramp_test/yaml_test.rb
205
205
  - test/sixarm_ruby_ramp_test/io_test.txt
206
+ has_rdoc: true
metadata.gz.sig CHANGED
Binary file