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
|
@@ -1,43 +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
|
-
module Nuggets
|
|
29
|
-
class Range
|
|
30
|
-
module QuantileMixin
|
|
31
|
-
|
|
32
|
-
# call-seq:
|
|
33
|
-
# range.quantile(value[, order]) => anInteger
|
|
34
|
-
#
|
|
35
|
-
# Determines the <tt>order</tt>-quantile of +value+ in _range_.
|
|
36
|
-
def quantile(value, order = 100)
|
|
37
|
-
value < first ? 1 : value >= last ? order :
|
|
38
|
-
((value - first) / ((last - first) / order.to_f)).to_i + 1
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
begin
|
|
2
|
-
require 'turtle_reader/rdf/compression'
|
|
3
|
-
warn "#{__FILE__}: 'nuggets/rdf/compression' is deprecated, use 'turtle_reader/rdf/compression' instead." unless ENV['NUGGETS_DEPRECATED_RDF_COMPRESSION']
|
|
4
|
-
rescue LoadError => err
|
|
5
|
-
warn "#{__FILE__}: 'nuggets/rdf/compression' is no longer available; install `turtle_reader' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_RDF_COMPRESSION']
|
|
6
|
-
end
|
data/lib/nuggets/rdf/prefix.rb
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
begin
|
|
2
|
-
require 'turtle_reader/rdf/prefix'
|
|
3
|
-
warn "#{__FILE__}: 'nuggets/rdf/prefix' is deprecated, use 'turtle_reader/rdf/prefix' instead." unless ENV['NUGGETS_DEPRECATED_RDF_PREFIX']
|
|
4
|
-
rescue LoadError => err
|
|
5
|
-
warn "#{__FILE__}: 'nuggets/rdf/prefix' is no longer available; install `turtle_reader' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_RDF_PREFIX']
|
|
6
|
-
end
|
data/lib/nuggets/rdf/turtle.rb
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
begin
|
|
2
|
-
require 'turtle_reader'
|
|
3
|
-
module Nuggets; module RDF; Turtle = ::TurtleReader; end; end
|
|
4
|
-
|
|
5
|
-
warn "#{__FILE__}: Nuggets::RDF::Turtle is deprecated, use TurtleReader instead." unless ENV['NUGGETS_DEPRECATED_RDF_TURTLE']
|
|
6
|
-
rescue LoadError => err
|
|
7
|
-
warn "#{__FILE__}: Nuggets::RDF::Turtle is no longer available; install `turtle_reader' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_RDF_TURTLE']
|
|
8
|
-
end
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
begin
|
|
2
|
-
require 'turtle_reader/rdf/turtle/reader'
|
|
3
|
-
warn "#{__FILE__}: 'nuggets/rdf/turtle/reader' is deprecated, use 'turtle_reader/rdf/turtle/reader' instead." unless ENV['NUGGETS_DEPRECATED_RDF_TURTLE_READER']
|
|
4
|
-
rescue LoadError => err
|
|
5
|
-
warn "#{__FILE__}: 'nuggets/rdf/turtle/reader' is no longer available; install `turtle_reader' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_RDF_TURTLE_READER']
|
|
6
|
-
end
|
data/lib/nuggets/rdf/uri.rb
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
begin
|
|
2
|
-
require 'turtle_reader/rdf/uri'
|
|
3
|
-
warn "#{__FILE__}: 'nuggets/rdf/uri' is deprecated, use 'turtle_reader/rdf/uri' instead." unless ENV['NUGGETS_DEPRECATED_RDF_URI']
|
|
4
|
-
rescue LoadError => err
|
|
5
|
-
warn "#{__FILE__}: 'nuggets/rdf/uri' is no longer available; install `turtle_reader' instead. (#{err})" unless ENV['NUGGETS_DEPRECATED_RDF_URI']
|
|
6
|
-
end
|
data/lib/nuggets/ruby.rb
DELETED
|
@@ -1,236 +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
|
-
require 'rbconfig'
|
|
29
|
-
|
|
30
|
-
module Nuggets
|
|
31
|
-
|
|
32
|
-
# Originally based on Phusion Passenger's
|
|
33
|
-
# {PlatformInfo}[https://github.com/FooBarWidget/passenger/blob/release-3.0.2/lib/phusion_passenger/platform_info/ruby.rb]
|
|
34
|
-
# module.
|
|
35
|
-
#
|
|
36
|
-
#--
|
|
37
|
-
# Phusion Passenger - http://www.modrails.com/
|
|
38
|
-
# Copyright (c) 2010 Phusion
|
|
39
|
-
#
|
|
40
|
-
# "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
|
|
41
|
-
#
|
|
42
|
-
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
43
|
-
# copy of this software and associated documentation files (the "Software"),
|
|
44
|
-
# to deal in the Software without restriction, including without limitation
|
|
45
|
-
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
46
|
-
# and/or sell copies of the Software, and to permit persons to whom the
|
|
47
|
-
# Software is furnished to do so, subject to the following conditions:
|
|
48
|
-
#
|
|
49
|
-
# The above copyright notice and this permission notice shall be included in
|
|
50
|
-
# all copies or substantial portions of the Software.
|
|
51
|
-
#++
|
|
52
|
-
|
|
53
|
-
module Ruby
|
|
54
|
-
|
|
55
|
-
extend self
|
|
56
|
-
|
|
57
|
-
CONFIG = ::RbConfig::CONFIG
|
|
58
|
-
|
|
59
|
-
# Store original $GEM_HOME value so that even if the app customizes
|
|
60
|
-
# $GEM_HOME we can still work with the original value.
|
|
61
|
-
if gem_home = ::ENV['GEM_HOME']
|
|
62
|
-
gem_home = gem_home.strip.freeze
|
|
63
|
-
gem_home = nil if gem_home.empty?
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
GEM_HOME = gem_home
|
|
67
|
-
|
|
68
|
-
RUBY_ENGINE = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : 'ruby'
|
|
69
|
-
|
|
70
|
-
OSX_RUBY_RE = %r{\A/System/Library/Frameworks/Ruby.framework/Versions/.*?/usr/bin/ruby\Z}
|
|
71
|
-
|
|
72
|
-
# Returns correct command for invoking the current Ruby interpreter.
|
|
73
|
-
def ruby_command
|
|
74
|
-
defined?(@ruby_command) ? @ruby_command : @ruby_command = ruby_executable
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
attr_writer :ruby_command
|
|
78
|
-
|
|
79
|
-
# Returns the full path to the current Ruby interpreter's executable file.
|
|
80
|
-
# This might not be the actual correct command to use for invoking the Ruby
|
|
81
|
-
# interpreter; use ruby_command instead.
|
|
82
|
-
def ruby_executable
|
|
83
|
-
@ruby_executable ||= begin
|
|
84
|
-
dir, name, ext = CONFIG.values_at(*%w[bindir RUBY_INSTALL_NAME EXEEXT])
|
|
85
|
-
::File.join(dir, name + ext).sub(/.*\s.*/m, '"\&"')
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
attr_writer :ruby_executable
|
|
90
|
-
|
|
91
|
-
# Locates a Ruby tool command +name+, e.g. 'gem', 'rake', 'bundle', etc. Instead
|
|
92
|
-
# of naively looking in $PATH, this function uses a variety of search heuristics
|
|
93
|
-
# to find the command that's really associated with the current Ruby interpreter.
|
|
94
|
-
# It should never locate a command that's actually associated with a different
|
|
95
|
-
# Ruby interpreter.
|
|
96
|
-
#
|
|
97
|
-
# NOTE: The return value may not be the actual correct invocation for the tool.
|
|
98
|
-
# Use command_for_ruby_tool for that.
|
|
99
|
-
#
|
|
100
|
-
# Returns +nil+ when nothing's found.
|
|
101
|
-
def locate_ruby_tool(name, extensions = ['', CONFIG['EXEEXT']].compact.uniq)
|
|
102
|
-
# Deduce Ruby's --program-prefix and --program-suffix from its install name
|
|
103
|
-
# and transform the given input name accordingly.
|
|
104
|
-
#
|
|
105
|
-
# "rake" => "jrake", "rake1.8", etc.
|
|
106
|
-
[name, CONFIG['RUBY_INSTALL_NAME'].sub('ruby', name)].uniq.each { |basename|
|
|
107
|
-
extensions.each { |ext|
|
|
108
|
-
result = locate_ruby_tool_by_basename(basename + ext) and return result
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
nil
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# Returns the correct command string for invoking the +name+ executable
|
|
116
|
-
# that belongs to the current Ruby interpreter. Returns +nil+ if the
|
|
117
|
-
# command is not found.
|
|
118
|
-
#
|
|
119
|
-
# If the command executable is a Ruby program, then we need to run it
|
|
120
|
-
# in the correct Ruby interpreter just in case the command doesn't
|
|
121
|
-
# have the correct shebang line; we don't want a totally different
|
|
122
|
-
# Ruby than the current one to be invoked.
|
|
123
|
-
def command_for_ruby_tool(name)
|
|
124
|
-
filename = respond_to?(name) ? send(name) : locate_ruby_tool(name)
|
|
125
|
-
shebang_command(filename) =~ /ruby/ ? "#{ruby_command} #{filename}" : filename
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def self.define_ruby_tool(name)
|
|
129
|
-
class_eval <<-EOT, __FILE__, __LINE__ + 1
|
|
130
|
-
def #{name}
|
|
131
|
-
@#{name} ||= locate_ruby_tool('#{name}')
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
attr_writer :#{name}
|
|
135
|
-
|
|
136
|
-
def #{name}_command
|
|
137
|
-
@#{name}_command ||= command_for_ruby_tool('#{name}')
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
attr_writer :#{name}_command
|
|
141
|
-
EOT
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
%w[gem rake rspec].each { |name| define_ruby_tool(name) }
|
|
145
|
-
|
|
146
|
-
def ruby_options_to_argv(args, ruby_command = ruby_command)
|
|
147
|
-
argv = [ruby_command]
|
|
148
|
-
|
|
149
|
-
ruby_options_from_hash(args.pop, argv) if args.last.is_a?(::Hash)
|
|
150
|
-
|
|
151
|
-
argv.concat(args.map! { |arg| arg.to_s.strip })
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def ruby_options_from_hash(hash, argv = [])
|
|
155
|
-
hash.each { |key, val|
|
|
156
|
-
opt = "-#{key.to_s[0, 1]}"
|
|
157
|
-
|
|
158
|
-
if val.is_a?(::Array)
|
|
159
|
-
val.each { |v| argv << opt << v.to_s }
|
|
160
|
-
elsif opt == '-e'
|
|
161
|
-
argv << opt << val.to_s
|
|
162
|
-
elsif val != false
|
|
163
|
-
argv << "#{opt}#{val unless val == true}"
|
|
164
|
-
end
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
argv
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
private
|
|
171
|
-
|
|
172
|
-
def locate_ruby_tool_by_basename(name)
|
|
173
|
-
# On OS X we must look for Ruby binaries in /usr/bin.
|
|
174
|
-
# RubyGems puts executables (e.g. 'rake') in there, not in
|
|
175
|
-
# /System/Libraries/(...)/bin.
|
|
176
|
-
dir = ::RUBY_PLATFORM =~ /darwin/ && ruby_command =~ OSX_RUBY_RE ?
|
|
177
|
-
'/usr/bin' : ::File.dirname(ruby_command)
|
|
178
|
-
|
|
179
|
-
filename = executable_filename(dir, name) and return filename
|
|
180
|
-
|
|
181
|
-
# RubyGems might put binaries in a directory other
|
|
182
|
-
# than Ruby's bindir. Debian packaged RubyGems and
|
|
183
|
-
# DebGem packaged RubyGems are the prime examples.
|
|
184
|
-
filename = executable_filename(::Gem.bindir, name) and return filename
|
|
185
|
-
|
|
186
|
-
# Looks like it's not in the RubyGems bindir. Search in $PATH, but
|
|
187
|
-
# be very careful about this because whatever we find might belong
|
|
188
|
-
# to a different Ruby interpreter than the current one.
|
|
189
|
-
::ENV['PATH'].split(::File::PATH_SEPARATOR).each { |path|
|
|
190
|
-
if filename = executable_filename(path, name)
|
|
191
|
-
return filename if shebang_command(filename) == ruby_command
|
|
192
|
-
end
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
nil
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
def executable_filename(dir, name)
|
|
199
|
-
filename = ::File.join(dir, name)
|
|
200
|
-
filename if ::File.file?(filename) && ::File.executable?(filename)
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
def shebang_command(filename)
|
|
204
|
-
::File.foreach(filename) { |line|
|
|
205
|
-
return $1 if line =~ /\A#!\s*(\S*)/
|
|
206
|
-
|
|
207
|
-
# Allow one extra line for magic comment.
|
|
208
|
-
break if $. > 1
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
nil
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
def File.ruby; ::Nuggets::Ruby.ruby_command; end
|
|
219
|
-
|
|
220
|
-
begin
|
|
221
|
-
require 'open4'
|
|
222
|
-
|
|
223
|
-
def Process.ruby(*args, &block)
|
|
224
|
-
argv = ::Nuggets::Ruby.ruby_options_to_argv(args)
|
|
225
|
-
::Open4.popen4(*argv, &block)
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
require 'nuggets/io/interact'
|
|
229
|
-
|
|
230
|
-
def Process.interact_ruby(input, *args)
|
|
231
|
-
ruby(*args) { |_, i, o, e|
|
|
232
|
-
::IO.interact({ input => i }, { o => $stdout, e => $stderr })
|
|
233
|
-
}
|
|
234
|
-
end
|
|
235
|
-
rescue ::LoadError
|
|
236
|
-
end
|
data/lib/nuggets/statistics.rb
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# load statistics related nuggets
|
|
2
|
-
|
|
3
|
-
require 'nuggets/array/boost'
|
|
4
|
-
require 'nuggets/array/correlation'
|
|
5
|
-
require 'nuggets/array/histogram'
|
|
6
|
-
require 'nuggets/array/mean'
|
|
7
|
-
require 'nuggets/array/median'
|
|
8
|
-
require 'nuggets/array/mode'
|
|
9
|
-
require 'nuggets/array/regression'
|
|
10
|
-
require 'nuggets/array/standard_deviation'
|
|
11
|
-
require 'nuggets/array/variance'
|
|
12
|
-
require 'nuggets/range/quantile'
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# load statistics related nuggets (mixins)
|
|
2
|
-
|
|
3
|
-
require 'nuggets/array/boost_mixin'
|
|
4
|
-
require 'nuggets/array/correlation_mixin'
|
|
5
|
-
require 'nuggets/array/histogram_mixin'
|
|
6
|
-
require 'nuggets/array/mean_mixin'
|
|
7
|
-
require 'nuggets/array/median_mixin'
|
|
8
|
-
require 'nuggets/array/mode_mixin'
|
|
9
|
-
require 'nuggets/array/regression_mixin'
|
|
10
|
-
require 'nuggets/array/standard_deviation_mixin'
|
|
11
|
-
require 'nuggets/array/variance_mixin'
|
|
12
|
-
require 'nuggets/range/quantile_mixin'
|
|
@@ -1,117 +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
|
-
module Nuggets
|
|
29
|
-
class String
|
|
30
|
-
module CamelscoreMixin
|
|
31
|
-
|
|
32
|
-
# List of acronyms to treat specially
|
|
33
|
-
# in #camelcase and #underscore.
|
|
34
|
-
CAMELSCORE_ACRONYMS = {
|
|
35
|
-
'html' => 'HTML',
|
|
36
|
-
'rss' => 'RSS',
|
|
37
|
-
'sql' => 'SQL',
|
|
38
|
-
'ssl' => 'SSL',
|
|
39
|
-
'xml' => 'XML'
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
# call-seq:
|
|
43
|
-
# str.camelcase => new_string
|
|
44
|
-
#
|
|
45
|
-
# Returns the CamelCase form of _str_.
|
|
46
|
-
def camelcase
|
|
47
|
-
dup.camelcase!
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
alias_method :camelize, :camelcase
|
|
51
|
-
|
|
52
|
-
# call-seq:
|
|
53
|
-
# str.camelcase! => str
|
|
54
|
-
#
|
|
55
|
-
# Replaces _str_ with its CamelCase form and returns _str_.
|
|
56
|
-
def camelcase!
|
|
57
|
-
sub!(/^[a-z]+/) {
|
|
58
|
-
CAMELSCORE_ACRONYMS[$&] || $&.capitalize
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
gsub!(/(?:_|([\/\d]))([a-z]+)/i) {
|
|
62
|
-
"#{$1}#{CAMELSCORE_ACRONYMS[$2] || $2.capitalize}"
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
gsub!('/', '::')
|
|
66
|
-
|
|
67
|
-
self
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
alias_method :camelize!, :camelcase!
|
|
71
|
-
|
|
72
|
-
# call-seq:
|
|
73
|
-
# str.underscore => new_string
|
|
74
|
-
#
|
|
75
|
-
# Returns the under_score form of _str_.
|
|
76
|
-
def underscore
|
|
77
|
-
dup.underscore!
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# call-seq:
|
|
81
|
-
# str.underscore! => str
|
|
82
|
-
#
|
|
83
|
-
# Replaces _str_ with its under_score form and returns _str_.
|
|
84
|
-
def underscore!
|
|
85
|
-
gsub!(/::/, '/')
|
|
86
|
-
|
|
87
|
-
a = CAMELSCORE_ACRONYMS.values
|
|
88
|
-
r = a.empty? ? /(?=a)b/ : ::Regexp.union(*a.sort_by { |v| v.length })
|
|
89
|
-
|
|
90
|
-
gsub!(/(?:([A-Za-z])|(\d)|^)(#{r})(?=\b|[^a-z])/) {
|
|
91
|
-
"#{$1 || $2}#{'_' if $1}#{$3.downcase}"
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
gsub!(/([A-Z])(?=[A-Z])/, '\1_')
|
|
95
|
-
gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
|
96
|
-
|
|
97
|
-
downcase!
|
|
98
|
-
|
|
99
|
-
self
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# call-seq:
|
|
103
|
-
# str.constantize(base = Object) => anObject
|
|
104
|
-
#
|
|
105
|
-
# Returns the constant pointed to by _str_, relative to +base+.
|
|
106
|
-
def constantize(base = ::Object)
|
|
107
|
-
names = split('::')
|
|
108
|
-
return if names.empty?
|
|
109
|
-
|
|
110
|
-
const = names.first.empty? ? (names.shift; ::Object) : base
|
|
111
|
-
names.each { |name| const = const.const_get(name) }
|
|
112
|
-
const
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|