ruby-nuggets 0.9.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,78 +0,0 @@
|
|
1
|
-
require 'nuggets/hash/deep_merge'
|
2
|
-
|
3
|
-
describe_extended Hash, Nuggets::Hash::DeepMergeMixin do
|
4
|
-
|
5
|
-
example do
|
6
|
-
{ :a => 1 }.deep_merge(:a => 2).should == { :a => 2 }
|
7
|
-
end
|
8
|
-
|
9
|
-
example do
|
10
|
-
{ :a => 1 }.deep_merge(:b => 2).should == { :a => 1, :b => 2 }
|
11
|
-
end
|
12
|
-
|
13
|
-
example do
|
14
|
-
{ :a => { :b => 1 } }.deep_merge(:b => 2).should == { :a => { :b => 1 }, :b => 2 }
|
15
|
-
end
|
16
|
-
|
17
|
-
example do
|
18
|
-
{ :a => { :b => 1 } }.deep_merge(:a => { :b => 2 }).should == { :a => { :b => 2 } }
|
19
|
-
end
|
20
|
-
|
21
|
-
example do
|
22
|
-
lambda { { :a => { :b => { :c => 1 } } }.deep_merge(:a => { :b => 2 }) }.should raise_error(TypeError)
|
23
|
-
end
|
24
|
-
|
25
|
-
example do
|
26
|
-
{ :a => { :b => { :c => 1 } } }.deep_merge(:a => { :b => { :c => 2 } }).should == { :a => { :b => { :c => 2 } } }
|
27
|
-
end
|
28
|
-
|
29
|
-
example do
|
30
|
-
{ :a => { :b => { :c => 1 } } }.deep_merge(:a => { :b => { :d => 2 } }).should == { :a => { :b => { :c => 1, :d => 2 } } }
|
31
|
-
end
|
32
|
-
|
33
|
-
example do
|
34
|
-
{ :a => { :b => { :c => 1 } } }.deep_merge(:a => { :b => { :c => 2 }, :d => 3 }).should == { :a => { :b => { :c => 2 }, :d => 3 } }
|
35
|
-
end
|
36
|
-
|
37
|
-
example do
|
38
|
-
{ :a => { :b => { :c => 1 }, :d => 2 } }.deep_merge(:a => { :b => { :c => 2 }, :d => 3 }).should == { :a => { :b => { :c => 2 }, :d => 3 } }
|
39
|
-
end
|
40
|
-
|
41
|
-
example do
|
42
|
-
{ :a => { :b => { :c => 1 }, :d => 2 }, :e => 3 }.deep_merge(:a => { :b => { :c => 2 }, :d => 3 }).should == { :a => { :b => { :c => 2 }, :d => 3 }, :e => 3 }
|
43
|
-
end
|
44
|
-
|
45
|
-
example do
|
46
|
-
{ :a => { :b => { :c => 1 } }, :d => { :e => 3 } }.deep_merge(:a => { :b => { :c => 2 } }, :d => { :e => 4 }).should == { :a => { :b => { :c => 2 } }, :d => { :e => 4 } }
|
47
|
-
end
|
48
|
-
|
49
|
-
context do
|
50
|
-
|
51
|
-
before :each do
|
52
|
-
@sub_hash1 = { :b => 1 }
|
53
|
-
@sub_hash2 = { :b => 2 }
|
54
|
-
|
55
|
-
@hash1 = { :a => @sub_hash1 }
|
56
|
-
@hash2 = { :a => @sub_hash2 }
|
57
|
-
@hash3 = { :a => { :b => 2} }
|
58
|
-
end
|
59
|
-
|
60
|
-
example do
|
61
|
-
@hash1.deep_merge(@hash2).should == @hash3
|
62
|
-
@hash1.should_not == @hash3
|
63
|
-
|
64
|
-
@sub_hash1[:b].should == 1
|
65
|
-
@sub_hash2[:b].should == 2
|
66
|
-
end
|
67
|
-
|
68
|
-
example do
|
69
|
-
@hash1.deep_merge!(@hash2).should == @hash3
|
70
|
-
@hash1.should == @hash3
|
71
|
-
|
72
|
-
@sub_hash1[:b].should == 1
|
73
|
-
@sub_hash2[:b].should == 2
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'nuggets/hash/insert'
|
2
|
-
|
3
|
-
describe Hash, 'insert' do
|
4
|
-
|
5
|
-
let(:h) { { a: 0, b: { b1: 1, b2: 2 } } }
|
6
|
-
|
7
|
-
example { h.insert(a: -1).should == { a: -1, b: { b1: 1, b2: 2 } } }
|
8
|
-
|
9
|
-
example { h.insert(b: { b3: 3 }).should == { a: 0, b: { b1: 1, b2: 2, b3: 3 } } }
|
10
|
-
|
11
|
-
example { h.insert!(b: { b0: 0 }); h.should == { a: 0, b: { b1: 1, b2: 2, b0: 0 } } }
|
12
|
-
|
13
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'nuggets/hash/nest'
|
2
|
-
|
3
|
-
describe_extended Hash, Nuggets::Hash::NestMixin, true do
|
4
|
-
|
5
|
-
example do
|
6
|
-
hash = Hash.nest
|
7
|
-
hash.should be_an_instance_of(Hash)
|
8
|
-
|
9
|
-
hash[:a].should be_nil
|
10
|
-
hash.should have_key(:a)
|
11
|
-
end
|
12
|
-
|
13
|
-
example do
|
14
|
-
hash = Hash.nest(0, 1)
|
15
|
-
hash.should be_an_instance_of(Hash)
|
16
|
-
|
17
|
-
hash[:a].should == 1
|
18
|
-
hash.should have_key(:a)
|
19
|
-
end
|
20
|
-
|
21
|
-
example do
|
22
|
-
hash = Hash.nest(1)
|
23
|
-
hash.should be_an_instance_of(Hash)
|
24
|
-
|
25
|
-
hash[:a].should be_an_instance_of(Hash)
|
26
|
-
hash.should have_key(:a)
|
27
|
-
|
28
|
-
hash[:a][:b].should be_nil
|
29
|
-
hash[:a].should have_key(:b)
|
30
|
-
end
|
31
|
-
|
32
|
-
example do
|
33
|
-
hash = Hash.nest(1, 1)
|
34
|
-
hash.should be_an_instance_of(Hash)
|
35
|
-
|
36
|
-
hash[:a].should be_an_instance_of(Hash)
|
37
|
-
hash.should have_key(:a)
|
38
|
-
|
39
|
-
hash[:a][:b].should == 1
|
40
|
-
hash[:a].should have_key(:b)
|
41
|
-
end
|
42
|
-
|
43
|
-
example do
|
44
|
-
hash = Hash.nest(1, [])
|
45
|
-
hash.should be_an_instance_of(Hash)
|
46
|
-
|
47
|
-
hash[:a].should be_an_instance_of(Hash)
|
48
|
-
hash.should have_key(:a)
|
49
|
-
|
50
|
-
hash[:a][:b].should == []
|
51
|
-
hash[:a].should have_key(:b)
|
52
|
-
|
53
|
-
hash[:a][:b] << 1
|
54
|
-
hash[:a][:b].should == [1]
|
55
|
-
|
56
|
-
hash[:a][:c] << 2
|
57
|
-
hash[:a][:c].should == [1, 2]
|
58
|
-
|
59
|
-
hash[:a][:b].should == [1, 2]
|
60
|
-
end
|
61
|
-
|
62
|
-
example do
|
63
|
-
hash = Hash.nest(1) { [] }
|
64
|
-
hash.should be_an_instance_of(Hash)
|
65
|
-
|
66
|
-
hash[:a].should be_an_instance_of(Hash)
|
67
|
-
hash.should have_key(:a)
|
68
|
-
|
69
|
-
hash[:a][:b].should == []
|
70
|
-
hash[:a].should have_key(:b)
|
71
|
-
|
72
|
-
hash[:a][:b] << 1
|
73
|
-
hash[:a][:b].should == [1]
|
74
|
-
|
75
|
-
hash[:a][:c] << 2
|
76
|
-
hash[:a][:c].should == [2]
|
77
|
-
|
78
|
-
hash[:a][:b].should == [1]
|
79
|
-
end
|
80
|
-
|
81
|
-
example do
|
82
|
-
hash = Hash.nest(3)
|
83
|
-
hash.should be_an_instance_of(Hash)
|
84
|
-
|
85
|
-
hash[:a].should be_an_instance_of(Hash)
|
86
|
-
hash.should have_key(:a)
|
87
|
-
|
88
|
-
hash[:a][:b].should be_an_instance_of(Hash)
|
89
|
-
hash[:a].should have_key(:b)
|
90
|
-
|
91
|
-
hash[:a][:b][:c].should be_an_instance_of(Hash)
|
92
|
-
hash[:a][:b].should have_key(:c)
|
93
|
-
|
94
|
-
hash[:a][:b][:c][:d].should be_nil
|
95
|
-
hash[:a][:b][:c].should have_key(:d)
|
96
|
-
|
97
|
-
hash[:a][:b][:c][:e] = 1
|
98
|
-
hash[:a][:b][:c][:e].should == 1
|
99
|
-
hash[:a][:b][:c].should have_key(:e)
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'nuggets/hash/only'
|
2
|
-
|
3
|
-
describe Hash, 'only' do
|
4
|
-
|
5
|
-
example {
|
6
|
-
h = { a: 5 }
|
7
|
-
|
8
|
-
h.only.should == { a: 5 }
|
9
|
-
h.only_pair.should == [:a, 5]
|
10
|
-
h.only(true).should == { a: 5 }
|
11
|
-
}
|
12
|
-
|
13
|
-
example {
|
14
|
-
h = { 1 => 2, 3 => 4 }
|
15
|
-
|
16
|
-
lambda { h.only }.should raise_error(IndexError, 'not a single-element hash')
|
17
|
-
lambda { h.only_pair }.should raise_error(IndexError, 'not a single-element hash')
|
18
|
-
h.only(true).should == { 1 => 2 }
|
19
|
-
}
|
20
|
-
|
21
|
-
example {
|
22
|
-
h = {}
|
23
|
-
|
24
|
-
lambda { h.only }.should raise_error(IndexError, 'not a single-element hash')
|
25
|
-
lambda { h.only_pair }.should raise_error(IndexError, 'not a single-element hash')
|
26
|
-
h.only(true).should == {}
|
27
|
-
}
|
28
|
-
|
29
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'nuggets/hash/seen'
|
2
|
-
|
3
|
-
describe_extended Hash, Nuggets::Hash::SeenMixin, true do
|
4
|
-
|
5
|
-
example do
|
6
|
-
hash = Hash.seen
|
7
|
-
hash.should be_an_instance_of(Hash)
|
8
|
-
|
9
|
-
hash[:a].should == false
|
10
|
-
hash.should have_key(:a)
|
11
|
-
|
12
|
-
hash[:a].should == true
|
13
|
-
hash[:a].should == true
|
14
|
-
end
|
15
|
-
|
16
|
-
example do
|
17
|
-
hash = Hash.seen(0, 1)
|
18
|
-
hash.should be_an_instance_of(Hash)
|
19
|
-
|
20
|
-
hash[:a].should == 1
|
21
|
-
hash.should have_key(:a)
|
22
|
-
|
23
|
-
hash[:a].should == 0
|
24
|
-
hash[:a].should == 0
|
25
|
-
end
|
26
|
-
|
27
|
-
example do
|
28
|
-
hash = Hash.seen.update(:a => :b)
|
29
|
-
hash.should be_an_instance_of(Hash)
|
30
|
-
|
31
|
-
hash[:a].should == :b
|
32
|
-
hash[:a].should == :b
|
33
|
-
hash.should have_key(:a)
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'nuggets/hash/unroll'
|
2
|
-
|
3
|
-
describe_extended Hash, Nuggets::Hash::UnrollMixin do
|
4
|
-
|
5
|
-
example do
|
6
|
-
hash = {}
|
7
|
-
hash.unroll.should == [[]]
|
8
|
-
end
|
9
|
-
|
10
|
-
example do
|
11
|
-
hash = { 'a' => 1 }
|
12
|
-
hash.unroll.should == [[1]]
|
13
|
-
end
|
14
|
-
|
15
|
-
example do
|
16
|
-
hash = { 'a' => { 'b' => 1 } }
|
17
|
-
hash.unroll.should == [['a', 1]]
|
18
|
-
end
|
19
|
-
|
20
|
-
example do
|
21
|
-
hash = { :a => { :b => 1 } }
|
22
|
-
hash.unroll.should == [[:a, 1]]
|
23
|
-
end
|
24
|
-
|
25
|
-
example do
|
26
|
-
hash = { :a => { :b => 1, :c => 2 } }
|
27
|
-
|
28
|
-
result = hash.unroll.first
|
29
|
-
result.size.should == 3
|
30
|
-
|
31
|
-
result.first.should == :a
|
32
|
-
result.should include(1)
|
33
|
-
result.should include(2)
|
34
|
-
end
|
35
|
-
|
36
|
-
if RUBY_VERSION < '1.9'
|
37
|
-
example do
|
38
|
-
hash = { :a => { :b => 1, :c => 2 } }
|
39
|
-
lambda { hash.unroll(:sort => true) }.should raise_error(NoMethodError, /<=>/)
|
40
|
-
end
|
41
|
-
|
42
|
-
example do
|
43
|
-
hash = { :a => { :b => 1, :c => 2 } }
|
44
|
-
lambda { hash.unroll(:sort_by => lambda { |h| h.to_s }) }.should_not raise_error(NoMethodError)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
example do
|
49
|
-
hash = { 'a' => { 'b' => 1, 'c' => 2 } }
|
50
|
-
hash.unroll(:sort => true).should == [['a', 1, 2]]
|
51
|
-
end
|
52
|
-
|
53
|
-
example do
|
54
|
-
hash = { 'a' => { 'b' => 1, 'c' => 2 }, 'd' => { 'b' => 0, 'c' => 3 } }
|
55
|
-
hash.unroll('b', 'c', :sort => true).should == [['a', 1, 2], ['d', 0, 3]]
|
56
|
-
end
|
57
|
-
|
58
|
-
example do
|
59
|
-
hash = { 'z' => { 'a' => { 'b' => 1, 'c' => 2 }, 'd' => { 'b' => 0, 'c' => 3 } } }
|
60
|
-
hash.unroll('b', :sort_by => lambda { |h| h.to_s }).should == [['z', 'a', 1], ['z', 'd', 0]]
|
61
|
-
end
|
62
|
-
|
63
|
-
example do
|
64
|
-
hash = { 'z' => { 'a' => { 'b' => 1, 'c' => 2 }, 'd' => { 'b' => 0, 'c' => 3 } } }
|
65
|
-
hash.unroll(:sort => true) { |h| h['b'] = nil; h['c'] *= 2 }.should == [['z', 'a', nil, 4], ['z', 'd', nil, 6]]
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
data/spec/nuggets/i18n_spec.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'nuggets/i18n'
|
4
|
-
|
5
|
-
describe String, 'i18n' do
|
6
|
-
|
7
|
-
let(:s) { 'Äh, Rüby iß sö cüül, nö? SÖS!' }
|
8
|
-
|
9
|
-
example { s.replace_diacritics.should == 'Aeh, Rueby iss soe cueuel, noe? SOES!' }
|
10
|
-
|
11
|
-
example { s.replace_diacritics!; s.should == 'Aeh, Rueby iss soe cueuel, noe? SOES!' }
|
12
|
-
|
13
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'nuggets/integer/length'
|
2
|
-
|
3
|
-
describe_extended Integer, Nuggets::Integer::LengthMixin do
|
4
|
-
|
5
|
-
{
|
6
|
-
0 => [1, 1],
|
7
|
-
123 => [3, 3],
|
8
|
-
-123 => [4, 3],
|
9
|
-
1_000_000 => [7, 7],
|
10
|
-
-1_000_000 => [8, 7],
|
11
|
-
10 ** 48 => [49, 49],
|
12
|
-
-(10 ** 48) => [50, 49]
|
13
|
-
}.each { |int, (len, cnt)|
|
14
|
-
example { int.length.should == len }
|
15
|
-
example { int.digit_count.should == cnt }
|
16
|
-
}
|
17
|
-
|
18
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'nuggets/integer/map'
|
2
|
-
|
3
|
-
describe_extended Integer, Nuggets::Integer::MapMixin do
|
4
|
-
|
5
|
-
{
|
6
|
-
0 => 1,
|
7
|
-
1 => 2,
|
8
|
-
-1 => 3,
|
9
|
-
123 => 246,
|
10
|
-
-123 => 247,
|
11
|
-
1_000_000 => 2_000_000,
|
12
|
-
-1_000_000 => 2_000_001,
|
13
|
-
10 ** 48 => 2_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000,
|
14
|
-
-(10 ** 48) => 2_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_001
|
15
|
-
}.each { |int, map|
|
16
|
-
example { int.map_positive.should == map }
|
17
|
-
}
|
18
|
-
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'nuggets/integer/to_binary_s'
|
2
|
-
|
3
|
-
describe Integer, 'to_binary_s' do
|
4
|
-
|
5
|
-
{
|
6
|
-
20000 => %w[00000000000000000100111000100000 100111000100000],
|
7
|
-
800 => %w[00000000000000000000001100100000 1100100000],
|
8
|
-
300 => %w[00000000000000000000000100101100 100101100],
|
9
|
-
700 => %w[00000000000000000000001010111100 1010111100],
|
10
|
-
130 => %w[00000000000000000000000010000010 10000010],
|
11
|
-
480 => %w[00000000000000000000000111100000 111100000],
|
12
|
-
9999 => %w[00000000000000000010011100001111 10011100001111],
|
13
|
-
25000 => %w[00000000000000000110000110101000 110000110101000]
|
14
|
-
}.each { |i, (j, k)|
|
15
|
-
example { i.to_binary_s.should == k }
|
16
|
-
example { i.to_binary_s(32).should == j }
|
17
|
-
}
|
18
|
-
|
19
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'nuggets/numeric/duration'
|
2
|
-
|
3
|
-
describe Numeric, 'duration' do
|
4
|
-
|
5
|
-
{
|
6
|
-
123 => [[[ 0, 2, 3], '2m3s', '2m3.00s'], [[0, 0, 0.0014236111111111112], '0d', '0d 2m3s']],
|
7
|
-
123456789 => [[[34293, 33, 9], '34293h33m9s', '34293h33m9.00s'], [[3, 11, 3.1480208333333333], '3y11m3d', '3y11m3d 3h33m9s']],
|
8
|
-
0 => [[[ 0, 0, 0], '0s', '0.00s'], [[0, 0, 0.0], '0d', '0d 0s']],
|
9
|
-
0.001 => [[[ 0, 0, 0.001], '0s', '0.00s'], [[0, 0, 1.1574074074074074e-08], '0d', '0d 0s']],
|
10
|
-
1.23 => [[[ 0, 0, 1.23], '1s', '1.23s'], [[0, 0, 1.4236111111111111e-05], '0d', '0d 1s']],
|
11
|
-
1234.56789 => [[[ 0, 20, 34.567890000000034], '20m35s', '20m34.57s'], [[0, 0, 0.014288980208333333], '0d', '0d 20m35s']]
|
12
|
-
}.each { |n, (h, y)|
|
13
|
-
example { [n.hms, n.to_hms, n.to_hms(2)].should == h }
|
14
|
-
example { [n.ymd, n.to_ymd, n.to_ymd(true)].should == y }
|
15
|
-
}
|
16
|
-
|
17
|
-
example {
|
18
|
-
lambda { -1.hms }.should raise_error(ArgumentError, 'negative duration -1')
|
19
|
-
}
|
20
|
-
|
21
|
-
example {
|
22
|
-
lambda { -1.ymd }.should raise_error(ArgumentError, 'negative duration -1')
|
23
|
-
}
|
24
|
-
|
25
|
-
end
|