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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'nuggets/object/boolean'
|
|
2
|
+
|
|
3
|
+
describe_extended Object, Nuggets::Object::BooleanMixin do
|
|
4
|
+
|
|
5
|
+
[0, 1, -1, nil, '', 'abc', Class, Object.new].each { |o|
|
|
6
|
+
example { o.should_not be_boolean }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
[true, false].each { |o|
|
|
10
|
+
example { o.should be_boolean }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
[0, 1, -1, '', 'abc', Class, Object.new, true].each { |o|
|
|
14
|
+
example { o.negate.should == false }
|
|
15
|
+
example { o.to_bool.should == true }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
[nil, false].each { |o|
|
|
19
|
+
example { o.negate.should == true }
|
|
20
|
+
example { o.to_bool.should == false }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'nuggets/object/msend'
|
|
2
|
+
|
|
3
|
+
describe_extended Object, Nuggets::Object::MSendMixin do
|
|
4
|
+
|
|
5
|
+
example do
|
|
6
|
+
o = 'foo bar'
|
|
7
|
+
o.msend(:length, :reverse).should == [o.length, o.reverse]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
example do
|
|
11
|
+
o = 42
|
|
12
|
+
o.msend(:to_s, :* => 2).should == [o.to_s, o * 2]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
example do
|
|
16
|
+
o = 42
|
|
17
|
+
o.msend([:to_s, 2], '-@').should == [o.to_s(2), -o]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
example do
|
|
21
|
+
o = Time.now
|
|
22
|
+
o.msend(:year, :month, :day).should == [o.year, o.month, o.day]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'nuggets/object/silence'
|
|
2
|
+
|
|
3
|
+
describe_extended Object, Nuggets::Object::SilenceMixin do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
@stderr, @old_stderr = '', $stderr
|
|
7
|
+
$stderr = StringIO.new(@stderr)
|
|
8
|
+
|
|
9
|
+
AConst = :foo
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
after do
|
|
13
|
+
$stderr = @old_stderr
|
|
14
|
+
Object.send(:remove_const, :AConst) if Object.const_defined?(:AConst)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
example do
|
|
18
|
+
AConst = :bar
|
|
19
|
+
|
|
20
|
+
AConst.should be_equal(:bar)
|
|
21
|
+
|
|
22
|
+
if RUBY_ENGINE == 'rbx'
|
|
23
|
+
@stderr.should == ''
|
|
24
|
+
else
|
|
25
|
+
@stderr.should =~ /warning: already initialized constant AConst/
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
example do
|
|
30
|
+
silence { AConst = :baz }
|
|
31
|
+
|
|
32
|
+
AConst.should be_equal(:baz)
|
|
33
|
+
@stderr.should == ''
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'nuggets/object/singleton_class'
|
|
2
|
+
|
|
3
|
+
describe_extended Object, Nuggets::Object::SingletonClassMixin do
|
|
4
|
+
|
|
5
|
+
objects = [Class, Object.new, Class.new, 's', [1, 2], { :a => 'b' }]
|
|
6
|
+
objects.unshift(Object) unless RUBY_PLATFORM == 'java' || RUBY_ENGINE == 'rbx'
|
|
7
|
+
|
|
8
|
+
objects.each { |o|
|
|
9
|
+
example { o.should_not be_a_singleton_class }
|
|
10
|
+
example { lambda { o.singleton_object }.should raise_error(TypeError) }
|
|
11
|
+
|
|
12
|
+
s = o.singleton_class
|
|
13
|
+
|
|
14
|
+
example { s.should be_a_singleton_class }
|
|
15
|
+
example { s.singleton_object.should be_equal(o) }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
example do
|
|
19
|
+
c = Class.new
|
|
20
|
+
c.should_not be_a_singleton_class
|
|
21
|
+
o = c.new
|
|
22
|
+
c.should_not be_a_singleton_class
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
example do
|
|
26
|
+
nil.singleton_class.should == NilClass
|
|
27
|
+
|
|
28
|
+
if RUBY_VERSION < '2'
|
|
29
|
+
NilClass.should be_a_singleton_class
|
|
30
|
+
else
|
|
31
|
+
NilClass.should be_a_virtual_class
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
NilClass.singleton_object.should be_equal(nil)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
example do
|
|
38
|
+
class A; end
|
|
39
|
+
class B < A; end
|
|
40
|
+
|
|
41
|
+
a = A.singleton_class
|
|
42
|
+
b = B.singleton_class
|
|
43
|
+
|
|
44
|
+
a.should be_a_singleton_class
|
|
45
|
+
b.should be_a_singleton_class
|
|
46
|
+
|
|
47
|
+
a.singleton_object.should be_equal(A)
|
|
48
|
+
b.singleton_object.should be_equal(B)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'nuggets/proc/bind'
|
|
2
|
+
|
|
3
|
+
describe_extended Proc, Nuggets::Proc::BindMixin do
|
|
4
|
+
|
|
5
|
+
before :each do
|
|
6
|
+
@l = lambda { bla }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
example do
|
|
10
|
+
lambda { @l.call }.should raise_error(NameError)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
example do
|
|
14
|
+
module Foo; def self.bla; 'bar'; end; end
|
|
15
|
+
@l.bind(Foo).call.should == 'bar'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
example do
|
|
19
|
+
class Bar; def self.bla; 'baz'; end; end
|
|
20
|
+
@l.bind(Bar).call.should == 'baz'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
example do
|
|
24
|
+
class Baz; def bla; 'foo'; end; end
|
|
25
|
+
@l.bind(Baz.new).call.should == 'foo'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'nuggets/range/quantile'
|
|
2
|
+
|
|
3
|
+
describe_extended Range, Nuggets::Range::QuantileMixin do
|
|
4
|
+
|
|
5
|
+
example do
|
|
6
|
+
(1..5).quantile(0, 3).should == 1
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
example do
|
|
10
|
+
(1..5).quantile(1, 3).should == 1
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
example do
|
|
14
|
+
(1..5).quantile(2, 3).should == 1
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
example do
|
|
18
|
+
(1..5).quantile(3, 3).should == 2
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
example do
|
|
22
|
+
(1..5).quantile(4, 3).should == 3
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
example do
|
|
26
|
+
(1..5).quantile(5, 3).should == 3
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
example do
|
|
30
|
+
(1..5).quantile(6, 3).should == 3
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require 'nuggets/string/camelscore'
|
|
2
|
+
|
|
3
|
+
describe_extended String, Nuggets::String::CamelscoreMixin do
|
|
4
|
+
|
|
5
|
+
def self.with_acronyms(acronyms, &block)
|
|
6
|
+
describe "with acronyms #{acronyms.inspect}" do
|
|
7
|
+
before :all do ::String::CAMELSCORE_ACRONYMS.replace(acronyms) end
|
|
8
|
+
after :all do ::String::CAMELSCORE_ACRONYMS.clear end
|
|
9
|
+
|
|
10
|
+
instance_eval(&block)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
with_acronyms({}) { [
|
|
15
|
+
['', ''],
|
|
16
|
+
%w[a A],
|
|
17
|
+
%w[a_b AB],
|
|
18
|
+
%w[a_b_c ABC],
|
|
19
|
+
%w[a/b A::B],
|
|
20
|
+
%w[a/b_c A::BC],
|
|
21
|
+
%w[a/b/c A::B::C],
|
|
22
|
+
%w[foo Foo],
|
|
23
|
+
%w[foo_bar FooBar],
|
|
24
|
+
%w[foo_bar_baz FooBarBaz],
|
|
25
|
+
%w[foo/bar Foo::Bar],
|
|
26
|
+
%w[foo/bar_baz Foo::BarBaz],
|
|
27
|
+
%w[foo/bar/baz Foo::Bar::Baz],
|
|
28
|
+
%w[active_model ActiveModel],
|
|
29
|
+
%w[active_model/errors ActiveModel::Errors],
|
|
30
|
+
%w[ssl_error SslError],
|
|
31
|
+
%w[s_s_l_error SSLError]
|
|
32
|
+
].each { |a, b|
|
|
33
|
+
example { a.camelcase.should == b }
|
|
34
|
+
example { b.underscore.should == a }
|
|
35
|
+
} }
|
|
36
|
+
|
|
37
|
+
with_acronyms('ab' => 'AB') {
|
|
38
|
+
example { 'ab'.camelcase.should == 'AB' }
|
|
39
|
+
example { 'AB'.underscore.should == 'ab' }
|
|
40
|
+
example { 'abc'.camelcase.should == 'Abc' }
|
|
41
|
+
example { 'Abc'.underscore.should == 'abc' }
|
|
42
|
+
example { 'ab_c'.camelcase.should == 'ABC' }
|
|
43
|
+
example { 'ABC'.underscore.should == 'ab_c' }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
with_acronyms('abc' => 'ABC') {
|
|
47
|
+
example { 'ab'.camelcase.should == 'Ab' }
|
|
48
|
+
example { 'AB'.underscore.should == 'a_b' }
|
|
49
|
+
example { 'abc'.camelcase.should == 'ABC' }
|
|
50
|
+
example { 'ABC'.underscore.should == 'abc' }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
with_acronyms('ab' => 'AB', 'abc' => 'ABC') {
|
|
54
|
+
example { 'ab'.camelcase.should == 'AB' }
|
|
55
|
+
example { 'AB'.underscore.should == 'ab' }
|
|
56
|
+
example { 'abc'.camelcase.should == 'ABC' }
|
|
57
|
+
example { 'Abc'.underscore.should == 'abc' }
|
|
58
|
+
example { 'ab_c'.camelcase.should == 'ABC' }
|
|
59
|
+
example { 'ABC'.underscore.should == 'ab_c' }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
with_acronyms('xml' => 'XML', 'html' => 'HTML', 'sql' => 'SQL') {
|
|
63
|
+
example { 'xml'.camelcase.should == 'XML' }
|
|
64
|
+
example { 'XML'.underscore.should == 'xml' }
|
|
65
|
+
example { 'html'.camelcase.should == 'HTML' }
|
|
66
|
+
example { 'HTML'.underscore.should == 'html' }
|
|
67
|
+
example { 'html5'.camelcase.should == 'HTML5' }
|
|
68
|
+
example { 'HTML5'.underscore.should == 'html5' }
|
|
69
|
+
#pending { 'xhtml'.camelcase.should == 'XHTML' }
|
|
70
|
+
#pending { 'XHTML'.underscore.should == 'xhtml' }
|
|
71
|
+
example { 'sql'.camelcase.should == 'SQL' }
|
|
72
|
+
example { 'SQL'.underscore.should == 'sql' }
|
|
73
|
+
#pending { 'mysql'.camelcase.should == 'MySQL' }
|
|
74
|
+
#pending { 'MySQL'.underscore.should == 'mysql' }
|
|
75
|
+
#pending { 'postgresql'.camelcase.should == 'PostgreSQL' }
|
|
76
|
+
#pending { 'PostgreSQL'.underscore.should == 'postgresql' }
|
|
77
|
+
#pending { 'sqlite'.camelcase.should == 'SQLite' }
|
|
78
|
+
#pending { 'SQLite'.underscore.should == 'sqlite' }
|
|
79
|
+
#pending { 'nosql'.camelcase.should == 'NoSQL' }
|
|
80
|
+
#pending { 'NoSQL'.underscore.should == 'nosql' }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
with_acronyms('rss' => 'RSS', 'xml' => 'XML') {
|
|
84
|
+
example { 'rss2xml'.camelcase.should == 'RSS2XML' }
|
|
85
|
+
example { 'RSS2XML'.underscore.should == 'rss2xml' }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
with_acronyms('ssl' => 'SSL') {
|
|
89
|
+
example { 'ssl'.camelcase.should == 'SSL' }
|
|
90
|
+
example { 'SSL'.underscore.should == 'ssl' }
|
|
91
|
+
example { 'ssl_error'.camelcase.should == 'SSLError' }
|
|
92
|
+
example { 'SSLError'.underscore.should == 'ssl_error' }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
example { ''.constantize.should be_nil }
|
|
96
|
+
example { '::'.constantize.should be_nil }
|
|
97
|
+
|
|
98
|
+
example { 'Nuggets'.constantize.should == ::Nuggets }
|
|
99
|
+
example { '::Nuggets'.constantize.should == ::Nuggets }
|
|
100
|
+
|
|
101
|
+
example { 'Nuggets::String'.constantize.should == ::Nuggets::String }
|
|
102
|
+
example { '::Nuggets::String'.constantize.should == ::Nuggets::String }
|
|
103
|
+
|
|
104
|
+
example { 'String'.constantize.should == ::String }
|
|
105
|
+
example { 'String'.constantize(::Nuggets).should == ::Nuggets::String }
|
|
106
|
+
example { '::String'.constantize(::Nuggets).should == ::String }
|
|
107
|
+
example { 'String'.constantize(::Nuggets::String).should == ::String }
|
|
108
|
+
example { 'String'.constantize(::Nuggets::String::CamelscoreMixin).should == ::String }
|
|
109
|
+
|
|
110
|
+
example { lambda { 'CamelscoreMixin'.constantize }.should raise_error(NameError) }
|
|
111
|
+
example { lambda { 'CamelscoreMixin'.constantize(::Nuggets) }.should raise_error(NameError) }
|
|
112
|
+
example { 'CamelscoreMixin'.constantize(::Nuggets::String).should == ::Nuggets::String::CamelscoreMixin }
|
|
113
|
+
|
|
114
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'nuggets/string/capitalize_first'
|
|
2
|
+
|
|
3
|
+
describe String, 'capitalize_first' do
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
'Some string' => 'Some string',
|
|
7
|
+
'some string' => 'Some string',
|
|
8
|
+
'SOME STRING' => 'SOME STRING'
|
|
9
|
+
}.each { |s, c|
|
|
10
|
+
example { s.capitalize_first.should == c }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'nuggets/string/case'
|
|
2
|
+
|
|
3
|
+
describe String, 'case' do
|
|
4
|
+
|
|
5
|
+
example {
|
|
6
|
+
s = 'Some string'
|
|
7
|
+
|
|
8
|
+
s.case.should == :mixed
|
|
9
|
+
s.should_not be_downcase
|
|
10
|
+
s.should_not be_upcase
|
|
11
|
+
s.should be_mixed_case
|
|
12
|
+
s.should be_capitalized
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
example {
|
|
16
|
+
s = 'some string'
|
|
17
|
+
|
|
18
|
+
s.case.should == :lower
|
|
19
|
+
s.should be_downcase
|
|
20
|
+
s.should_not be_mixed_case
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
example {
|
|
24
|
+
s = 'SOME STRING'
|
|
25
|
+
|
|
26
|
+
s.case.should == :upper
|
|
27
|
+
s.should be_upcase
|
|
28
|
+
s.should_not be_mixed_case
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'nuggets/string/evaluate'
|
|
2
|
+
|
|
3
|
+
describe_extended String, Nuggets::String::EvaluateMixin do
|
|
4
|
+
|
|
5
|
+
describe do
|
|
6
|
+
|
|
7
|
+
%w[bl#{a}blub bl#{a}#{b}lub].each { |str|
|
|
8
|
+
{ 'blablub' => %w[a b], 'blubblub' => %w[ub b] }.each { |res, (a, b)|
|
|
9
|
+
example { str.evaluate(binding).should == res }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
example do
|
|
13
|
+
lambda { str.evaluate(binding) }.should raise_error(NameError, /`a'/)
|
|
14
|
+
end
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
[ 'a"b"c', 'a\"b\"c', 'a\\"b\\"c', 'a\\\"b\\\"c',
|
|
20
|
+
"a'b'c", 'a%q{b}c', 'a{b}c', 'a{bc', 'ab}c' ].each { |str|
|
|
21
|
+
example { str.evaluate(binding).should == str }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'nuggets/string/msub'
|
|
2
|
+
|
|
3
|
+
describe String, 'msub' do
|
|
4
|
+
|
|
5
|
+
let(:s) { 'Foo, Bar - Baz' }
|
|
6
|
+
|
|
7
|
+
example { s.gsub(/a/, 'o').gsub(/o/, 'a').should == 'Faa, Bar - Baz' }
|
|
8
|
+
example { s.msub('a' => 'o', 'o' => 'a').should == 'Faa, Bor - Boz' }
|
|
9
|
+
|
|
10
|
+
example { s.msub!('a' => 'o', 'o' => 'a'); s.should == 'Faa, Bor - Boz' }
|
|
11
|
+
|
|
12
|
+
example { s.msub(/[A-Z]/ => '#{__match__.downcase}', __binding__: binding).should == 'foo, bar - baz' }
|
|
13
|
+
example { s.msub(/[A-Z]/ => lambda { |match| match.downcase }).should == 'foo, bar - baz' }
|
|
14
|
+
|
|
15
|
+
t = '!!!'
|
|
16
|
+
|
|
17
|
+
example { lambda { s.msub('r' => '???', 'z' => '#{t}') }.should raise_error(NameError) }
|
|
18
|
+
example { s.msub('r' => '???', 'z' => '#{t}', __binding__: binding).should == 'Foo, Ba??? - Ba!!!' }
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'nuggets/string/nsub'
|
|
2
|
+
|
|
3
|
+
describe String, 'nsub' do
|
|
4
|
+
|
|
5
|
+
let(:s) { 'a b c d e f g h i' }
|
|
6
|
+
|
|
7
|
+
example { s.nsub(' ', '', 6).should == 'abcdefg h i' }
|
|
8
|
+
|
|
9
|
+
example { s.nsub(' ', 6) { '' }.should == 'abcdefg h i' }
|
|
10
|
+
|
|
11
|
+
example { s.nsub!(' ', '', 6); s.should == 'abcdefg h i' }
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'nuggets/string/sub_with_md'
|
|
2
|
+
|
|
3
|
+
describe String, 'sub_with_md' do
|
|
4
|
+
|
|
5
|
+
let(:s) { 'Foo, Bar - Baz' }
|
|
6
|
+
|
|
7
|
+
example {
|
|
8
|
+
s.gsub(/\w(\w+)(\W*)/) { |m|
|
|
9
|
+
"#{$1.gsub(/[ao]/, 'X')}#{$2}"
|
|
10
|
+
}.should == 'XXXrXz'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
example {
|
|
14
|
+
s.gsub_with_md(/\w(\w+)(\W*)/) { |md|
|
|
15
|
+
"#{md[1].gsub(/[ao]/, 'X')}#{md[2]}"
|
|
16
|
+
}.should == 'XX, Xr - Xz'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
example {
|
|
20
|
+
s.gsub_with_md(/\w(\w+)(\W*)/) { |md|
|
|
21
|
+
"#{md[1].gsub_with_md(/[ao]/) { |md2| md2[0].upcase }}#{md[2]}"
|
|
22
|
+
}.should == 'OO, Ar - Az'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
end
|