epitools 0.5.28 → 0.5.29
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/core_ext/array.rb +24 -1
- data/lib/epitools/core_ext/enumerable.rb +12 -3
- data/lib/epitools/core_ext/misc.rb +20 -2
- data/lib/epitools/core_ext/numbers.rb +24 -3
- data/lib/epitools/core_ext/string.rb +11 -1
- data/spec/.rspec +3 -0
- data/spec/core_ext_spec.rb +11 -0
- metadata +3 -3
- data/spec/spec.opts +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bd295ef4f56858d08b947caa73cdbc3e9bed57b
|
4
|
+
data.tar.gz: 335ab48442074262d802aada39a9fc51a53cd351
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58ebc78bf95e4bf09b8ab5e482e5c97edf4f5da6402994aca2147f8f27996a531dbb03ba848d438dfa87afe029189aaa1e503b838f9206415265a00166e127f8
|
7
|
+
data.tar.gz: afec7cf64783fd9073a6074af82049a5b2add2f0e2355f5e17a9ed809b4f01a58febbf40fd716008bb55a44cf660875af86de71d3e721cd4e2913f29c10b98d9
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.29
|
@@ -50,12 +50,35 @@ class Array
|
|
50
50
|
end
|
51
51
|
|
52
52
|
#
|
53
|
-
# Pick the middle element
|
53
|
+
# Pick the middle element
|
54
54
|
#
|
55
55
|
def middle
|
56
56
|
self[(size-1) / 2]
|
57
57
|
end
|
58
58
|
|
59
|
+
#
|
60
|
+
# Find the statistical mean
|
61
|
+
#
|
62
|
+
def mean
|
63
|
+
sum / size.to_f
|
64
|
+
end
|
65
|
+
alias_method :average, :mean
|
66
|
+
|
67
|
+
#
|
68
|
+
# Find the statistical median (middle value in the sorted dataset)
|
69
|
+
#
|
70
|
+
def median
|
71
|
+
sort.middle
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
#
|
76
|
+
# Find the statistical "mode" (most frequently occurring value)
|
77
|
+
#
|
78
|
+
def mode
|
79
|
+
counts.max_by { |k,v| v }.first
|
80
|
+
end
|
81
|
+
|
59
82
|
#
|
60
83
|
# XOR operator
|
61
84
|
#
|
@@ -140,7 +140,7 @@ module Enumerable
|
|
140
140
|
#
|
141
141
|
# Sum the elements
|
142
142
|
#
|
143
|
-
def sum
|
143
|
+
def sum(&block)
|
144
144
|
if block_given?
|
145
145
|
map(&block).reduce(:+)
|
146
146
|
else
|
@@ -362,8 +362,17 @@ module Enumerable
|
|
362
362
|
end
|
363
363
|
h
|
364
364
|
end
|
365
|
-
alias_method :
|
366
|
-
alias_method :
|
365
|
+
alias_method :count_by, :counts
|
366
|
+
alias_method :group_counts, :counts
|
367
|
+
|
368
|
+
|
369
|
+
#
|
370
|
+
# group_by the elements themselves
|
371
|
+
#
|
372
|
+
def groups
|
373
|
+
group_by(&:self)
|
374
|
+
end
|
375
|
+
alias_method :grouped, :groups
|
367
376
|
|
368
377
|
end
|
369
378
|
|
@@ -13,7 +13,7 @@ end
|
|
13
13
|
class Binding
|
14
14
|
|
15
15
|
#
|
16
|
-
# Get a
|
16
|
+
# Get a variable in this binding
|
17
17
|
#
|
18
18
|
def [](key)
|
19
19
|
eval(key.to_s)
|
@@ -31,7 +31,6 @@ class Binding
|
|
31
31
|
#
|
32
32
|
# Return all the local variables in the binding
|
33
33
|
#
|
34
|
-
|
35
34
|
if RUBY_VERSION["1.8"]
|
36
35
|
def local_variables
|
37
36
|
eval("local_variables").map(&:to_sym)
|
@@ -44,6 +43,19 @@ class Binding
|
|
44
43
|
|
45
44
|
alias_method :keys, :local_variables
|
46
45
|
|
46
|
+
#
|
47
|
+
# Combine the variables in two bindings (the latter having precedence)
|
48
|
+
#
|
49
|
+
def merge(other)
|
50
|
+
self.eval do
|
51
|
+
other.eval do
|
52
|
+
binding
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
alias_method :|, :merge
|
58
|
+
|
47
59
|
end
|
48
60
|
|
49
61
|
|
@@ -243,3 +255,9 @@ def STDIN.purge
|
|
243
255
|
# No more input!
|
244
256
|
end
|
245
257
|
end
|
258
|
+
|
259
|
+
|
260
|
+
class DateTime
|
261
|
+
def to_i; to_time.to_i; end
|
262
|
+
def to_f; to_time.to_f; end
|
263
|
+
end
|
@@ -99,13 +99,34 @@ class Numeric
|
|
99
99
|
|
100
100
|
end
|
101
101
|
|
102
|
+
|
103
|
+
def ln
|
104
|
+
Math.log(self)
|
105
|
+
end
|
106
|
+
|
107
|
+
|
102
108
|
# Math.log is different in 1.8
|
103
109
|
if RUBY_VERSION["1.8"]
|
104
|
-
|
110
|
+
|
111
|
+
def log(n=nil)
|
112
|
+
if n
|
113
|
+
Math.log(self) / Math.log(n)
|
114
|
+
else
|
115
|
+
Math.log(self)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
105
119
|
else
|
106
|
-
def log(n); Math.log(self, n); end
|
107
|
-
end
|
108
120
|
|
121
|
+
def log(n=nil)
|
122
|
+
if n
|
123
|
+
Math.log(self, n)
|
124
|
+
else
|
125
|
+
Math.log(self)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
109
130
|
|
110
131
|
BYTE_SIZE_TABLE = {
|
111
132
|
# power # units
|
@@ -74,7 +74,7 @@ class String
|
|
74
74
|
alias_method :strip_ansi, :strip_color
|
75
75
|
|
76
76
|
#
|
77
|
-
# Like #
|
77
|
+
# Like #each_line, but skips empty lines and removes \n's.
|
78
78
|
#
|
79
79
|
def nice_lines
|
80
80
|
# note: $/ is the platform's newline separator
|
@@ -84,6 +84,16 @@ class String
|
|
84
84
|
alias_method :nicelines, :nice_lines
|
85
85
|
alias_method :clean_lines, :nice_lines
|
86
86
|
|
87
|
+
#
|
88
|
+
# Like #each_line, but removes trailing \n
|
89
|
+
#
|
90
|
+
def each_chomped
|
91
|
+
each_line { |line| yield line.chomp }
|
92
|
+
end
|
93
|
+
alias_method :chomped_lines, :each_chomped
|
94
|
+
alias_method :chomp_lines, :each_chomped
|
95
|
+
|
96
|
+
|
87
97
|
#
|
88
98
|
# Wrap the lines in the string so they're at most "width" wide.
|
89
99
|
# (If no width is specified, defaults to the width of the terminal.)
|
data/spec/.rspec
ADDED
data/spec/core_ext_spec.rb
CHANGED
@@ -352,6 +352,16 @@ describe Array do
|
|
352
352
|
a << 6
|
353
353
|
a.middle.should == 3
|
354
354
|
end
|
355
|
+
|
356
|
+
it "means, medians, modes" do
|
357
|
+
a = [1,2,3,4,4,5,5,5,6]
|
358
|
+
# 0 1 2 3 4 5 6 7 8
|
359
|
+
# ^- median
|
360
|
+
|
361
|
+
a.median.should == 4
|
362
|
+
a.mode.should == 5
|
363
|
+
a.mean.should == a.sum.to_f / a.size
|
364
|
+
end
|
355
365
|
|
356
366
|
it "/'s" do
|
357
367
|
a = [1,2,3,4,5]
|
@@ -424,6 +434,7 @@ describe Enumerable do
|
|
424
434
|
|
425
435
|
it "sums" do
|
426
436
|
[1,2,3,4,5].sum.should == 15
|
437
|
+
[1,2,3,4,5].sum { 1 }.should == 5
|
427
438
|
end
|
428
439
|
|
429
440
|
it "averages" do
|
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.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/epitools/typed_struct.rb
|
82
82
|
- lib/epitools/wm.rb
|
83
83
|
- lib/epitools/zopen.rb
|
84
|
+
- spec/.rspec
|
84
85
|
- spec/autoreq_spec.rb
|
85
86
|
- spec/browser_spec.rb
|
86
87
|
- spec/clitools_spec.rb
|
@@ -95,7 +96,6 @@ files:
|
|
95
96
|
- spec/permutations_spec.rb
|
96
97
|
- spec/rash_spec.rb
|
97
98
|
- spec/ratio_spec.rb
|
98
|
-
- spec/spec.opts
|
99
99
|
- spec/spec_helper.rb
|
100
100
|
- spec/sys_spec.rb
|
101
101
|
- spec/term_spec.rb
|