epitools 0.5.91 → 0.5.92
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Snakefile +1 -0
- data/VERSION +1 -1
- data/lib/epitools/core_ext/enumerable.rb +14 -0
- data/lib/epitools/minimal.rb +30 -0
- data/spec/core_ext_spec.rb +134 -128
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5af87dba30589c9d2cf9367cc81758b72b2a853
|
4
|
+
data.tar.gz: d100d1a465f5d5088176a7d9d624e9460e7774b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe5397193aed765f41464fe9fad1da4cb98d5a8c47b6c7aa5d5a7e8da0235aa21a2190839e929f2d13692594e8d39147366388f9fd7f72eddd4d9232b9e238e5
|
7
|
+
data.tar.gz: 6c85fda4344ecbecf77539a32e76660585ebf6222f955f3b1deb156a42922430a2bd137c5ffafc489285a7fd9d714e2cec89d06a03d7d09940a3c1a56cbadd1b
|
data/Snakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
🐍
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.92
|
@@ -405,6 +405,20 @@ module Enumerable
|
|
405
405
|
end
|
406
406
|
alias_method :grouped, :groups
|
407
407
|
|
408
|
+
#
|
409
|
+
# Sort strings by their numerical values
|
410
|
+
#
|
411
|
+
def sort_numerically
|
412
|
+
sort_by do |e|
|
413
|
+
case e
|
414
|
+
when String
|
415
|
+
e.split(/(\d+)/).map { |s| s =~ /^\d+$/ ? s.to_i : s }
|
416
|
+
else
|
417
|
+
[e]
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
408
422
|
#
|
409
423
|
# Multiplies this Enumerable by something. (Same behaviour as Enumerator#*)
|
410
424
|
#
|
data/lib/epitools/minimal.rb
CHANGED
@@ -256,6 +256,36 @@ end
|
|
256
256
|
|
257
257
|
####################################################################
|
258
258
|
|
259
|
+
class << ARGV
|
260
|
+
def paths_R
|
261
|
+
the_expander = proc do |paths|
|
262
|
+
paths.map { |path| path.dir? ? the_expander.(path.ls_R) : path }
|
263
|
+
end
|
264
|
+
|
265
|
+
the_expander.(paths)
|
266
|
+
end
|
267
|
+
alias_method :recursive_paths, :paths_R
|
268
|
+
|
269
|
+
def paths
|
270
|
+
map(&:to_Path)
|
271
|
+
end
|
272
|
+
|
273
|
+
def opts
|
274
|
+
partition { |arg| arg[/^--?\w{1,2}/].nil? }
|
275
|
+
end
|
276
|
+
|
277
|
+
def args
|
278
|
+
self - opts
|
279
|
+
end
|
280
|
+
|
281
|
+
def regexes
|
282
|
+
map { |arg| /#{Regexp.escape arg}/i }
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
####################################################################
|
288
|
+
|
259
289
|
require 'epitools/autoloads'
|
260
290
|
|
261
291
|
####################################################################
|
data/spec/core_ext_spec.rb
CHANGED
@@ -5,32 +5,32 @@ describe Object do
|
|
5
5
|
|
6
6
|
it "withs" do
|
7
7
|
class Cookie; attr_accessor :size, :chips; end
|
8
|
-
|
8
|
+
|
9
9
|
c = Cookie.new; c.size = 10; c.chips = 200
|
10
10
|
w = c.with(:chips=>50)
|
11
|
-
|
11
|
+
|
12
12
|
w.size.should == c.size
|
13
13
|
w.chips.should_not == c.chips
|
14
14
|
w.should_not === c
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "in?" do
|
18
18
|
5.in?([1,2,3,4,5,6]).should == true
|
19
19
|
5.in?(1..10).should == true
|
20
20
|
5.in?(20..30).should == false
|
21
21
|
"butt".in?("butts!!!").should == true
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "times" do
|
25
|
-
lambda {
|
25
|
+
lambda {
|
26
26
|
time("time test") { x = 10 }
|
27
27
|
}.should_not raise_error
|
28
28
|
|
29
|
-
lambda {
|
29
|
+
lambda {
|
30
30
|
time("time test") { raise "ERROR" }
|
31
31
|
}.should raise_error
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "benches" do
|
35
35
|
lambda { bench { rand } }.should_not raise_error
|
36
36
|
lambda { bench(20) { rand } }.should_not raise_error
|
@@ -43,59 +43,59 @@ describe Object do
|
|
43
43
|
s = Struct.new(:a,:b).new
|
44
44
|
s.a = 5
|
45
45
|
s.b = 10
|
46
|
-
|
47
|
-
s.try(:a).should == 5
|
46
|
+
|
47
|
+
s.try(:a).should == 5
|
48
48
|
s.try(:b).should == 10
|
49
49
|
s.try(:c).should == nil
|
50
|
-
|
50
|
+
|
51
51
|
lambda { s.try(:c) }.should_not raise_error
|
52
52
|
lambda { s.c }.should raise_error
|
53
53
|
|
54
54
|
def s.test(a); a; end
|
55
|
-
|
55
|
+
|
56
56
|
s.test(1).should == 1
|
57
57
|
s.try(:test, 1).should == 1
|
58
|
-
|
58
|
+
|
59
59
|
lambda { s.test }.should raise_error
|
60
60
|
lambda { s.try(:test) }.should raise_error
|
61
|
-
|
61
|
+
|
62
62
|
def s.blocky; yield; end
|
63
|
-
|
63
|
+
|
64
64
|
s.blocky{ 1 }.should == 1
|
65
65
|
s.try(:blocky){ 1 }.should == 1
|
66
66
|
s.try(:nonexistant){ 1 }.should == nil
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it "nots" do
|
70
70
|
10.even?.should == true
|
71
71
|
10.not.even?.should == false
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
it "alias_class_methods" do
|
75
75
|
class Blah
|
76
76
|
def self.classmethod
|
77
77
|
true
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
alias_class_method :aliased, :classmethod
|
81
81
|
end
|
82
|
-
|
83
|
-
lambda do
|
82
|
+
|
83
|
+
lambda do
|
84
84
|
Blah.classmethod.should == true
|
85
85
|
end.should_not raise_error
|
86
|
-
|
86
|
+
|
87
87
|
end
|
88
88
|
|
89
89
|
it "marshals/unmarshals" do
|
90
90
|
:whee.marshal.unmarshal.should == :whee
|
91
91
|
:whee.marshal.should == Marshal.dump(:whee)
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
it "selfs" do
|
95
95
|
a = [1,2,3,4]
|
96
96
|
a.map(&:self).should == a
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
it "memoizes" do
|
100
100
|
|
101
101
|
class Fake
|
@@ -118,32 +118,32 @@ describe Object do
|
|
118
118
|
f.instance_variable_get("@temp").should == true
|
119
119
|
f.instance_variable_get("@cacheme").should == true
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
end
|
123
123
|
|
124
124
|
|
125
125
|
describe Class do
|
126
|
-
|
126
|
+
|
127
127
|
it "uses" do
|
128
128
|
module Test1
|
129
129
|
def test1; :test1; end
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
module Test2
|
133
133
|
def test2; :test2; end
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
Hash.using(Test1).new.test1.should == :test1
|
137
137
|
Hash.using(Test2).new.test2.should == :test2
|
138
138
|
h = Hash.using(Test1, Test2).new
|
139
139
|
h.test1.should == :test1
|
140
140
|
h.test2.should == :test2
|
141
|
-
|
141
|
+
|
142
142
|
Hash.using(Test1) do |h|
|
143
143
|
h.new.test1.should == :test1
|
144
|
-
end
|
144
|
+
end
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
end
|
148
148
|
|
149
149
|
|
@@ -159,19 +159,19 @@ describe Numeric do
|
|
159
159
|
BigDecimal.new("1111.1234567").commatize.should == "1,111.1234567"
|
160
160
|
-1234567.1234567.underscorize.should == "-1_234_567.1234567"
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
it "does time things" do
|
164
164
|
1.second.should == 1
|
165
165
|
1.minute.should == 60
|
166
166
|
2.minutes.should == 120
|
167
167
|
2.hours.should == 120*60
|
168
168
|
2.5.days.should == 3600*24*2.5
|
169
|
-
|
169
|
+
|
170
170
|
5.days.ago.to_i.should == (Time.now - 5.days).to_i
|
171
|
-
1.year.ago.year.should == Time.now.year - 1
|
171
|
+
1.year.ago.year.should == Time.now.year - 1
|
172
172
|
5.days.from_now.to_i.should == (Time.now + 5.days).to_i
|
173
173
|
end
|
174
|
-
|
174
|
+
|
175
175
|
it "thingses" do
|
176
176
|
10.things.should == [0,1,2,3,4,5,6,7,8,9]
|
177
177
|
4.things {|n| n * 5 }.should == [0,5,10,15]
|
@@ -197,13 +197,13 @@ describe Numeric do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
describe String do
|
200
|
-
|
200
|
+
|
201
201
|
it "anys?" do
|
202
202
|
"".should_not be_any
|
203
203
|
"\n".should_not be_any
|
204
204
|
"YAY".should be_any
|
205
205
|
end
|
206
|
-
|
206
|
+
|
207
207
|
|
208
208
|
|
209
209
|
it "rot13s" do
|
@@ -211,24 +211,24 @@ describe String do
|
|
211
211
|
message.rot13.should_not == message
|
212
212
|
message.rot13.rot13.should == message
|
213
213
|
end
|
214
|
-
|
214
|
+
|
215
215
|
it "tightens" do
|
216
216
|
" hi there".tighten.should == "hi there"
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
it "dewhitespaces" do
|
220
220
|
"\nso there i \n was, eating my cookies".dewhitespace.should == "so there i was, eating my cookies"
|
221
221
|
end
|
222
|
-
|
222
|
+
|
223
223
|
it "nice_lineses" do
|
224
|
-
"\n\n\nblah\n\n\nblah\n\n\n".nice_lines.should == ["blah", "blah"]
|
224
|
+
"\n\n\nblah\n\n\nblah\n\n\n".nice_lines.should == ["blah", "blah"]
|
225
225
|
end
|
226
226
|
|
227
227
|
it "nice_htmls" do
|
228
228
|
s = "<a><b><p><c>whee</a>"
|
229
229
|
s.nice_html.should_not == s
|
230
230
|
end
|
231
|
-
|
231
|
+
|
232
232
|
it "wraps" do
|
233
233
|
s1 = "Hello there, I am a sentence or series of words."
|
234
234
|
s2 = "012345678901234567890123456789012345678901234567"
|
@@ -265,27 +265,27 @@ describe String do
|
|
265
265
|
it "strips color" do
|
266
266
|
s = "woot!"
|
267
267
|
color_s = s.light_green
|
268
|
-
color_s.strip_color.should == s
|
268
|
+
color_s.strip_color.should == s
|
269
269
|
end
|
270
|
-
|
270
|
+
|
271
271
|
it "urlencodes/decodes" do
|
272
272
|
s = "hi + there & mom + !!!!! I AM ON RSPEC"
|
273
273
|
s.urlencode.should_not == s
|
274
274
|
s.urlencode.should == "hi%20+%20there%20&%20mom%20+%20!!!!!%20I%20AM%20ON%20RSPEC"
|
275
275
|
s.urlencode.urldecode.should == s
|
276
276
|
end
|
277
|
-
|
277
|
+
|
278
278
|
it "to_paramses" do
|
279
279
|
"file=yay&setting=1&awesome=true".to_params.should == {"file" => "yay", "setting"=>"1", "awesome"=>"true"}
|
280
280
|
end
|
281
|
-
|
281
|
+
|
282
282
|
it "md5/sha1s" do
|
283
283
|
s = "hashme"
|
284
284
|
s.md5.should_not == s
|
285
285
|
s.sha1.should_not == s
|
286
286
|
s.sha1.should_not == s.md5
|
287
287
|
end
|
288
|
-
|
288
|
+
|
289
289
|
it "gzips/gunzips/delfates/inflates" do
|
290
290
|
s = "asdklfjasdfjaeh"
|
291
291
|
s.deflate.should_not == s
|
@@ -293,14 +293,14 @@ describe String do
|
|
293
293
|
|
294
294
|
s.gzip.should_not == s
|
295
295
|
s.gzip.gunzip.should == s
|
296
|
-
|
296
|
+
|
297
297
|
s.gzip(9).size.should < s.gzip(0).size
|
298
298
|
s.deflate(9).size.should < s.deflate(0).size
|
299
299
|
end
|
300
300
|
|
301
301
|
it "starts/endswith" do
|
302
|
-
"blahblahblah".startswith("blah").should == true
|
303
|
-
"blahblahblah".endswith("blah").should == true
|
302
|
+
"blahblahblah".startswith("blah").should == true
|
303
|
+
"blahblahblah".endswith("blah").should == true
|
304
304
|
end
|
305
305
|
|
306
306
|
it "amounts" do
|
@@ -320,7 +320,7 @@ describe String do
|
|
320
320
|
it "n choose r" do
|
321
321
|
n = 49
|
322
322
|
r = 6
|
323
|
-
|
323
|
+
|
324
324
|
n.choose(r).should == n.fact / (r.fact * (n-r).fact)
|
325
325
|
end
|
326
326
|
|
@@ -340,39 +340,39 @@ end
|
|
340
340
|
|
341
341
|
|
342
342
|
describe Integer do
|
343
|
-
|
343
|
+
|
344
344
|
it "integer?s" do
|
345
|
-
|
345
|
+
|
346
346
|
{
|
347
347
|
true => [ "123", "000", 123 ],
|
348
348
|
false => [ "123asdf", "asdfasdf", Object.new, nil, 123.45 ]
|
349
349
|
}.each do |expected_result, objects|
|
350
350
|
objects.each { |object| object.integer?.should == expected_result }
|
351
351
|
end
|
352
|
-
|
352
|
+
|
353
353
|
end
|
354
|
-
|
354
|
+
|
355
355
|
it "has bits" do
|
356
356
|
1.to_bits.should == [1]
|
357
357
|
2.to_bits.should == [0,1]
|
358
358
|
3.to_bits.should == [1,1]
|
359
359
|
42.to_bits.should == [0,1,0,1,0,1]
|
360
|
-
|
360
|
+
|
361
361
|
# round trip
|
362
362
|
20.times do
|
363
363
|
n = rand(918282393982)
|
364
364
|
n.to_bits.reverse.join.to_i(2).should == n
|
365
365
|
end
|
366
366
|
end
|
367
|
-
|
367
|
+
|
368
368
|
it "slices into bits" do
|
369
|
-
i = "111011".to_i(2)
|
370
|
-
# Note: to_i(2) accepts big-endian, while the Fixnum#[] slicing will return little endian.
|
369
|
+
i = "111011".to_i(2)
|
370
|
+
# Note: to_i(2) accepts big-endian, while the Fixnum#[] slicing will return little endian.
|
371
371
|
# So make sure to reverse the bit string for the specs.
|
372
372
|
|
373
373
|
i[0].should == 1
|
374
374
|
i[2].should == 0
|
375
|
-
|
375
|
+
|
376
376
|
i[0..2].should == [1,1,0]
|
377
377
|
i[-3..-1].should == [1,1,1]
|
378
378
|
i[0..-1].should == [1,1,0,1,1,1]
|
@@ -380,20 +380,20 @@ describe Integer do
|
|
380
380
|
|
381
381
|
it "converts to/from base62" do
|
382
382
|
Integer::BASE62_BASE.should == 62
|
383
|
-
|
383
|
+
|
384
384
|
[1,20,500,501,34191923].each do |n|
|
385
385
|
n.to_base62.from_base62.should == n
|
386
386
|
end
|
387
|
-
|
387
|
+
|
388
388
|
sum = "asdf".md5
|
389
389
|
sum.to_base62.from_base62.to_s(16).should == sum
|
390
390
|
end
|
391
|
-
|
391
|
+
|
392
392
|
it "factors numbers" do
|
393
393
|
10.factors.should == [2,5]
|
394
394
|
256.factors.should == [2,2,2,2,2,2,2,2]
|
395
395
|
end
|
396
|
-
|
396
|
+
|
397
397
|
it "primes numbers" do
|
398
398
|
[3,5,7,11,13,17,23,3628273133].all? { |n| n.should be_prime }
|
399
399
|
end
|
@@ -443,24 +443,24 @@ describe Number do
|
|
443
443
|
end
|
444
444
|
|
445
445
|
describe Array do
|
446
|
-
|
446
|
+
|
447
447
|
it "squashes" do
|
448
448
|
[1,2,[3,4,[5],[],[nil,nil],[6]]].squash.should == [1,2,3,4,5,6]
|
449
449
|
end
|
450
|
-
|
450
|
+
|
451
451
|
it "remove_ifs" do
|
452
452
|
nums = [1,2,3,4,5,6,7,8,9,10,11,12]
|
453
453
|
even = nums.remove_if { |n| n.even? } # remove all even numbers from the "nums" array and return them
|
454
|
-
odd = nums
|
455
|
-
|
454
|
+
odd = nums
|
455
|
+
|
456
456
|
even.should == [2,4,6,8,10,12]
|
457
457
|
odd.should == [1,3,5,7,9,11]
|
458
458
|
end
|
459
|
-
|
459
|
+
|
460
460
|
it "rzips" do
|
461
461
|
[5,39].rzip([:hours, :mins, :secs]).to_a.should == [ [5, :mins], [39, :secs] ]
|
462
462
|
end
|
463
|
-
|
463
|
+
|
464
464
|
it "middles" do
|
465
465
|
a = [0,1,2,3,4,5]
|
466
466
|
a.middle.should == 2
|
@@ -477,7 +477,7 @@ describe Array do
|
|
477
477
|
a.mode.should == 5
|
478
478
|
a.mean.should == a.sum.to_f / a.size
|
479
479
|
end
|
480
|
-
|
480
|
+
|
481
481
|
it "/'s" do
|
482
482
|
a = [1,2,3,4,5]
|
483
483
|
b = [1,2,3,4]
|
@@ -485,15 +485,15 @@ describe Array do
|
|
485
485
|
# splits?
|
486
486
|
(a/2).should == [[1,2,3],[4,5]]
|
487
487
|
(a/3).should == [[1,2],[3,4],[5]]
|
488
|
-
|
489
|
-
(b/2).should == [[1,2],[3,4]]
|
488
|
+
|
489
|
+
(b/2).should == [[1,2],[3,4]]
|
490
490
|
end
|
491
|
-
|
491
|
+
|
492
492
|
it "includes?s" do
|
493
493
|
[:a, :b, :c].includes?(:c).should == true
|
494
494
|
[:a, :b, :c].includes?(5).should == false
|
495
495
|
end
|
496
|
-
|
496
|
+
|
497
497
|
end
|
498
498
|
|
499
499
|
|
@@ -501,17 +501,17 @@ describe Enumerable do
|
|
501
501
|
|
502
502
|
it "maps deeply" do
|
503
503
|
[["a\n", "b\n"], ["c\n", "d\n"]].map_recursively(&:strip).should == [ %w[a b], %w[c d] ]
|
504
|
-
|
505
|
-
[[1,2],[3,4]].map_recursively {|e| e ** 2}.should == [[1,4],[9,16]]
|
506
|
-
[1,2,3,4].map_recursively {|e| e ** 2}.should == [1,4,9,16]
|
507
|
-
[[],[],1,2,3,4].map_recursively {|e| e ** 2}.should == [[], [], 1, 4, 9, 16]
|
504
|
+
|
505
|
+
[[1,2],[3,4]].map_recursively {|e| e ** 2}.should == [[1,4],[9,16]]
|
506
|
+
[1,2,3,4].map_recursively {|e| e ** 2}.should == [1,4,9,16]
|
507
|
+
[[],[],1,2,3,4].map_recursively {|e| e ** 2}.should == [[], [], 1, 4, 9, 16]
|
508
508
|
end
|
509
|
-
|
509
|
+
|
510
510
|
it "selects deeply" do
|
511
511
|
[[1,2],[3,4]].select_recursively {|e| e % 2 == 0 }.should == [[2],[4]]
|
512
|
-
[{},"Blah",1,2,3,4].select_recursively {|e| e == 2 }.should == [2]
|
512
|
+
[{},"Blah",1,2,3,4].select_recursively {|e| e == 2 }.should == [2]
|
513
513
|
end
|
514
|
-
|
514
|
+
|
515
515
|
it "splits" do
|
516
516
|
[1,2,3,4,5].split_at {|e| e == 3}.should == [ [1,2], [4,5] ]
|
517
517
|
[1,2,3,4,5].split_after {|e| e == 3}.should == [ [1,2,3], [4,5] ]
|
@@ -527,21 +527,21 @@ describe Enumerable do
|
|
527
527
|
it "splits with nested things" do
|
528
528
|
array = [ [],["a"],"a",[1,2,3] ]
|
529
529
|
|
530
|
-
lambda {
|
530
|
+
lambda {
|
531
531
|
array.split_at("a")
|
532
532
|
}.should_not raise_error
|
533
|
-
|
534
|
-
array.split_at("a").should == [ array[0..1], array[3..3] ]
|
533
|
+
|
534
|
+
array.split_at("a").should == [ array[0..1], array[3..3] ]
|
535
535
|
array.split_at([1,2,3]).should == [ array[0..2] ]
|
536
536
|
end
|
537
|
-
|
537
|
+
|
538
538
|
it "splits with arbitrary objects" do
|
539
539
|
arbitrary = Struct.new(:a, :b, :c)
|
540
|
-
|
540
|
+
|
541
541
|
particular = arbitrary.new(1,2,3)
|
542
542
|
array = [ arbitrary.new, arbitrary.new, particular, arbitrary.new]
|
543
|
-
|
544
|
-
array.split_at(particular).should == [ array[0..1], array[3..3] ]
|
543
|
+
|
544
|
+
array.split_at(particular).should == [ array[0..1], array[3..3] ]
|
545
545
|
end
|
546
546
|
|
547
547
|
it "splits lazily" do
|
@@ -566,7 +566,7 @@ describe Enumerable do
|
|
566
566
|
result.to_a.should == chunks
|
567
567
|
end
|
568
568
|
end
|
569
|
-
|
569
|
+
|
570
570
|
it "sums" do
|
571
571
|
[1,2,3,4,5].sum.should == 15
|
572
572
|
[1,2,3,4,5].sum { 1 }.should == 5
|
@@ -586,29 +586,29 @@ describe Enumerable do
|
|
586
586
|
a.foldl(:+).should == a.sum
|
587
587
|
%w[hi there].foldl(:+).should == "hithere"
|
588
588
|
|
589
|
-
[ [1],[2],[3],[4] ].foldl(:+).should == [1,2,3,4]
|
589
|
+
[ [1],[2],[3],[4] ].foldl(:+).should == [1,2,3,4]
|
590
590
|
end
|
591
|
-
|
591
|
+
|
592
592
|
it "powersets" do
|
593
|
-
[1,2,3].powerset.should == [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
|
594
|
-
[1,2].to_enum.powerset.should == [[], [1], [2], [1, 2]]
|
593
|
+
[1,2,3].powerset.to_a.should == [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
|
594
|
+
[1,2].to_enum.powerset.to_a.should == [[], [1], [2], [1, 2]]
|
595
595
|
end
|
596
|
-
|
596
|
+
|
597
597
|
it "unzips" do
|
598
598
|
[ [:a, 1], [:b, 2] ].unzip.should == [ [:a, :b], [1, 2] ]
|
599
599
|
end
|
600
|
-
|
600
|
+
|
601
601
|
it "group_neighbours_bys" do
|
602
602
|
a = [1,2,5,6,7,10,11,13]
|
603
603
|
result = a.group_neighbours_by { |a,b| b-a <= 1 }
|
604
604
|
result.should == [[1,2],[5,6,7],[10,11],[13]]
|
605
605
|
end
|
606
|
-
|
606
|
+
|
607
607
|
it "includes?s" do
|
608
608
|
[:a, :b, :c].to_enum.includes?(:c).should == true
|
609
609
|
[:a, :b, :c].to_enum.includes?(5).should == false
|
610
610
|
end
|
611
|
-
|
611
|
+
|
612
612
|
it "permutatitons and combinations" do
|
613
613
|
10.times.permutation(2).to_a.should == 10.times.to_a.permutation(2).to_a
|
614
614
|
10.times.combination(2).to_a.should == 10.times.to_a.combination(2).to_a
|
@@ -625,12 +625,18 @@ describe Enumerable do
|
|
625
625
|
(a * b).to_a.should == [[1,3],[1,4],[2,3],[2,4]]
|
626
626
|
end
|
627
627
|
|
628
|
+
it "sorts strings numerically" do
|
629
|
+
a = ["a1", "a11", "a2", "a3"]
|
630
|
+
a.sort_numerically.should == ["a1", "a2", "a3", "a11"]
|
631
|
+
a.sort.should_not == a.sort_numerically
|
632
|
+
end
|
633
|
+
|
628
634
|
end
|
629
635
|
|
630
636
|
describe Enumerator do
|
631
637
|
|
632
638
|
it "spins" do
|
633
|
-
lambda {
|
639
|
+
lambda {
|
634
640
|
(1..20).each.with_spinner(1).each { }
|
635
641
|
}.should_not raise_error
|
636
642
|
end
|
@@ -644,7 +650,7 @@ describe Enumerator do
|
|
644
650
|
end
|
645
651
|
|
646
652
|
it "multiplies" do
|
647
|
-
e = [1,2,3].to_enum * 3
|
653
|
+
e = [1,2,3].to_enum * 3
|
648
654
|
e.to_a.should == [1,2,3]*3
|
649
655
|
|
650
656
|
e = [1,2].to_enum * [3,4].to_enum
|
@@ -681,18 +687,18 @@ describe Hash do
|
|
681
687
|
|
682
688
|
it "selects recursively" do
|
683
689
|
# nevermind. hashes are stupid.
|
684
|
-
# {1=>2, 3=>{4=>5, 6=>7}}.select_recursively {|k,v| k == 1 }.should == {1=>2}
|
690
|
+
# {1=>2, 3=>{4=>5, 6=>7}}.select_recursively {|k,v| k == 1 }.should == {1=>2}
|
685
691
|
end
|
686
|
-
|
692
|
+
|
687
693
|
it "maps keys" do
|
688
694
|
h = @h.map_keys{|k| k.upcase}
|
689
695
|
h.keys.should == @h.keys.map{|k| k.upcase}
|
690
696
|
h.values.should == @h.values
|
691
|
-
|
697
|
+
|
692
698
|
h.map_keys! { 1 }
|
693
699
|
h.keys.should == [1]
|
694
700
|
end
|
695
|
-
|
701
|
+
|
696
702
|
it "maps values" do
|
697
703
|
h = @h.map_values{|v| v.upcase}
|
698
704
|
|
@@ -713,24 +719,24 @@ describe Hash do
|
|
713
719
|
|
714
720
|
h.slice("nonexistant").should == {}
|
715
721
|
end
|
716
|
-
|
722
|
+
|
717
723
|
it "mkdir_p's and trees" do
|
718
724
|
h = {}
|
719
725
|
h.mkdir_p(["a", "b", "c"]).should == {"a"=>{"b"=>{"c"=>{}}}}
|
720
726
|
h.mkdir_p(["a", "b", "whoa"]).should == {"a"=>{"b"=>{"c"=>{}, "whoa"=>{}}}}
|
721
|
-
|
722
|
-
lambda {
|
727
|
+
|
728
|
+
lambda {
|
723
729
|
h.tree.should =~ ["a", " b", " c", " whoa"]
|
724
730
|
}.should_not raise_error
|
725
731
|
end
|
726
|
-
|
732
|
+
|
727
733
|
it "to_querys" do
|
728
734
|
# this will probably fail half the time in Ruby 1.8 because the hash order is random
|
729
735
|
params = {"donkeys"=>"7", "stubborn"=>"true"}
|
730
736
|
params.to_query.to_params.should == params
|
731
737
|
params.to_query.in?(["donkeys=7&stubborn=true", "stubborn=true&donkeys=7"]).should == true
|
732
738
|
end
|
733
|
-
|
739
|
+
|
734
740
|
it "includes?s and key?s" do
|
735
741
|
@h.key?("key1").should == true
|
736
742
|
@h.includes?("key1").should == true
|
@@ -743,11 +749,11 @@ describe Hash do
|
|
743
749
|
changes = a.diff(b)
|
744
750
|
changes.should == {:a=>{:c=>[1, 2]}, :b=>[2, nil]}
|
745
751
|
a.apply_diff(changes).should == b
|
746
|
-
|
752
|
+
|
747
753
|
a.apply_diff!(changes)
|
748
754
|
a.should == b
|
749
755
|
end
|
750
|
-
|
756
|
+
|
751
757
|
end
|
752
758
|
|
753
759
|
|
@@ -761,7 +767,7 @@ describe Time do
|
|
761
767
|
2.months.ago.in_words.should == "2 months ago"
|
762
768
|
2.years.ago.in_words.should == "2 years ago"
|
763
769
|
2.5.years.ago.in_words.should == "2 years ago"
|
764
|
-
|
770
|
+
|
765
771
|
2.5.years.from_now.in_words.should == "2 years from now"
|
766
772
|
end
|
767
773
|
end
|
@@ -770,14 +776,14 @@ end
|
|
770
776
|
describe Binding do
|
771
777
|
a = 1
|
772
778
|
b = proc { a }
|
773
|
-
|
779
|
+
|
774
780
|
b.binding.keys.should =~ [:a, :b]
|
775
781
|
b.binding.keys.should == b.binding.local_variables
|
776
|
-
|
782
|
+
|
777
783
|
b.binding[:a].should == 1
|
778
784
|
b.binding["a"].should == 1
|
779
785
|
b.binding[:b].should == b
|
780
|
-
|
786
|
+
|
781
787
|
b.binding[:a] = 5
|
782
788
|
b.binding[:a].should == 5
|
783
789
|
b.call.should == 5
|
@@ -792,23 +798,23 @@ describe Proc do
|
|
792
798
|
a &= proc { 3 }
|
793
799
|
a.call.should == [[1,2],3]
|
794
800
|
end
|
795
|
-
|
801
|
+
|
796
802
|
it "chains procs" do
|
797
803
|
b = proc { 1 } | proc { |input| input + 1 }
|
798
804
|
b.call.should == 2
|
799
805
|
b = b.chain( proc { |input| input + 1 } )
|
800
|
-
b.call(1).should == 3
|
806
|
+
b.call(1).should == 3
|
801
807
|
end
|
802
|
-
|
808
|
+
|
803
809
|
end
|
804
810
|
|
805
811
|
|
806
812
|
describe BasicObject do
|
807
|
-
|
813
|
+
|
808
814
|
it "is blank!" do
|
809
815
|
BasicObject.methods(false).should == []
|
810
816
|
end
|
811
|
-
|
817
|
+
|
812
818
|
end
|
813
819
|
|
814
820
|
|
@@ -874,18 +880,18 @@ end
|
|
874
880
|
|
875
881
|
|
876
882
|
describe "truthiness" do
|
877
|
-
|
883
|
+
|
878
884
|
it "is truthy!" do
|
879
885
|
{
|
880
886
|
# truthy things
|
881
887
|
true => [
|
882
888
|
"yes", "on", "1", "Enabled",
|
883
|
-
1, 1.7,
|
889
|
+
1, 1.7,
|
884
890
|
:blah, true,
|
885
891
|
[1,2,3], [1,2,3].to_enum,
|
886
892
|
1938389127239847129803741980237498012374,
|
887
893
|
],
|
888
|
-
|
894
|
+
|
889
895
|
# untruthy things
|
890
896
|
false => [
|
891
897
|
"", " ", "\t\n ", "asdf", 0, 0.0, false, nil, [], [].to_enum,
|
@@ -894,7 +900,7 @@ describe "truthiness" do
|
|
894
900
|
objs.each { |obj| obj.truthy?.should == truthiness }
|
895
901
|
end
|
896
902
|
end
|
897
|
-
|
903
|
+
|
898
904
|
end
|
899
905
|
|
900
906
|
|
@@ -903,11 +909,11 @@ describe "proper grammar" do
|
|
903
909
|
it "responds_to?" do
|
904
910
|
proc{}.responds_to?(:call).should == true
|
905
911
|
end
|
906
|
-
|
912
|
+
|
907
913
|
it "includes?" do
|
908
914
|
[1,2,3,4,5].includes?(5).should == true
|
909
915
|
end
|
910
|
-
|
916
|
+
|
911
917
|
it "is_an?" do
|
912
918
|
Object.new.is_an?(Object).should == true
|
913
919
|
end
|
@@ -930,11 +936,11 @@ describe "global methods" do
|
|
930
936
|
|
931
937
|
it "locals's" do
|
932
938
|
require 'binding_of_caller'
|
933
|
-
|
939
|
+
|
934
940
|
a = 5
|
935
941
|
b = 10
|
936
942
|
_what_ = :splunge
|
937
|
-
|
943
|
+
|
938
944
|
locals.should == {:a=>5, :b=>10}
|
939
945
|
end
|
940
946
|
|
@@ -943,10 +949,10 @@ end
|
|
943
949
|
|
944
950
|
describe "to_jsons and to_yamls" do
|
945
951
|
data = {"a"=>"b", "yes"=>true, "hello"=>[1,2,3,4,5]}
|
946
|
-
data.to_json.from_json.should == data
|
952
|
+
data.to_json.from_json.should == data
|
947
953
|
|
948
954
|
data = {:a=>"b", 1=>true, "hello"=>[1,2,3,4,5]}
|
949
|
-
data.to_yaml.from_yaml.should == data
|
955
|
+
data.to_yaml.from_yaml.should == data
|
950
956
|
end
|
951
957
|
|
952
958
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.92
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- LICENSE
|
41
41
|
- README.rdoc
|
42
42
|
- Rakefile
|
43
|
+
- Snakefile
|
43
44
|
- TODO
|
44
45
|
- VERSION
|
45
46
|
- lib/epitools.rb
|
@@ -123,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
version: '0'
|
124
125
|
requirements: []
|
125
126
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.5.
|
127
|
+
rubygems_version: 2.5.2
|
127
128
|
signing_key:
|
128
129
|
specification_version: 3
|
129
130
|
summary: Not utils... METILS!
|
130
131
|
test_files: []
|
131
|
-
has_rdoc:
|