ruby-nuggets 0.9.9 → 1.0.0
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
- metadata +20 -324
- data/COPYING +0 -663
- data/ChangeLog +0 -7
- data/README +0 -62
- data/Rakefile +0 -47
- data/lib/nuggets.rb +0 -73
- data/lib/nuggets/all.rb +0 -36
- data/lib/nuggets/all_mixins.rb +0 -34
- data/lib/nuggets/ansicolor2css.rb +0 -125
- data/lib/nuggets/argv/option.rb +0 -3
- data/lib/nuggets/argv/option_mixin.rb +0 -85
- data/lib/nuggets/array/boost.rb +0 -5
- data/lib/nuggets/array/boost_mixin.rb +0 -78
- data/lib/nuggets/array/combination.rb +0 -63
- data/lib/nuggets/array/correlation.rb +0 -5
- data/lib/nuggets/array/correlation_mixin.rb +0 -64
- data/lib/nuggets/array/flatten_once.rb +0 -57
- data/lib/nuggets/array/flush.rb +0 -5
- data/lib/nuggets/array/flush_mixin.rb +0 -47
- data/lib/nuggets/array/format.rb +0 -66
- data/lib/nuggets/array/hashify.rb +0 -5
- data/lib/nuggets/array/hashify_mixin.rb +0 -48
- data/lib/nuggets/array/histogram.rb +0 -5
- data/lib/nuggets/array/histogram_mixin.rb +0 -170
- data/lib/nuggets/array/in_order.rb +0 -51
- data/lib/nuggets/array/limit.rb +0 -5
- data/lib/nuggets/array/limit_mixin.rb +0 -57
- data/lib/nuggets/array/mean.rb +0 -5
- data/lib/nuggets/array/mean_mixin.rb +0 -203
- data/lib/nuggets/array/median.rb +0 -5
- data/lib/nuggets/array/median_mixin.rb +0 -74
- data/lib/nuggets/array/mode.rb +0 -5
- data/lib/nuggets/array/mode_mixin.rb +0 -70
- data/lib/nuggets/array/monotone.rb +0 -84
- data/lib/nuggets/array/only.rb +0 -42
- data/lib/nuggets/array/rand.rb +0 -45
- data/lib/nuggets/array/regression.rb +0 -5
- data/lib/nuggets/array/regression_mixin.rb +0 -150
- data/lib/nuggets/array/runiq.rb +0 -5
- data/lib/nuggets/array/runiq_mixin.rb +0 -53
- data/lib/nuggets/array/shuffle.rb +0 -133
- data/lib/nuggets/array/standard_deviation.rb +0 -5
- data/lib/nuggets/array/standard_deviation_mixin.rb +0 -51
- data/lib/nuggets/array/to_hash.rb +0 -65
- data/lib/nuggets/array/variance.rb +0 -5
- data/lib/nuggets/array/variance_mixin.rb +0 -82
- data/lib/nuggets/cli.rb +0 -8
- data/lib/nuggets/content_type.rb +0 -98
- data/lib/nuggets/dotted_decimal.rb +0 -60
- data/lib/nuggets/enumerable/agrep.rb +0 -80
- data/lib/nuggets/enumerable/all_any_extended.rb +0 -67
- data/lib/nuggets/enumerable/minmax.rb +0 -103
- data/lib/nuggets/env/set.rb +0 -3
- data/lib/nuggets/env/set_mixin.rb +0 -68
- data/lib/nuggets/env/user_encoding.rb +0 -3
- data/lib/nuggets/env/user_encoding_mixin.rb +0 -55
- data/lib/nuggets/env/user_home.rb +0 -3
- data/lib/nuggets/env/user_home_mixin.rb +0 -57
- data/lib/nuggets/file/ext.rb +0 -5
- data/lib/nuggets/file/ext_mixin.rb +0 -88
- data/lib/nuggets/file/replace.rb +0 -5
- data/lib/nuggets/file/replace_mixin.rb +0 -56
- data/lib/nuggets/file/sub.rb +0 -5
- data/lib/nuggets/file/sub_mixin.rb +0 -96
- data/lib/nuggets/file/which.rb +0 -5
- data/lib/nuggets/file/which_mixin.rb +0 -73
- data/lib/nuggets/hash/at.rb +0 -69
- data/lib/nuggets/hash/deep_fetch.rb +0 -5
- data/lib/nuggets/hash/deep_fetch_mixin.rb +0 -75
- data/lib/nuggets/hash/deep_merge.rb +0 -5
- data/lib/nuggets/hash/deep_merge_mixin.rb +0 -54
- data/lib/nuggets/hash/idmap.rb +0 -5
- data/lib/nuggets/hash/idmap_mixin.rb +0 -42
- data/lib/nuggets/hash/in_order.rb +0 -44
- data/lib/nuggets/hash/insert.rb +0 -54
- data/lib/nuggets/hash/nest.rb +0 -5
- data/lib/nuggets/hash/nest_mixin.rb +0 -79
- data/lib/nuggets/hash/only.rb +0 -53
- data/lib/nuggets/hash/seen.rb +0 -5
- data/lib/nuggets/hash/seen_mixin.rb +0 -59
- data/lib/nuggets/hash/unroll.rb +0 -5
- data/lib/nuggets/hash/unroll_mixin.rb +0 -89
- data/lib/nuggets/hash/zip.rb +0 -5
- data/lib/nuggets/hash/zip_mixin.rb +0 -160
- data/lib/nuggets/i18n.rb +0 -156
- data/lib/nuggets/integer/factorial.rb +0 -57
- data/lib/nuggets/integer/length.rb +0 -5
- data/lib/nuggets/integer/length_mixin.rb +0 -50
- data/lib/nuggets/integer/map.rb +0 -5
- data/lib/nuggets/integer/map_mixin.rb +0 -43
- data/lib/nuggets/integer/to_binary_s.rb +0 -39
- data/lib/nuggets/io/agrep.rb +0 -44
- data/lib/nuggets/io/interact.rb +0 -5
- data/lib/nuggets/io/interact_mixin.rb +0 -160
- data/lib/nuggets/io/modes.rb +0 -122
- data/lib/nuggets/io/null.rb +0 -5
- data/lib/nuggets/io/null_mixin.rb +0 -41
- data/lib/nuggets/io/redirect.rb +0 -5
- data/lib/nuggets/io/redirect_mixin.rb +0 -51
- data/lib/nuggets/lazy_attr.rb +0 -45
- data/lib/nuggets/log_parser.rb +0 -71
- data/lib/nuggets/log_parser/apache.rb +0 -102
- data/lib/nuggets/log_parser/rails.rb +0 -220
- data/lib/nuggets/lsi.rb +0 -8
- data/lib/nuggets/midos.rb +0 -8
- data/lib/nuggets/mysql.rb +0 -8
- data/lib/nuggets/net/success.rb +0 -60
- data/lib/nuggets/numeric/between.rb +0 -2
- data/lib/nuggets/numeric/duration.rb +0 -101
- data/lib/nuggets/numeric/limit.rb +0 -63
- data/lib/nuggets/numeric/signum.rb +0 -53
- data/lib/nuggets/numeric/to_multiple.rb +0 -62
- data/lib/nuggets/object/blank.rb +0 -20
- data/lib/nuggets/object/blank_mixin.rb +0 -100
- data/lib/nuggets/object/boolean.rb +0 -5
- data/lib/nuggets/object/boolean_mixin.rb +0 -62
- data/lib/nuggets/object/eigenclass.rb +0 -2
- data/lib/nuggets/object/ghost_class.rb +0 -2
- data/lib/nuggets/object/metaclass.rb +0 -2
- data/lib/nuggets/object/msend.rb +0 -5
- data/lib/nuggets/object/msend_mixin.rb +0 -44
- data/lib/nuggets/object/silence.rb +0 -5
- data/lib/nuggets/object/silence_mixin.rb +0 -45
- data/lib/nuggets/object/singleton_class.rb +0 -5
- data/lib/nuggets/object/singleton_class_mixin.rb +0 -96
- data/lib/nuggets/object/uniclass.rb +0 -2
- data/lib/nuggets/object/virtual_class.rb +0 -2
- data/lib/nuggets/pluggable.rb +0 -92
- data/lib/nuggets/proc/bind.rb +0 -5
- data/lib/nuggets/proc/bind_mixin.rb +0 -52
- data/lib/nuggets/range/quantile.rb +0 -5
- data/lib/nuggets/range/quantile_mixin.rb +0 -43
- data/lib/nuggets/rdf/compression.rb +0 -6
- data/lib/nuggets/rdf/prefix.rb +0 -6
- data/lib/nuggets/rdf/turtle.rb +0 -8
- data/lib/nuggets/rdf/turtle/reader.rb +0 -6
- data/lib/nuggets/rdf/uri.rb +0 -6
- data/lib/nuggets/ruby.rb +0 -236
- data/lib/nuggets/statistics.rb +0 -12
- data/lib/nuggets/statistics_mixins.rb +0 -12
- data/lib/nuggets/string/camelscore.rb +0 -5
- data/lib/nuggets/string/camelscore_mixin.rb +0 -117
- data/lib/nuggets/string/capitalize_first.rb +0 -47
- data/lib/nuggets/string/case.rb +0 -82
- data/lib/nuggets/string/evaluate.rb +0 -5
- data/lib/nuggets/string/evaluate_mixin.rb +0 -48
- data/lib/nuggets/string/msub.rb +0 -85
- data/lib/nuggets/string/nsub.rb +0 -66
- data/lib/nuggets/string/sub_with_md.rb +0 -112
- data/lib/nuggets/string/wc.rb +0 -5
- data/lib/nuggets/string/wc_mixin.rb +0 -96
- data/lib/nuggets/string/word_wrap.rb +0 -77
- data/lib/nuggets/string/xor.rb +0 -5
- data/lib/nuggets/string/xor_mixin.rb +0 -60
- data/lib/nuggets/tempfile/open.rb +0 -58
- data/lib/nuggets/uri/content_type.rb +0 -5
- data/lib/nuggets/uri/content_type_mixin.rb +0 -48
- data/lib/nuggets/uri/exist.rb +0 -5
- data/lib/nuggets/uri/exist_mixin.rb +0 -57
- data/lib/nuggets/uri/redirect.rb +0 -5
- data/lib/nuggets/uri/redirect_mixin.rb +0 -102
- data/lib/nuggets/util/ansicolor2css.rb +0 -4
- data/lib/nuggets/util/cli.rb +0 -4
- data/lib/nuggets/util/content_type.rb +0 -4
- data/lib/nuggets/util/dotted_decimal.rb +0 -3
- data/lib/nuggets/util/i18n.rb +0 -4
- data/lib/nuggets/util/lazy_attr.rb +0 -4
- data/lib/nuggets/util/log_parser.rb +0 -4
- data/lib/nuggets/util/log_parser/apache.rb +0 -4
- data/lib/nuggets/util/log_parser/rails.rb +0 -4
- data/lib/nuggets/util/midos.rb +0 -4
- data/lib/nuggets/util/mysql.rb +0 -4
- data/lib/nuggets/util/pluggable.rb +0 -4
- data/lib/nuggets/util/ruby.rb +0 -4
- data/lib/nuggets/version.rb +0 -27
- data/spec/nuggets/array/boost_spec.rb +0 -50
- data/spec/nuggets/array/combination_spec.rb +0 -25
- data/spec/nuggets/array/correlation_spec.rb +0 -81
- data/spec/nuggets/array/flatten_once_spec.rb +0 -16
- data/spec/nuggets/array/flush_spec.rb +0 -43
- data/spec/nuggets/array/format_spec.rb +0 -52
- data/spec/nuggets/array/hashify_spec.rb +0 -41
- data/spec/nuggets/array/histogram_spec.rb +0 -87
- data/spec/nuggets/array/in_order_spec.rb +0 -13
- data/spec/nuggets/array/limit_spec.rb +0 -62
- data/spec/nuggets/array/mean_spec.rb +0 -203
- data/spec/nuggets/array/median_spec.rb +0 -77
- data/spec/nuggets/array/mode_spec.rb +0 -57
- data/spec/nuggets/array/monotone_spec.rb +0 -30
- data/spec/nuggets/array/only_spec.rb +0 -26
- data/spec/nuggets/array/regression_spec.rb +0 -54
- data/spec/nuggets/array/runiq_spec.rb +0 -25
- data/spec/nuggets/array/standard_deviation_spec.rb +0 -33
- data/spec/nuggets/array/to_hash_spec.rb +0 -28
- data/spec/nuggets/array/variance_spec.rb +0 -106
- data/spec/nuggets/dotted_decimal_spec.rb +0 -27
- data/spec/nuggets/enumerable/all_any_extended_spec.rb +0 -31
- data/spec/nuggets/enumerable/minmax_spec.rb +0 -21
- data/spec/nuggets/env/set_spec.rb +0 -29
- data/spec/nuggets/env/user_encoding_spec.rb +0 -38
- data/spec/nuggets/env/user_home_spec.rb +0 -42
- data/spec/nuggets/file/ext_spec.rb +0 -38
- data/spec/nuggets/file/replace_spec.rb +0 -95
- data/spec/nuggets/file/sub_spec.rb +0 -149
- data/spec/nuggets/file/which_spec.rb +0 -22
- data/spec/nuggets/hash/at_spec.rb +0 -19
- data/spec/nuggets/hash/deep_fetch_spec.rb +0 -159
- data/spec/nuggets/hash/deep_merge_spec.rb +0 -78
- data/spec/nuggets/hash/in_order_spec.rb +0 -12
- data/spec/nuggets/hash/insert_spec.rb +0 -13
- data/spec/nuggets/hash/nest_spec.rb +0 -102
- data/spec/nuggets/hash/only_spec.rb +0 -29
- data/spec/nuggets/hash/seen_spec.rb +0 -36
- data/spec/nuggets/hash/unroll_spec.rb +0 -68
- data/spec/nuggets/i18n_spec.rb +0 -13
- data/spec/nuggets/integer/factorial_spec.rb +0 -10
- data/spec/nuggets/integer/length_spec.rb +0 -18
- data/spec/nuggets/integer/map_spec.rb +0 -19
- data/spec/nuggets/integer/to_binary_s_spec.rb +0 -19
- data/spec/nuggets/numeric/duration_spec.rb +0 -25
- data/spec/nuggets/numeric/limit_spec.rb +0 -16
- data/spec/nuggets/numeric/signum_spec.rb +0 -16
- data/spec/nuggets/numeric/to_multiple_spec.rb +0 -16
- data/spec/nuggets/object/blank_spec.rb +0 -34
- data/spec/nuggets/object/boolean_spec.rb +0 -23
- data/spec/nuggets/object/msend_spec.rb +0 -25
- data/spec/nuggets/object/silence_spec.rb +0 -36
- data/spec/nuggets/object/singleton_class_spec.rb +0 -51
- data/spec/nuggets/proc/bind_spec.rb +0 -28
- data/spec/nuggets/range/quantile_spec.rb +0 -33
- data/spec/nuggets/string/camelscore_spec.rb +0 -114
- data/spec/nuggets/string/capitalize_first_spec.rb +0 -13
- data/spec/nuggets/string/case_spec.rb +0 -31
- data/spec/nuggets/string/evaluate_spec.rb +0 -24
- data/spec/nuggets/string/msub_spec.rb +0 -20
- data/spec/nuggets/string/nsub_spec.rb +0 -13
- data/spec/nuggets/string/sub_with_md_spec.rb +0 -25
- data/spec/nuggets/string/wc_spec.rb +0 -73
- data/spec/nuggets/string/word_wrap_spec.rb +0 -81
- data/spec/nuggets/string/xor_spec.rb +0 -57
- data/spec/nuggets/uri/content_type_spec.rb +0 -42
- data/spec/nuggets/uri/exist_spec.rb +0 -49
- data/spec/spec_helper.rb +0 -36
data/lib/nuggets/array/boost.rb
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
#--
|
|
2
|
-
###############################################################################
|
|
3
|
-
# #
|
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
|
5
|
-
# language. #
|
|
6
|
-
# #
|
|
7
|
-
# Copyright (C) 2007-2012 Jens Wille #
|
|
8
|
-
# #
|
|
9
|
-
# Authors: #
|
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
|
11
|
-
# #
|
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
|
15
|
-
# option) any later version. #
|
|
16
|
-
# #
|
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
|
20
|
-
# for more details. #
|
|
21
|
-
# #
|
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
24
|
-
# #
|
|
25
|
-
###############################################################################
|
|
26
|
-
#++
|
|
27
|
-
|
|
28
|
-
require 'nuggets/array/mean_mixin'
|
|
29
|
-
|
|
30
|
-
module Nuggets
|
|
31
|
-
class Array
|
|
32
|
-
module BoostMixin
|
|
33
|
-
|
|
34
|
-
def self.included(base)
|
|
35
|
-
base.send :include, Nuggets::Array::MeanMixin
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# call-seq:
|
|
39
|
-
# array.boost_factor(other_array) => aFloat
|
|
40
|
-
# array.boost_factor(other_array) { |array| ... } => aFloat
|
|
41
|
-
#
|
|
42
|
-
# Calculates the "boost factor" *from* the series of values in _array_ *to*
|
|
43
|
-
# the series of values in +other_array+ by means of their arithmetic mean
|
|
44
|
-
# or the value returned from the block given.
|
|
45
|
-
#
|
|
46
|
-
# Example:
|
|
47
|
-
#
|
|
48
|
-
# # series of runtime measurements for old version
|
|
49
|
-
# a = [1.5, 1.6, 1.4]
|
|
50
|
-
#
|
|
51
|
-
# # series of runtime measurements for new version
|
|
52
|
-
# b = [0.7, 0.8, 0.8]
|
|
53
|
-
#
|
|
54
|
-
# # what speedup did we get? => almost 50%
|
|
55
|
-
# a.boost_factor(b) #=> -0.48888888888888893
|
|
56
|
-
def boost_factor(other, &block)
|
|
57
|
-
block ||= :mean.to_proc
|
|
58
|
-
block[other] / block[self] - 1
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
alias_method :boof, :boost_factor
|
|
62
|
-
|
|
63
|
-
# call-seq:
|
|
64
|
-
# array.boost(factor) => anArray
|
|
65
|
-
#
|
|
66
|
-
# Maps each value in _array_ to its "boosted" value according to +factor+.
|
|
67
|
-
# (Cf. #boost_factor)
|
|
68
|
-
#
|
|
69
|
-
# Example:
|
|
70
|
-
#
|
|
71
|
-
# a.boost(a.boost_factor(b)).mean == b.mean
|
|
72
|
-
def boost(factor)
|
|
73
|
-
map { |x| x * (1 + factor) }
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
#--
|
|
2
|
-
###############################################################################
|
|
3
|
-
# #
|
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
|
5
|
-
# language. #
|
|
6
|
-
# #
|
|
7
|
-
# Copyright (C) 2007-2011 Jens Wille #
|
|
8
|
-
# #
|
|
9
|
-
# Authors: #
|
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
|
11
|
-
# #
|
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
|
15
|
-
# option) any later version. #
|
|
16
|
-
# #
|
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
|
20
|
-
# for more details. #
|
|
21
|
-
# #
|
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
24
|
-
# #
|
|
25
|
-
###############################################################################
|
|
26
|
-
#++
|
|
27
|
-
|
|
28
|
-
class Array
|
|
29
|
-
|
|
30
|
-
# call-seq:
|
|
31
|
-
# array.comb(n, ...) => new_array
|
|
32
|
-
# array.comb(n, ...) { |combination| ... } => new_array
|
|
33
|
-
#
|
|
34
|
-
# Returns an array of arrays of each possible +n+-combination of _array_ for each
|
|
35
|
-
# given +n+. If a block is given, each +combination+ is yielded to it. Based on
|
|
36
|
-
# <http://blade.nagaokaut.ac.jp/~sinara/ruby/math/combinatorics/array-comb.rb>.
|
|
37
|
-
def comb(*sizes)
|
|
38
|
-
# If no sizes are given, produce all!
|
|
39
|
-
sizes = (0..size).to_a.reverse if sizes.empty?
|
|
40
|
-
|
|
41
|
-
combinations, collect_and_yield = [], lambda { |combination|
|
|
42
|
-
yield combination if block_given?
|
|
43
|
-
combinations << combination
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
sizes.each { |n|
|
|
47
|
-
case n
|
|
48
|
-
when 0 # Short-cut (breaks recursion)
|
|
49
|
-
collect_and_yield[[]]
|
|
50
|
-
when 1..size # Ignore out-of-range values
|
|
51
|
-
self[1..-1].comb(n - 1) { |combination|
|
|
52
|
-
collect_and_yield[combination.unshift(first)]
|
|
53
|
-
}
|
|
54
|
-
self[1..-1].comb(n) { |combination|
|
|
55
|
-
collect_and_yield[combination]
|
|
56
|
-
}
|
|
57
|
-
end
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
combinations
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
end
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
#--
|
|
2
|
-
###############################################################################
|
|
3
|
-
# #
|
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
|
5
|
-
# language. #
|
|
6
|
-
# #
|
|
7
|
-
# Copyright (C) 2007-2011 Jens Wille #
|
|
8
|
-
# #
|
|
9
|
-
# Authors: #
|
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
|
11
|
-
# #
|
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
|
15
|
-
# option) any later version. #
|
|
16
|
-
# #
|
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
|
20
|
-
# for more details. #
|
|
21
|
-
# #
|
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
24
|
-
# #
|
|
25
|
-
###############################################################################
|
|
26
|
-
#++
|
|
27
|
-
|
|
28
|
-
require 'nuggets/array/standard_deviation_mixin'
|
|
29
|
-
|
|
30
|
-
module Nuggets
|
|
31
|
-
class Array
|
|
32
|
-
module CorrelationMixin
|
|
33
|
-
|
|
34
|
-
def self.included(base)
|
|
35
|
-
base.send :include, Nuggets::Array::StandardDeviationMixin
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# call-seq:
|
|
39
|
-
# array.correlation_coefficient => anArray
|
|
40
|
-
#
|
|
41
|
-
# Calculates the {Pearson product-moment correlation
|
|
42
|
-
# coefficient}[http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient]
|
|
43
|
-
# for the <tt>{x,y}</tt> pairs in _array_. If _array_ only contains
|
|
44
|
-
# values instead of pairs, +y+ will be the value and +x+ will be each
|
|
45
|
-
# value's position (rank) in _array_.
|
|
46
|
-
def correlation_coefficient
|
|
47
|
-
return 0.0 if empty?
|
|
48
|
-
|
|
49
|
-
target = first.respond_to?(:to_ary) ? self :
|
|
50
|
-
self.class.new(size) { |i| [i + 1, at(i)] }
|
|
51
|
-
|
|
52
|
-
c = target.cov
|
|
53
|
-
|
|
54
|
-
(sx = target.std { |x, _| x }).zero? ||
|
|
55
|
-
(sy = target.std { |_, y| y }).zero? ?
|
|
56
|
-
c < 0 ? -1.0 : 1.0 : c / (sx * sy)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
alias_method :corr, :correlation_coefficient
|
|
60
|
-
alias_method :pmcc, :correlation_coefficient
|
|
61
|
-
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
#--
|
|
2
|
-
###############################################################################
|
|
3
|
-
# #
|
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
|
5
|
-
# language. #
|
|
6
|
-
# #
|
|
7
|
-
# Copyright (C) 2007-2011 Jens Wille #
|
|
8
|
-
# #
|
|
9
|
-
# Authors: #
|
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
|
11
|
-
# #
|
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
|
15
|
-
# option) any later version. #
|
|
16
|
-
# #
|
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
|
20
|
-
# for more details. #
|
|
21
|
-
# #
|
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
24
|
-
# #
|
|
25
|
-
###############################################################################
|
|
26
|
-
#++
|
|
27
|
-
|
|
28
|
-
class Array
|
|
29
|
-
|
|
30
|
-
# call-seq:
|
|
31
|
-
# array.flatten_once => new_array
|
|
32
|
-
#
|
|
33
|
-
# Flatten _array_ by _one_ level only. Pretty straight-forward port of David
|
|
34
|
-
# Alan Black's flattenx C implementation (though much slower, of course ;-).
|
|
35
|
-
def flatten_once
|
|
36
|
-
flat = []
|
|
37
|
-
|
|
38
|
-
each { |element|
|
|
39
|
-
if element.is_a?(::Array)
|
|
40
|
-
flat += element
|
|
41
|
-
else
|
|
42
|
-
flat << element
|
|
43
|
-
end
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
flat
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# call-seq:
|
|
50
|
-
# array.flatten_once! => array
|
|
51
|
-
#
|
|
52
|
-
# Destructive version of #flatten_once.
|
|
53
|
-
def flatten_once!
|
|
54
|
-
replace(flatten_once)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
end
|
data/lib/nuggets/array/flush.rb
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
#--
|
|
2
|
-
###############################################################################
|
|
3
|
-
# #
|
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
|
5
|
-
# language. #
|
|
6
|
-
# #
|
|
7
|
-
# Copyright (C) 2007-2013 Jens Wille #
|
|
8
|
-
# #
|
|
9
|
-
# Authors: #
|
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
|
11
|
-
# #
|
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
|
15
|
-
# option) any later version. #
|
|
16
|
-
# #
|
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
|
20
|
-
# for more details. #
|
|
21
|
-
# #
|
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
24
|
-
# #
|
|
25
|
-
###############################################################################
|
|
26
|
-
#++
|
|
27
|
-
|
|
28
|
-
module Nuggets
|
|
29
|
-
class Array
|
|
30
|
-
module FlushMixin
|
|
31
|
-
|
|
32
|
-
# call-seq:
|
|
33
|
-
# array.flush => anArray
|
|
34
|
-
# array.flush { |array| ... } => anObject
|
|
35
|
-
#
|
|
36
|
-
# If a block is given, yields _array_ to the block and
|
|
37
|
-
# clears it afterwards; returns the return value of the
|
|
38
|
-
# block. Otherwise clears _array_ and returns its contents.
|
|
39
|
-
def flush
|
|
40
|
-
ret = block_given? ? yield(self) : dup
|
|
41
|
-
clear
|
|
42
|
-
ret
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
data/lib/nuggets/array/format.rb
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#--
|
|
2
|
-
###############################################################################
|
|
3
|
-
# #
|
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
|
5
|
-
# language. #
|
|
6
|
-
# #
|
|
7
|
-
# Copyright (C) 2007-2011 Jens Wille #
|
|
8
|
-
# #
|
|
9
|
-
# Authors: #
|
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
|
11
|
-
# #
|
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
|
15
|
-
# option) any later version. #
|
|
16
|
-
# #
|
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
|
20
|
-
# for more details. #
|
|
21
|
-
# #
|
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
24
|
-
# #
|
|
25
|
-
###############################################################################
|
|
26
|
-
#++
|
|
27
|
-
|
|
28
|
-
require 'nuggets/array/combination'
|
|
29
|
-
|
|
30
|
-
class Array
|
|
31
|
-
|
|
32
|
-
# call-seq:
|
|
33
|
-
# array % other_array => aString
|
|
34
|
-
# array % str => aString
|
|
35
|
-
#
|
|
36
|
-
# Format--Uses the first string in _array_ for which the corresponding
|
|
37
|
-
# combination of _other_array_ does not contain blank elements as a format
|
|
38
|
-
# specification, and returns the result of applying it to that combination
|
|
39
|
-
# (cf. String#%). Returns an empty string if _other_array_ is empty.
|
|
40
|
-
#
|
|
41
|
-
# Applies to string argument accordingly: First string in _array_ applied to
|
|
42
|
-
# _str_; empty string if _str_ is empty.
|
|
43
|
-
def %(args)
|
|
44
|
-
opts = { :sep => ', ' }
|
|
45
|
-
opts.update(pop) if last.is_a?(::Hash)
|
|
46
|
-
|
|
47
|
-
default = lambda { |n| ['%s'] * n * opts[:sep] }
|
|
48
|
-
|
|
49
|
-
case args
|
|
50
|
-
when ::String
|
|
51
|
-
return (first || default[1]) % args unless
|
|
52
|
-
args.nil? || args.empty?
|
|
53
|
-
when ::Array
|
|
54
|
-
i = 0
|
|
55
|
-
[*args].comb { |x|
|
|
56
|
-
return (self[i] || default[x.size]) % x unless
|
|
57
|
-
x.empty? || x.any? { |y| y.nil? || y.empty? }
|
|
58
|
-
|
|
59
|
-
i += 1
|
|
60
|
-
}
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
''
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
end
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
#--
|
|
2
|
-
###############################################################################
|
|
3
|
-
# #
|
|
4
|
-
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
|
5
|
-
# language. #
|
|
6
|
-
# #
|
|
7
|
-
# Copyright (C) 2007-2014 Jens Wille #
|
|
8
|
-
# #
|
|
9
|
-
# Authors: #
|
|
10
|
-
# Jens Wille <jens.wille@gmail.com> #
|
|
11
|
-
# #
|
|
12
|
-
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
|
13
|
-
# under the terms of the GNU Affero General Public License as published by #
|
|
14
|
-
# the Free Software Foundation; either version 3 of the License, or (at your #
|
|
15
|
-
# option) any later version. #
|
|
16
|
-
# #
|
|
17
|
-
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
|
18
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
19
|
-
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License #
|
|
20
|
-
# for more details. #
|
|
21
|
-
# #
|
|
22
|
-
# You should have received a copy of the GNU Affero General Public License #
|
|
23
|
-
# along with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
24
|
-
# #
|
|
25
|
-
###############################################################################
|
|
26
|
-
#++
|
|
27
|
-
|
|
28
|
-
module Nuggets
|
|
29
|
-
class Array
|
|
30
|
-
module HashifyMixin
|
|
31
|
-
|
|
32
|
-
def hashify(value = nil, &block)
|
|
33
|
-
block ||= lambda { |key| [key, key] }
|
|
34
|
-
|
|
35
|
-
hash = case value
|
|
36
|
-
when ::Hash then value
|
|
37
|
-
when ::Proc then ::Hash.new(&value)
|
|
38
|
-
else ::Hash.new(value)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
each { |key| hash.store(*block[key]) }
|
|
42
|
-
|
|
43
|
-
hash
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|