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
- data/COPYING +663 -0
- data/ChangeLog +7 -0
- data/README +74 -0
- data/Rakefile +50 -0
- data/lib/nuggets.rb +73 -0
- data/lib/nuggets/all.rb +35 -0
- data/lib/nuggets/all_mixins.rb +33 -0
- data/lib/nuggets/ansicolor2css.rb +124 -0
- data/lib/nuggets/argv/option.rb +3 -0
- data/lib/nuggets/argv/option_mixin.rb +84 -0
- data/lib/nuggets/array/boost.rb +5 -0
- data/lib/nuggets/array/boost_mixin.rb +77 -0
- data/lib/nuggets/array/combination.rb +62 -0
- data/lib/nuggets/array/correlation.rb +5 -0
- data/lib/nuggets/array/correlation_mixin.rb +63 -0
- data/lib/nuggets/array/flatten_once.rb +56 -0
- data/lib/nuggets/array/flush.rb +5 -0
- data/lib/nuggets/array/flush_mixin.rb +46 -0
- data/lib/nuggets/array/format.rb +65 -0
- data/lib/nuggets/array/hashify.rb +5 -0
- data/lib/nuggets/array/hashify_mixin.rb +47 -0
- data/lib/nuggets/array/histogram.rb +5 -0
- data/lib/nuggets/array/histogram_mixin.rb +169 -0
- data/lib/nuggets/array/in_order.rb +50 -0
- data/lib/nuggets/array/limit.rb +5 -0
- data/lib/nuggets/array/limit_mixin.rb +56 -0
- data/lib/nuggets/array/mean.rb +5 -0
- data/lib/nuggets/array/mean_mixin.rb +202 -0
- data/lib/nuggets/array/median.rb +5 -0
- data/lib/nuggets/array/median_mixin.rb +73 -0
- data/lib/nuggets/array/mode.rb +5 -0
- data/lib/nuggets/array/mode_mixin.rb +69 -0
- data/lib/nuggets/array/monotone.rb +83 -0
- data/lib/nuggets/array/only.rb +41 -0
- data/lib/nuggets/array/rand.rb +44 -0
- data/lib/nuggets/array/regression.rb +5 -0
- data/lib/nuggets/array/regression_mixin.rb +149 -0
- data/lib/nuggets/array/runiq.rb +5 -0
- data/lib/nuggets/array/runiq_mixin.rb +52 -0
- data/lib/nuggets/array/shuffle.rb +132 -0
- data/lib/nuggets/array/standard_deviation.rb +5 -0
- data/lib/nuggets/array/standard_deviation_mixin.rb +50 -0
- data/lib/nuggets/array/to_hash.rb +64 -0
- data/lib/nuggets/array/variance.rb +5 -0
- data/lib/nuggets/array/variance_mixin.rb +81 -0
- data/lib/nuggets/content_type.rb +97 -0
- data/lib/nuggets/dotted_decimal.rb +59 -0
- data/lib/nuggets/enumerable/agrep.rb +79 -0
- data/lib/nuggets/enumerable/all_any_extended.rb +66 -0
- data/lib/nuggets/enumerable/minmax.rb +102 -0
- data/lib/nuggets/env/set.rb +3 -0
- data/lib/nuggets/env/set_mixin.rb +67 -0
- data/lib/nuggets/env/user_encoding.rb +3 -0
- data/lib/nuggets/env/user_encoding_mixin.rb +54 -0
- data/lib/nuggets/env/user_home.rb +3 -0
- data/lib/nuggets/env/user_home_mixin.rb +56 -0
- data/lib/nuggets/file/ext.rb +5 -0
- data/lib/nuggets/file/ext_mixin.rb +87 -0
- data/lib/nuggets/file/replace.rb +5 -0
- data/lib/nuggets/file/replace_mixin.rb +55 -0
- data/lib/nuggets/file/sub.rb +5 -0
- data/lib/nuggets/file/sub_mixin.rb +95 -0
- data/lib/nuggets/file/which.rb +5 -0
- data/lib/nuggets/file/which_mixin.rb +72 -0
- data/lib/nuggets/hash/at.rb +68 -0
- data/lib/nuggets/hash/deep_fetch.rb +5 -0
- data/lib/nuggets/hash/deep_fetch_mixin.rb +74 -0
- data/lib/nuggets/hash/deep_merge.rb +5 -0
- data/lib/nuggets/hash/deep_merge_mixin.rb +53 -0
- data/lib/nuggets/hash/idmap.rb +5 -0
- data/lib/nuggets/hash/idmap_mixin.rb +41 -0
- data/lib/nuggets/hash/in_order.rb +43 -0
- data/lib/nuggets/hash/insert.rb +53 -0
- data/lib/nuggets/hash/nest.rb +5 -0
- data/lib/nuggets/hash/nest_mixin.rb +78 -0
- data/lib/nuggets/hash/only.rb +52 -0
- data/lib/nuggets/hash/seen.rb +5 -0
- data/lib/nuggets/hash/seen_mixin.rb +58 -0
- data/lib/nuggets/hash/unroll.rb +5 -0
- data/lib/nuggets/hash/unroll_mixin.rb +88 -0
- data/lib/nuggets/hash/zip.rb +5 -0
- data/lib/nuggets/hash/zip_mixin.rb +159 -0
- data/lib/nuggets/i18n.rb +155 -0
- data/lib/nuggets/integer/factorial.rb +56 -0
- data/lib/nuggets/integer/length.rb +5 -0
- data/lib/nuggets/integer/length_mixin.rb +49 -0
- data/lib/nuggets/integer/map.rb +5 -0
- data/lib/nuggets/integer/map_mixin.rb +42 -0
- data/lib/nuggets/integer/to_binary_s.rb +38 -0
- data/lib/nuggets/io/agrep.rb +43 -0
- data/lib/nuggets/io/interact.rb +5 -0
- data/lib/nuggets/io/interact_mixin.rb +159 -0
- data/lib/nuggets/io/modes.rb +121 -0
- data/lib/nuggets/io/null.rb +5 -0
- data/lib/nuggets/io/null_mixin.rb +40 -0
- data/lib/nuggets/io/redirect.rb +5 -0
- data/lib/nuggets/io/redirect_mixin.rb +50 -0
- data/lib/nuggets/lazy_attr.rb +44 -0
- data/lib/nuggets/log_parser.rb +70 -0
- data/lib/nuggets/log_parser/apache.rb +101 -0
- data/lib/nuggets/log_parser/rails.rb +219 -0
- data/lib/nuggets/net/success.rb +59 -0
- data/lib/nuggets/numeric/between.rb +2 -0
- data/lib/nuggets/numeric/duration.rb +100 -0
- data/lib/nuggets/numeric/limit.rb +62 -0
- data/lib/nuggets/numeric/signum.rb +52 -0
- data/lib/nuggets/numeric/to_multiple.rb +61 -0
- data/lib/nuggets/object/blank.rb +20 -0
- data/lib/nuggets/object/blank_mixin.rb +99 -0
- data/lib/nuggets/object/boolean.rb +5 -0
- data/lib/nuggets/object/boolean_mixin.rb +61 -0
- data/lib/nuggets/object/eigenclass.rb +2 -0
- data/lib/nuggets/object/ghost_class.rb +2 -0
- data/lib/nuggets/object/metaclass.rb +2 -0
- data/lib/nuggets/object/msend.rb +5 -0
- data/lib/nuggets/object/msend_mixin.rb +43 -0
- data/lib/nuggets/object/silence.rb +5 -0
- data/lib/nuggets/object/silence_mixin.rb +44 -0
- data/lib/nuggets/object/singleton_class.rb +5 -0
- data/lib/nuggets/object/singleton_class_mixin.rb +95 -0
- data/lib/nuggets/object/uniclass.rb +2 -0
- data/lib/nuggets/object/virtual_class.rb +2 -0
- data/lib/nuggets/pluggable.rb +91 -0
- data/lib/nuggets/proc/bind.rb +5 -0
- data/lib/nuggets/proc/bind_mixin.rb +51 -0
- data/lib/nuggets/range/quantile.rb +5 -0
- data/lib/nuggets/range/quantile_mixin.rb +42 -0
- data/lib/nuggets/ruby.rb +235 -0
- data/lib/nuggets/statistics.rb +12 -0
- data/lib/nuggets/statistics_mixins.rb +12 -0
- data/lib/nuggets/string/camelscore.rb +5 -0
- data/lib/nuggets/string/camelscore_mixin.rb +116 -0
- data/lib/nuggets/string/capitalize_first.rb +46 -0
- data/lib/nuggets/string/case.rb +81 -0
- data/lib/nuggets/string/evaluate.rb +5 -0
- data/lib/nuggets/string/evaluate_mixin.rb +47 -0
- data/lib/nuggets/string/msub.rb +84 -0
- data/lib/nuggets/string/nsub.rb +65 -0
- data/lib/nuggets/string/sub_with_md.rb +111 -0
- data/lib/nuggets/string/wc.rb +5 -0
- data/lib/nuggets/string/wc_mixin.rb +95 -0
- data/lib/nuggets/string/word_wrap.rb +76 -0
- data/lib/nuggets/string/xor.rb +5 -0
- data/lib/nuggets/string/xor_mixin.rb +59 -0
- data/lib/nuggets/tempfile/open.rb +57 -0
- data/lib/nuggets/uri/content_type.rb +5 -0
- data/lib/nuggets/uri/content_type_mixin.rb +47 -0
- data/lib/nuggets/uri/exist.rb +5 -0
- data/lib/nuggets/uri/exist_mixin.rb +56 -0
- data/lib/nuggets/uri/redirect.rb +5 -0
- data/lib/nuggets/uri/redirect_mixin.rb +101 -0
- data/lib/nuggets/version.rb +27 -0
- data/spec/nuggets/array/boost_spec.rb +50 -0
- data/spec/nuggets/array/combination_spec.rb +25 -0
- data/spec/nuggets/array/correlation_spec.rb +81 -0
- data/spec/nuggets/array/flatten_once_spec.rb +16 -0
- data/spec/nuggets/array/flush_spec.rb +43 -0
- data/spec/nuggets/array/format_spec.rb +52 -0
- data/spec/nuggets/array/hashify_spec.rb +41 -0
- data/spec/nuggets/array/histogram_spec.rb +87 -0
- data/spec/nuggets/array/in_order_spec.rb +13 -0
- data/spec/nuggets/array/limit_spec.rb +62 -0
- data/spec/nuggets/array/mean_spec.rb +203 -0
- data/spec/nuggets/array/median_spec.rb +77 -0
- data/spec/nuggets/array/mode_spec.rb +57 -0
- data/spec/nuggets/array/monotone_spec.rb +30 -0
- data/spec/nuggets/array/only_spec.rb +26 -0
- data/spec/nuggets/array/regression_spec.rb +54 -0
- data/spec/nuggets/array/runiq_spec.rb +25 -0
- data/spec/nuggets/array/standard_deviation_spec.rb +33 -0
- data/spec/nuggets/array/to_hash_spec.rb +28 -0
- data/spec/nuggets/array/variance_spec.rb +106 -0
- data/spec/nuggets/dotted_decimal_spec.rb +27 -0
- data/spec/nuggets/enumerable/all_any_extended_spec.rb +31 -0
- data/spec/nuggets/enumerable/minmax_spec.rb +21 -0
- data/spec/nuggets/env/set_spec.rb +29 -0
- data/spec/nuggets/env/user_encoding_spec.rb +38 -0
- data/spec/nuggets/env/user_home_spec.rb +42 -0
- data/spec/nuggets/file/ext_spec.rb +38 -0
- data/spec/nuggets/file/replace_spec.rb +95 -0
- data/spec/nuggets/file/sub_spec.rb +149 -0
- data/spec/nuggets/file/which_spec.rb +22 -0
- data/spec/nuggets/hash/at_spec.rb +19 -0
- data/spec/nuggets/hash/deep_fetch_spec.rb +159 -0
- data/spec/nuggets/hash/deep_merge_spec.rb +78 -0
- data/spec/nuggets/hash/in_order_spec.rb +12 -0
- data/spec/nuggets/hash/insert_spec.rb +13 -0
- data/spec/nuggets/hash/nest_spec.rb +102 -0
- data/spec/nuggets/hash/only_spec.rb +29 -0
- data/spec/nuggets/hash/seen_spec.rb +36 -0
- data/spec/nuggets/hash/unroll_spec.rb +68 -0
- data/spec/nuggets/i18n_spec.rb +13 -0
- data/spec/nuggets/integer/factorial_spec.rb +10 -0
- data/spec/nuggets/integer/length_spec.rb +18 -0
- data/spec/nuggets/integer/map_spec.rb +19 -0
- data/spec/nuggets/integer/to_binary_s_spec.rb +19 -0
- data/spec/nuggets/numeric/duration_spec.rb +25 -0
- data/spec/nuggets/numeric/limit_spec.rb +16 -0
- data/spec/nuggets/numeric/signum_spec.rb +16 -0
- data/spec/nuggets/numeric/to_multiple_spec.rb +16 -0
- data/spec/nuggets/object/blank_spec.rb +34 -0
- data/spec/nuggets/object/boolean_spec.rb +23 -0
- data/spec/nuggets/object/msend_spec.rb +25 -0
- data/spec/nuggets/object/silence_spec.rb +36 -0
- data/spec/nuggets/object/singleton_class_spec.rb +51 -0
- data/spec/nuggets/proc/bind_spec.rb +28 -0
- data/spec/nuggets/range/quantile_spec.rb +33 -0
- data/spec/nuggets/string/camelscore_spec.rb +114 -0
- data/spec/nuggets/string/capitalize_first_spec.rb +13 -0
- data/spec/nuggets/string/case_spec.rb +31 -0
- data/spec/nuggets/string/evaluate_spec.rb +24 -0
- data/spec/nuggets/string/msub_spec.rb +20 -0
- data/spec/nuggets/string/nsub_spec.rb +13 -0
- data/spec/nuggets/string/sub_with_md_spec.rb +25 -0
- data/spec/nuggets/string/wc_spec.rb +73 -0
- data/spec/nuggets/string/word_wrap_spec.rb +81 -0
- data/spec/nuggets/string/xor_spec.rb +57 -0
- data/spec/nuggets/uri/content_type_spec.rb +42 -0
- data/spec/nuggets/uri/exist_spec.rb +49 -0
- data/spec/spec_helper.rb +36 -0
- metadata +309 -17
data/ChangeLog
ADDED
data/README
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
= nuggets - Extending Ruby
|
|
2
|
+
|
|
3
|
+
== VERSION
|
|
4
|
+
|
|
5
|
+
This documentation refers to nuggets version 1.0.0.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
== DESCRIPTION
|
|
9
|
+
|
|
10
|
+
Nuggets provides a collection of extensions to Ruby classes.
|
|
11
|
+
It's similar to projects like Facets[http://rubyworks.github.com/facets]
|
|
12
|
+
and Extensions[http://extensions.rubyforge.org] (or even
|
|
13
|
+
Labrador[http://labrador.rubyforge.org]).
|
|
14
|
+
|
|
15
|
+
This is simply where I put stuff that I need on a more or
|
|
16
|
+
less regular basis or that struck me as interesting while
|
|
17
|
+
surfing the web, reading books, or following discussions on
|
|
18
|
+
ruby-talk[http://lists.ruby-lang.org/cgi-bin/mailman/listinfo/ruby-talk].
|
|
19
|
+
|
|
20
|
+
There are several ways to get the extensions you're interested in:
|
|
21
|
+
|
|
22
|
+
# Either require() what you need:
|
|
23
|
+
require 'nuggets/object/singleton_class'
|
|
24
|
+
require 'nuggets/string/sub_with_md'
|
|
25
|
+
require 'nuggets/string/nsub'
|
|
26
|
+
|
|
27
|
+
# Or use the helper method (see the documentation of Nuggets()
|
|
28
|
+
# for more examples):
|
|
29
|
+
require 'nuggets'
|
|
30
|
+
Nuggets(object: 'singleton_class', string: %w[sub_with_md nsub])
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
== NEW NAME
|
|
34
|
+
|
|
35
|
+
This project used to be named <tt>ruby-nuggets</tt> but was renamed
|
|
36
|
+
to +nuggets+ with version 1.0.0. Please update your dependencies.
|
|
37
|
+
(Require paths are unchanged.)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
== DISCLAIMER
|
|
41
|
+
|
|
42
|
+
Please be aware that some of the things herein might not work as
|
|
43
|
+
expected or cause other libraries to misbehave. Use at your own risk!
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
== LINKS
|
|
47
|
+
|
|
48
|
+
Documentation:: https://blackwinter.github.io/nuggets/
|
|
49
|
+
Source code:: https://github.com/blackwinter/nuggets
|
|
50
|
+
RubyGem:: https://rubygems.org/gems/nuggets
|
|
51
|
+
Travis CI:: https://travis-ci.org/blackwinter/nuggets
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
== AUTHORS
|
|
55
|
+
|
|
56
|
+
* Jens Wille <mailto:jens.wille@gmail.com>
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
== LICENSE AND COPYRIGHT
|
|
60
|
+
|
|
61
|
+
Copyright (C) 2007-2014 Jens Wille
|
|
62
|
+
|
|
63
|
+
nuggets is free software: you can redistribute it and/or modify it
|
|
64
|
+
under the terms of the GNU Affero General Public License as published by
|
|
65
|
+
the Free Software Foundation, either version 3 of the License, or (at your
|
|
66
|
+
option) any later version.
|
|
67
|
+
|
|
68
|
+
nuggets is distributed in the hope that it will be useful, but
|
|
69
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
70
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
|
71
|
+
License for more details.
|
|
72
|
+
|
|
73
|
+
You should have received a copy of the GNU Affero General Public License
|
|
74
|
+
along with nuggets. If not, see <http://www.gnu.org/licenses/>.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require File.expand_path(%q{../lib/nuggets/version}, __FILE__)
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require 'hen'
|
|
5
|
+
|
|
6
|
+
Hen.lay! {{
|
|
7
|
+
gem: {
|
|
8
|
+
name: %q{nuggets},
|
|
9
|
+
version: Nuggets::VERSION,
|
|
10
|
+
summary: %q{Extending Ruby.},
|
|
11
|
+
description: %q{Various extensions to Ruby classes.},
|
|
12
|
+
author: %q{Jens Wille},
|
|
13
|
+
email: %q{jens.wille@gmail.com},
|
|
14
|
+
license: %q{AGPL-3.0},
|
|
15
|
+
homepage: :blackwinter,
|
|
16
|
+
dependencies: %w[],
|
|
17
|
+
|
|
18
|
+
development_dependencies: [
|
|
19
|
+
#'amatch', # enumerable/agrep
|
|
20
|
+
'mime-types', # content_type
|
|
21
|
+
'open4', # ruby
|
|
22
|
+
#'ruby-filemagic' # content_type
|
|
23
|
+
],
|
|
24
|
+
|
|
25
|
+
required_ruby_version: '>= 1.9.3'
|
|
26
|
+
}
|
|
27
|
+
}}
|
|
28
|
+
rescue LoadError => err
|
|
29
|
+
warn "Please install the `hen' gem. (#{err})"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
desc 'Run all specs in isolation'
|
|
33
|
+
task 'spec:isolated' do
|
|
34
|
+
ARGV.delete('spec:isolated')
|
|
35
|
+
ARGV.unshift('spec')
|
|
36
|
+
|
|
37
|
+
Dir['spec/*/**/*_spec.rb'].each { |spec|
|
|
38
|
+
ENV['SPEC'] = spec
|
|
39
|
+
system($0, *ARGV)
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
if RUBY_PLATFORM == 'java'
|
|
44
|
+
task spec: :enable_objspace
|
|
45
|
+
|
|
46
|
+
task :enable_objspace do
|
|
47
|
+
k, v = 'JRUBY_OPTS', '-X+O'
|
|
48
|
+
ENV[k] ? ENV[k] += " #{v}" : ENV[k] = v
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/nuggets.rb
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#--
|
|
2
|
+
###############################################################################
|
|
3
|
+
# #
|
|
4
|
+
# nuggets -- Extending Ruby #
|
|
5
|
+
# #
|
|
6
|
+
# Copyright (C) 2007-2014 Jens Wille #
|
|
7
|
+
# #
|
|
8
|
+
# Authors: #
|
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
|
10
|
+
# #
|
|
11
|
+
# nuggets is free software; you can redistribute it and/or modify it under #
|
|
12
|
+
# the terms of the GNU Affero General Public License as published by the Free #
|
|
13
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
|
14
|
+
# any later version. #
|
|
15
|
+
# #
|
|
16
|
+
# nuggets is distributed in the hope that it will be useful, but WITHOUT ANY #
|
|
17
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
|
18
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
|
|
19
|
+
# more details. #
|
|
20
|
+
# #
|
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
|
22
|
+
# along with nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
23
|
+
# #
|
|
24
|
+
###############################################################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
# Load selected +nuggets+.
|
|
28
|
+
#
|
|
29
|
+
# Examples:
|
|
30
|
+
# # All String nuggets
|
|
31
|
+
# Nuggets(:string)
|
|
32
|
+
# Nuggets(String)
|
|
33
|
+
#
|
|
34
|
+
# # Only 'msub' and 'word_wrap' String nuggets
|
|
35
|
+
# Nuggets(string: %w[msub word_wrap])
|
|
36
|
+
#
|
|
37
|
+
# # Selected String nuggets and all Numeric nuggets
|
|
38
|
+
# Nuggets(:numeric, string: %w[msub word_wrap])
|
|
39
|
+
#
|
|
40
|
+
# # etc.
|
|
41
|
+
def Nuggets(*nuggets)
|
|
42
|
+
loaded_nuggets, load_nuggets = [], lambda { |base, *nuggets|
|
|
43
|
+
nuggets_by_hierarchy = nuggets.last.is_a?(Hash) ? nuggets.pop : {}
|
|
44
|
+
|
|
45
|
+
nuggets.each { |nugget|
|
|
46
|
+
begin
|
|
47
|
+
require path = File.join(base.to_s, nugget.to_s.downcase)
|
|
48
|
+
loaded_nuggets << path
|
|
49
|
+
rescue LoadError
|
|
50
|
+
# if it's a directory, load anything in it
|
|
51
|
+
$LOAD_PATH.each { |dir|
|
|
52
|
+
if File.directory?(dir_path = File.join(dir, path))
|
|
53
|
+
load_nuggets[path, *Dir[File.join(dir_path, '*')].map { |file|
|
|
54
|
+
File.basename(file, '.rb') unless file.end_with?('_mixin.rb')
|
|
55
|
+
}.compact]
|
|
56
|
+
break
|
|
57
|
+
end
|
|
58
|
+
} and raise # otherwise, re-raise
|
|
59
|
+
end
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
nuggets_by_hierarchy.each { |hierarchy, nuggets|
|
|
63
|
+
nuggets = [nuggets] if nuggets.is_a?(Hash)
|
|
64
|
+
load_nuggets[File.join(base.to_s, hierarchy.to_s.downcase), *nuggets]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
load_nuggets['nuggets', *nuggets]
|
|
69
|
+
|
|
70
|
+
loaded_nuggets
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
require_relative 'nuggets/version'
|
data/lib/nuggets/all.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#--
|
|
2
|
+
###############################################################################
|
|
3
|
+
# #
|
|
4
|
+
# nuggets -- Extending Ruby #
|
|
5
|
+
# #
|
|
6
|
+
# Copyright (C) 2007-2011 Jens Wille #
|
|
7
|
+
# #
|
|
8
|
+
# Authors: #
|
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
|
10
|
+
# #
|
|
11
|
+
# nuggets is free software; you can redistribute it and/or modify it under #
|
|
12
|
+
# the terms of the GNU Affero General Public License as published by the Free #
|
|
13
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
|
14
|
+
# any later version. #
|
|
15
|
+
# #
|
|
16
|
+
# nuggets is distributed in the hope that it will be useful, but WITHOUT ANY #
|
|
17
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
|
18
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
|
|
19
|
+
# more details. #
|
|
20
|
+
# #
|
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
|
22
|
+
# along with nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
23
|
+
# #
|
|
24
|
+
###############################################################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
base = ::File.dirname(__FILE__)
|
|
28
|
+
base_re = ::Regexp.escape(base)
|
|
29
|
+
|
|
30
|
+
::Dir[::File.join(base, %w[* ** *.rb])].sort.each { |path|
|
|
31
|
+
next if path.include?('/util/') || path.end_with?('_mixin.rb')
|
|
32
|
+
|
|
33
|
+
ext_re = ::Regexp.escape(::File.extname(path))
|
|
34
|
+
require path.sub(/#{base_re}(.*)#{ext_re}/, 'nuggets\1')
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#--
|
|
2
|
+
###############################################################################
|
|
3
|
+
# #
|
|
4
|
+
# nuggets -- Extending Ruby #
|
|
5
|
+
# #
|
|
6
|
+
# Copyright (C) 2007-2011 Jens Wille #
|
|
7
|
+
# #
|
|
8
|
+
# Authors: #
|
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
|
10
|
+
# #
|
|
11
|
+
# nuggets is free software; you can redistribute it and/or modify it under #
|
|
12
|
+
# the terms of the GNU Affero General Public License as published by the Free #
|
|
13
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
|
14
|
+
# any later version. #
|
|
15
|
+
# #
|
|
16
|
+
# nuggets is distributed in the hope that it will be useful, but WITHOUT ANY #
|
|
17
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
|
18
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
|
|
19
|
+
# more details. #
|
|
20
|
+
# #
|
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
|
22
|
+
# along with nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
23
|
+
# #
|
|
24
|
+
###############################################################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
base = ::File.dirname(__FILE__)
|
|
28
|
+
base_re = ::Regexp.escape(base)
|
|
29
|
+
|
|
30
|
+
::Dir[::File.join(base, %w[* ** *_mixin.rb])].sort.each { |path|
|
|
31
|
+
ext_re = ::Regexp.escape(::File.extname(path))
|
|
32
|
+
require path.sub(/#{base_re}(.*)#{ext_re}/, 'nuggets\1')
|
|
33
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#--
|
|
2
|
+
###############################################################################
|
|
3
|
+
# #
|
|
4
|
+
# nuggets -- Extending Ruby #
|
|
5
|
+
# #
|
|
6
|
+
# Copyright (C) 2007-2011 Jens Wille #
|
|
7
|
+
# #
|
|
8
|
+
# Authors: #
|
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
|
10
|
+
# #
|
|
11
|
+
# nuggets is free software; you can redistribute it and/or modify it under #
|
|
12
|
+
# the terms of the GNU Affero General Public License as published by the Free #
|
|
13
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
|
14
|
+
# any later version. #
|
|
15
|
+
# #
|
|
16
|
+
# nuggets is distributed in the hope that it will be useful, but WITHOUT ANY #
|
|
17
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
|
18
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
|
|
19
|
+
# more details. #
|
|
20
|
+
# #
|
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
|
22
|
+
# along with nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
23
|
+
# #
|
|
24
|
+
###############################################################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
module Nuggets
|
|
28
|
+
module ANSIColor2CSS
|
|
29
|
+
|
|
30
|
+
extend self
|
|
31
|
+
|
|
32
|
+
ATTRIBUTES = {
|
|
33
|
+
'0' => nil, # clear
|
|
34
|
+
'1' => 'font-weight: bold', # bold
|
|
35
|
+
'2' => '', # dark
|
|
36
|
+
'3' => 'font-style: italic', # italic -- not widely implemented
|
|
37
|
+
'4' => 'text-decoration: underline', # underline
|
|
38
|
+
'5' => 'text-decoration: blink', # blink
|
|
39
|
+
'6' => 'text-decoration: blink', # rapid blink -- not widely implemented
|
|
40
|
+
'7' => '', # reverse
|
|
41
|
+
'8' => 'opacity: 0', # concealed
|
|
42
|
+
'9' => 'text-decoration: line-through', # strikethrough -- not widely implemented
|
|
43
|
+
'22' => 'font-weight: normal', # bold off
|
|
44
|
+
'23' => 'font-style: normal', # italic off
|
|
45
|
+
'24' => 'text-decoration: none', # underline off
|
|
46
|
+
'25' => 'text-decoration: none', # blink off
|
|
47
|
+
'27' => '', # reverse off
|
|
48
|
+
'28' => 'opacity: 1', # concealed off
|
|
49
|
+
'29' => 'text-decoration: none', # strikethrough off
|
|
50
|
+
'30' => 'color: black', # black
|
|
51
|
+
'31' => 'color: maroon', # red
|
|
52
|
+
'32' => 'color: green', # green
|
|
53
|
+
'33' => 'color: olive', # yellow
|
|
54
|
+
'34' => 'color: navy', # blue
|
|
55
|
+
'35' => 'color: purple', # magenta
|
|
56
|
+
'36' => 'color: teal', # cyan
|
|
57
|
+
'37' => 'color: silver', # white
|
|
58
|
+
'39' => 'color: silver', # default (white)
|
|
59
|
+
'40' => 'background-color: black', # on black
|
|
60
|
+
'41' => 'background-color: maroon', # on red
|
|
61
|
+
'42' => 'background-color: green', # on green
|
|
62
|
+
'43' => 'background-color: olive', # on yellow
|
|
63
|
+
'44' => 'background-color: navy', # on blue
|
|
64
|
+
'45' => 'background-color: purple', # on magenta
|
|
65
|
+
'46' => 'background-color: teal', # on cyan
|
|
66
|
+
'47' => 'background-color: silver', # on white
|
|
67
|
+
'49' => 'background-color: black', # on default (black)
|
|
68
|
+
'90' => 'color: gray', # bright black
|
|
69
|
+
'91' => 'color: red', # bright red
|
|
70
|
+
'92' => 'color: lime', # bright green
|
|
71
|
+
'93' => 'color: yellow', # bright yellow
|
|
72
|
+
'94' => 'color: blue', # bright blue
|
|
73
|
+
'95' => 'color: fuchsia', # bright magenta
|
|
74
|
+
'96' => 'color: cyan', # bright cyan
|
|
75
|
+
'97' => 'color: white', # bright white
|
|
76
|
+
'100' => 'background-color: gray', # on bright black
|
|
77
|
+
'101' => 'background-color: red', # on bright red
|
|
78
|
+
'102' => 'background-color: lime', # on bright green
|
|
79
|
+
'103' => 'background-color: yellow', # on bright yellow
|
|
80
|
+
'104' => 'background-color: blue', # on bright blue
|
|
81
|
+
'105' => 'background-color: fuchsia', # on bright magenta
|
|
82
|
+
'106' => 'background-color: cyan', # on bright cyan
|
|
83
|
+
'107' => 'background-color: white' # on bright white
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
ATTRIBUTES_RE = ::Regexp.union(*ATTRIBUTES.keys)
|
|
87
|
+
|
|
88
|
+
DELIMITER = ';'
|
|
89
|
+
|
|
90
|
+
COLOR_RE = %r{
|
|
91
|
+
\e \[ ( #{ATTRIBUTES_RE} (?: #{DELIMITER} #{ATTRIBUTES_RE} )* ) m
|
|
92
|
+
}x
|
|
93
|
+
|
|
94
|
+
STYLE = '<span style="%s">'
|
|
95
|
+
CLEAR = '</span>'
|
|
96
|
+
|
|
97
|
+
def convert(string)
|
|
98
|
+
string.gsub(COLOR_RE) { format($1.split(DELIMITER).uniq) }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def format(attributes)
|
|
102
|
+
"#{clear(attributes)}#{style(attributes) if attributes.any?}"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def clear(attributes)
|
|
106
|
+
CLEAR if attributes.delete('0')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def style(attributes)
|
|
110
|
+
STYLE % ATTRIBUTES.values_at(*attributes).join('; ')
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
class String
|
|
117
|
+
|
|
118
|
+
def ansicolor2css
|
|
119
|
+
::Nuggets::ANSIColor2CSS.convert(self)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
alias_method :ansicolour2css, :ansicolor2css
|
|
123
|
+
|
|
124
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#--
|
|
2
|
+
###############################################################################
|
|
3
|
+
# #
|
|
4
|
+
# nuggets -- Extending Ruby #
|
|
5
|
+
# #
|
|
6
|
+
# Copyright (C) 2007-2013 Jens Wille #
|
|
7
|
+
# #
|
|
8
|
+
# Authors: #
|
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
|
10
|
+
# #
|
|
11
|
+
# nuggets is free software; you can redistribute it and/or modify it under #
|
|
12
|
+
# the terms of the GNU Affero General Public License as published by the Free #
|
|
13
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
|
14
|
+
# any later version. #
|
|
15
|
+
# #
|
|
16
|
+
# nuggets is distributed in the hope that it will be useful, but WITHOUT ANY #
|
|
17
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
|
18
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
|
|
19
|
+
# more details. #
|
|
20
|
+
# #
|
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
|
22
|
+
# along with nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
|
23
|
+
# #
|
|
24
|
+
###############################################################################
|
|
25
|
+
#++
|
|
26
|
+
|
|
27
|
+
module Nuggets
|
|
28
|
+
module Argv
|
|
29
|
+
module OptionMixin
|
|
30
|
+
|
|
31
|
+
# call-seq:
|
|
32
|
+
# ARGV.switch(short[, long]) -> true | false
|
|
33
|
+
#
|
|
34
|
+
# Whether ARGV includes the switch +short+ (or +long+).
|
|
35
|
+
def switch(*args)
|
|
36
|
+
!!(__key(*args) { |key| include?(key) })
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# call-seq:
|
|
40
|
+
# ARGV.option(short[, long]) -> aString
|
|
41
|
+
# ARGV.option(short[, long]) { |value| ... } -> anObject
|
|
42
|
+
#
|
|
43
|
+
# Returns the value associated with the option +short+ (or +long+) if present
|
|
44
|
+
# in ARGV. Yields that value to the block if given and returns its result.
|
|
45
|
+
def option(*args, &block)
|
|
46
|
+
__opt(block, *args) { |index| at(index + 1) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# call-seq:
|
|
50
|
+
# ARGV.switch!(short[, long]) -> true | false
|
|
51
|
+
#
|
|
52
|
+
# Whether ARGV includes the switch +short+ (or +long+). Removes the matching
|
|
53
|
+
# switch from ARGV.
|
|
54
|
+
def switch!(*args)
|
|
55
|
+
!!(__key(*args) { |key| delete(key) })
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# call-seq:
|
|
59
|
+
# ARGV.option!(short[, long]) -> aString
|
|
60
|
+
# ARGV.option!(short[, long]) { |value| ... } -> anObject
|
|
61
|
+
#
|
|
62
|
+
# Returns the value associated with the option +short+ (or +long+) if present
|
|
63
|
+
# in ARGV and removes both from ARGV. Yields that value to the block if given
|
|
64
|
+
# and returns its result.
|
|
65
|
+
def option!(*args, &block)
|
|
66
|
+
__opt(block, *args) { |index| delete_at(index); delete_at(index) }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def __key(short, long = nil) # :yield: key
|
|
72
|
+
long && yield("--#{long}") || yield("-#{short}")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def __opt(block, *args)
|
|
76
|
+
index = __key(*args) { |key| index(key) } or return
|
|
77
|
+
|
|
78
|
+
value = yield(index)
|
|
79
|
+
block ? block[value] : value
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|