ruby-nuggets 0.9.8.1 → 0.9.9
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/README +1 -1
- data/Rakefile +9 -3
- data/lib/nuggets/all.rb +1 -1
- data/lib/nuggets/array/combination.rb +2 -25
- data/lib/nuggets/array/flatten_once.rb +1 -12
- data/lib/nuggets/array/format.rb +2 -60
- data/lib/nuggets/array/in_order.rb +1 -12
- data/lib/nuggets/array/monotone.rb +10 -27
- data/lib/nuggets/array/only.rb +1 -16
- data/lib/nuggets/array/shuffle.rb +1 -1
- data/lib/nuggets/array/to_hash.rb +1 -22
- data/lib/nuggets/cli.rb +2 -2
- data/lib/nuggets/content_type.rb +3 -8
- data/lib/nuggets/dotted_decimal.rb +0 -18
- data/lib/nuggets/enumerable/all_any_extended.rb +0 -27
- data/lib/nuggets/enumerable/minmax.rb +4 -25
- data/lib/nuggets/hash/at.rb +2 -20
- data/lib/nuggets/hash/deep_fetch.rb +5 -0
- data/lib/nuggets/hash/deep_fetch_mixin.rb +75 -0
- data/lib/nuggets/hash/in_order.rb +0 -8
- data/lib/nuggets/hash/insert.rb +2 -13
- data/lib/nuggets/hash/only.rb +2 -18
- data/lib/nuggets/i18n.rb +1 -10
- data/lib/nuggets/integer/factorial.rb +0 -17
- data/lib/nuggets/integer/to_binary_s.rb +0 -8
- data/lib/nuggets/lsi.rb +2 -2
- data/lib/nuggets/midos.rb +2 -2
- data/lib/nuggets/mysql.rb +6 -207
- data/lib/nuggets/numeric/duration.rb +0 -8
- data/lib/nuggets/numeric/limit.rb +1 -8
- data/lib/nuggets/numeric/signum.rb +0 -7
- data/lib/nuggets/numeric/to_multiple.rb +0 -6
- data/lib/nuggets/rdf/compression.rb +3 -89
- data/lib/nuggets/rdf/prefix.rb +6 -32
- data/lib/nuggets/rdf/turtle/reader.rb +5 -70
- data/lib/nuggets/rdf/turtle.rb +6 -122
- data/lib/nuggets/rdf/uri.rb +5 -37
- data/lib/nuggets/ruby.rb +39 -147
- data/lib/nuggets/string/capitalize_first.rb +2 -18
- data/lib/nuggets/string/case.rb +0 -22
- data/lib/nuggets/string/msub.rb +0 -18
- data/lib/nuggets/string/nsub.rb +2 -16
- data/lib/nuggets/string/sub_with_md.rb +6 -25
- data/lib/nuggets/string/word_wrap.rb +1 -35
- data/lib/nuggets/util/ansicolor2css.rb +1 -1
- data/lib/nuggets/util/cli.rb +1 -1
- data/lib/nuggets/util/content_type.rb +1 -1
- data/lib/nuggets/util/dotted_decimal.rb +1 -2
- data/lib/nuggets/util/i18n.rb +1 -1
- data/lib/nuggets/util/lazy_attr.rb +1 -1
- data/lib/nuggets/util/log_parser/apache.rb +1 -1
- data/lib/nuggets/util/log_parser/rails.rb +1 -1
- data/lib/nuggets/util/log_parser.rb +1 -1
- data/lib/nuggets/util/midos.rb +1 -1
- data/lib/nuggets/util/mysql.rb +1 -1
- data/lib/nuggets/util/pluggable.rb +1 -1
- data/lib/nuggets/util/ruby.rb +1 -1
- data/lib/nuggets/version.rb +2 -2
- data/spec/nuggets/array/boost_spec.rb +1 -3
- data/spec/nuggets/array/combination_spec.rb +25 -0
- data/spec/nuggets/array/correlation_spec.rb +1 -3
- data/spec/nuggets/array/flatten_once_spec.rb +16 -0
- data/spec/nuggets/array/flush_spec.rb +1 -3
- data/spec/nuggets/array/format_spec.rb +52 -0
- data/spec/nuggets/array/hashify_spec.rb +1 -3
- data/spec/nuggets/array/histogram_spec.rb +1 -3
- data/spec/nuggets/array/in_order_spec.rb +13 -0
- data/spec/nuggets/array/limit_spec.rb +1 -3
- data/spec/nuggets/array/mean_spec.rb +3 -5
- data/spec/nuggets/array/median_spec.rb +3 -5
- data/spec/nuggets/array/mode_spec.rb +1 -3
- 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 +1 -3
- data/spec/nuggets/array/runiq_spec.rb +1 -3
- data/spec/nuggets/array/standard_deviation_spec.rb +1 -3
- data/spec/nuggets/array/to_hash_spec.rb +28 -0
- data/spec/nuggets/array/variance_spec.rb +3 -5
- 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 +1 -3
- data/spec/nuggets/env/user_encoding_spec.rb +1 -3
- data/spec/nuggets/env/user_home_spec.rb +12 -10
- data/spec/nuggets/file/ext_spec.rb +1 -3
- data/spec/nuggets/file/replace_spec.rb +1 -3
- data/spec/nuggets/file/sub_spec.rb +1 -3
- data/spec/nuggets/file/which_spec.rb +1 -3
- 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 +1 -3
- 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 +1 -3
- data/spec/nuggets/hash/only_spec.rb +29 -0
- data/spec/nuggets/hash/seen_spec.rb +4 -6
- data/spec/nuggets/hash/unroll_spec.rb +2 -4
- data/spec/nuggets/i18n_spec.rb +13 -0
- data/spec/nuggets/integer/factorial_spec.rb +10 -0
- data/spec/nuggets/integer/length_spec.rb +1 -3
- data/spec/nuggets/integer/map_spec.rb +1 -3
- 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 +1 -2
- data/spec/nuggets/object/boolean_spec.rb +1 -3
- data/spec/nuggets/object/msend_spec.rb +1 -3
- data/spec/nuggets/object/silence_spec.rb +7 -4
- data/spec/nuggets/object/singleton_class_spec.rb +11 -4
- data/spec/nuggets/proc/bind_spec.rb +1 -3
- data/spec/nuggets/range/quantile_spec.rb +1 -3
- data/spec/nuggets/string/camelscore_spec.rb +11 -13
- 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 +1 -3
- 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 +1 -3
- data/spec/nuggets/string/word_wrap_spec.rb +81 -0
- data/spec/nuggets/string/xor_spec.rb +1 -3
- data/spec/nuggets/uri/content_type_spec.rb +32 -27
- data/spec/nuggets/uri/exist_spec.rb +33 -9
- data/spec/spec_helper.rb +17 -0
- metadata +34 -5
- data/.rspec +0 -1
data/lib/nuggets/version.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/array/boost'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Array.ancestors.should include(Nuggets::Array::BoostMixin) }
|
3
|
+
describe_extended Array, Nuggets::Array::BoostMixin do
|
6
4
|
|
7
5
|
example {
|
8
6
|
lambda { [].boost_factor([]) }.should raise_error(NoMethodError)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'nuggets/array/combination'
|
2
|
+
|
3
|
+
describe Array, 'combination' do
|
4
|
+
|
5
|
+
let(:a) { %w[a b c d] }
|
6
|
+
|
7
|
+
example {
|
8
|
+
r = [%w[a b c], %w[a b d], %w[a c d], %w[b c d]]
|
9
|
+
|
10
|
+
a.comb(3).should == r
|
11
|
+
lambda { |b| a.comb(3, &b) }.should yield_successive_args(*r)
|
12
|
+
}
|
13
|
+
|
14
|
+
example {
|
15
|
+
a.comb(4, 2, 4).should == [%w[a b c d], %w[a b], %w[a c], %w[a d], %w[b c], %w[b d], %w[c d], %w[a b c d]]
|
16
|
+
}
|
17
|
+
|
18
|
+
example {
|
19
|
+
r = [%w[a b c d], %w[a b c], %w[a b d], %w[a c d], %w[b c d], %w[a b], %w[a c], %w[a d], %w[b c], %w[b d], %w[c d], %w[a], %w[b], %w[c], %w[d], []]
|
20
|
+
|
21
|
+
a.comb.should == r
|
22
|
+
lambda { |b| a.comb(&b) }.should yield_successive_args(*r)
|
23
|
+
}
|
24
|
+
|
25
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/array/correlation'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Array.ancestors.should include(Nuggets::Array::CorrelationMixin) }
|
3
|
+
describe_extended Array, Nuggets::Array::CorrelationMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
[].correlation_coefficient.should == 0.0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'nuggets/array/flatten_once'
|
2
|
+
|
3
|
+
describe Array, 'flatten_once' do
|
4
|
+
|
5
|
+
let(:a) { [1, 2, [3, 4, 5], 6, [7, [8, 9]]] }
|
6
|
+
|
7
|
+
example {
|
8
|
+
a.flatten_once.should == [1, 2, 3, 4, 5, 6, 7, [8, 9]]
|
9
|
+
}
|
10
|
+
|
11
|
+
example {
|
12
|
+
a.flatten_once!
|
13
|
+
a.should == [1, 2, 3, 4, 5, 6, 7, [8, 9]]
|
14
|
+
}
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'nuggets/array/format'
|
2
|
+
|
3
|
+
describe Array, 'format' do
|
4
|
+
|
5
|
+
def self.test_format(*f)
|
6
|
+
f.pop.each { |x, y| example { (f.dup % x).should == y } }
|
7
|
+
end
|
8
|
+
|
9
|
+
test_format('"%s"',
|
10
|
+
[] => '',
|
11
|
+
'string' => '"string"',
|
12
|
+
'' => ''
|
13
|
+
)
|
14
|
+
|
15
|
+
test_format('%s, (%s)', '%s', '(%s)',
|
16
|
+
['place', 'country'] => 'place, (country)',
|
17
|
+
['place', '' ] => 'place',
|
18
|
+
['', 'country'] => '(country)',
|
19
|
+
['', '' ] => ''
|
20
|
+
)
|
21
|
+
|
22
|
+
test_format('%s: %s (%s)', '%s: %s', '%s (%s)', '%s (%s)',
|
23
|
+
['author', 'title', 'year'] => 'author: title (year)',
|
24
|
+
['author', 'title', '' ] => 'author: title',
|
25
|
+
['author', '', 'year'] => 'author (year)',
|
26
|
+
['', 'title', 'year'] => 'title (year)',
|
27
|
+
['author', '' , '' ] => 'author',
|
28
|
+
['', 'title', '' ] => 'title',
|
29
|
+
['', '', 'year'] => 'year',
|
30
|
+
['', '', '' ] => ''
|
31
|
+
)
|
32
|
+
|
33
|
+
test_format({ :sep => ':' },
|
34
|
+
['1', '2', '3', '4'] => '1:2:3:4',
|
35
|
+
['1', '2', '3', '' ] => '1:2:3',
|
36
|
+
['1', '2', '', '4'] => '1:2:4',
|
37
|
+
['1', '', '3', '4'] => '1:3:4',
|
38
|
+
['', '2', '3', '4'] => '2:3:4',
|
39
|
+
['1', '2', '', '' ] => '1:2',
|
40
|
+
['1', '', '3', '' ] => '1:3',
|
41
|
+
['1', '', '', '4'] => '1:4',
|
42
|
+
['', '2', '3', '' ] => '2:3',
|
43
|
+
['', '2', '', '4'] => '2:4',
|
44
|
+
['', '', '3', '4'] => '3:4',
|
45
|
+
['1', '', '', '' ] => '1',
|
46
|
+
['', '2', '', '' ] => '2',
|
47
|
+
['', '', '3', '' ] => '3',
|
48
|
+
['', '', '', '4'] => '4',
|
49
|
+
['', '', '', '' ] => ''
|
50
|
+
)
|
51
|
+
|
52
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/array/hashify'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Array.ancestors.should include(Nuggets::Array::HashifyMixin) }
|
3
|
+
describe_extended Array, Nuggets::Array::HashifyMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
hash = [1, 2, 3, 4].hashify
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/array/histogram'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Array.ancestors.should include(Nuggets::Array::HistogramMixin) }
|
3
|
+
describe_extended Array, Nuggets::Array::HistogramMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
[].histogram.should == {}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'nuggets/array/in_order'
|
2
|
+
|
3
|
+
describe Array, 'in_order' do
|
4
|
+
|
5
|
+
let(:a) { [:created_at, :email, :login, :updated_at] }
|
6
|
+
|
7
|
+
example { a.in_order(:login, :email).should == [:login, :email, :created_at, :updated_at] }
|
8
|
+
|
9
|
+
example { a.in_order(:email, :address).should == [:email, :created_at, :login, :updated_at] }
|
10
|
+
|
11
|
+
example { a.in_order!(:login, :email); a.should == [:login, :email, :created_at, :updated_at] }
|
12
|
+
|
13
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'nuggets/array/limit'
|
2
2
|
require 'nuggets/numeric/limit'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
it { Array.ancestors.should include(Nuggets::Array::LimitMixin) }
|
4
|
+
describe_extended Array, Nuggets::Array::LimitMixin do
|
7
5
|
|
8
6
|
describe '#limit' do
|
9
7
|
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'nuggets/array/mean'
|
2
2
|
require 'nuggets/array/standard_deviation'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
it { Array.ancestors.should include(Nuggets::Array::MeanMixin) }
|
4
|
+
describe_extended Array, Nuggets::Array::MeanMixin do
|
7
5
|
|
8
6
|
describe 'equalities' do
|
9
7
|
|
@@ -82,8 +80,8 @@ describe Array, 'when extended by', Nuggets::Array::MeanMixin do
|
|
82
80
|
[1e16, 1, 3, -1e16].arithmetic_mean.should == 1.0
|
83
81
|
end
|
84
82
|
|
85
|
-
|
86
|
-
|
83
|
+
xexample do
|
84
|
+
[1e30, 1, 3, -1e30].arithmetic_mean.should == 1.0
|
87
85
|
end
|
88
86
|
|
89
87
|
context do
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/array/median'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Array.ancestors.should include(Nuggets::Array::MedianMixin) }
|
3
|
+
describe_extended Array, Nuggets::Array::MedianMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
[].median.should be_nil
|
@@ -69,11 +67,11 @@ describe Array, 'when extended by', Nuggets::Array::MedianMixin do
|
|
69
67
|
end
|
70
68
|
|
71
69
|
example do
|
72
|
-
lambda { %w[one two three four].median }.should raise_error(NoMethodError, %
|
70
|
+
lambda { %w[one two three four].median }.should raise_error(NoMethodError, %r{undefined method `/' .*String})
|
73
71
|
end
|
74
72
|
|
75
73
|
example do
|
76
|
-
lambda { [1, 2, 'three'].median }.should raise_error(ArgumentError,
|
74
|
+
lambda { [1, 2, 'three'].median }.should raise_error(ArgumentError, /comparison .* failed/)
|
77
75
|
end
|
78
76
|
|
79
77
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'nuggets/array/monotone'
|
2
|
+
|
3
|
+
describe Array, 'monotone' do
|
4
|
+
|
5
|
+
example {
|
6
|
+
a = [1, 2, 3, 4]
|
7
|
+
|
8
|
+
a.should be_monotonic
|
9
|
+
a.should be_ascending
|
10
|
+
a.should be_strictly_ascending
|
11
|
+
a.should_not be_descending
|
12
|
+
}
|
13
|
+
|
14
|
+
example {
|
15
|
+
b = [1, 2, 4, 3]
|
16
|
+
|
17
|
+
b.should_not be_monotonic
|
18
|
+
b.should_not be_ascending
|
19
|
+
b.should_not be_descending
|
20
|
+
}
|
21
|
+
|
22
|
+
example {
|
23
|
+
c = [1, 2, 4, 4]
|
24
|
+
|
25
|
+
c.should be_monotonic
|
26
|
+
c.should be_ascending
|
27
|
+
c.should_not be_strictly_ascending
|
28
|
+
}
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'nuggets/array/only'
|
2
|
+
|
3
|
+
describe Array, 'only' do
|
4
|
+
|
5
|
+
example {
|
6
|
+
a = [5]
|
7
|
+
|
8
|
+
a.only.should == 5
|
9
|
+
a.only(true).should == 5
|
10
|
+
}
|
11
|
+
|
12
|
+
example {
|
13
|
+
a = [1, 2, 3]
|
14
|
+
|
15
|
+
lambda { a.only }.should raise_error(IndexError, 'not a single-element array')
|
16
|
+
a.only(true).should == 1
|
17
|
+
}
|
18
|
+
|
19
|
+
example {
|
20
|
+
a = []
|
21
|
+
|
22
|
+
lambda { a.only }.should raise_error(IndexError, 'not a single-element array')
|
23
|
+
a.only(true).should be_nil
|
24
|
+
}
|
25
|
+
|
26
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/array/regression'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Array.ancestors.should include(Nuggets::Array::RegressionMixin) }
|
3
|
+
describe_extended Array, Nuggets::Array::RegressionMixin do
|
6
4
|
|
7
5
|
example {
|
8
6
|
[].linear_least_squares.should == []
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/array/runiq'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Array.ancestors.should include(Nuggets::Array::RuniqMixin) }
|
3
|
+
describe_extended Array, Nuggets::Array::RuniqMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
[1, 2, 3, 4, 3, 2].runiq.should == [1, 4, 3, 2]
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/array/standard_deviation'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Array.ancestors.should include(Nuggets::Array::StandardDeviationMixin) }
|
3
|
+
describe_extended Array, Nuggets::Array::StandardDeviationMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
[].standard_deviation.should == 0.0
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'nuggets/array/to_hash'
|
2
|
+
|
3
|
+
describe Array, 'to_hash' do
|
4
|
+
|
5
|
+
example {
|
6
|
+
a = [[:a, 1], [:b, 2], [:c, 3]]
|
7
|
+
a.to_h.should == { a: 1, b: 2, c: 3 }
|
8
|
+
}
|
9
|
+
|
10
|
+
example {
|
11
|
+
a = [[:a, [1, 2]], [:b, 3], [[:c, :d], [4, [5, 6]]]]
|
12
|
+
a.to_h.should == { a: [1, 2], b: 3, [:c, :d] => [4, [5, 6]] }
|
13
|
+
}
|
14
|
+
|
15
|
+
example {
|
16
|
+
a = %w[a b c d]
|
17
|
+
|
18
|
+
a.to_h.should == { 'a' => 'b', 'c' => 'd' }
|
19
|
+
a.to_h(1).should == { 'a' => 1, 'b' => 1, 'c' => 1, 'd' => 1 }
|
20
|
+
a.to_h { nil }.should == { 'a' => nil, 'b' => nil, 'c' => nil, 'd' => nil }
|
21
|
+
}
|
22
|
+
|
23
|
+
example {
|
24
|
+
h = { a: 1, b: [2, 3], c: { d: 4 } }
|
25
|
+
h.to_a.to_h.should == h
|
26
|
+
}
|
27
|
+
|
28
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/array/variance'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { Array.ancestors.should include(Nuggets::Array::VarianceMixin) }
|
3
|
+
describe_extended Array, Nuggets::Array::VarianceMixin do
|
6
4
|
|
7
5
|
example do
|
8
6
|
[].variance.should == 0.0
|
@@ -40,8 +38,8 @@ describe Array, 'when extended by', Nuggets::Array::VarianceMixin do
|
|
40
38
|
[1, 2, 4, 5, 8].variance { |i| i + 1e7 }.should == 6.0
|
41
39
|
end
|
42
40
|
|
43
|
-
|
44
|
-
|
41
|
+
xexample do
|
42
|
+
[1, 2, 4, 5, 8].variance { |i| i + 1e12 }.should == 6.0
|
45
43
|
end
|
46
44
|
|
47
45
|
example do
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'nuggets/dotted_decimal'
|
2
|
+
|
3
|
+
addr = {
|
4
|
+
'77.47.161.3' => 1294967043,
|
5
|
+
'77.47.161.11' => 1294967051,
|
6
|
+
'136.202.107.2' => 2294967042,
|
7
|
+
'196.101.53.1' => 3294967041,
|
8
|
+
'255.255.255.0' => 4294967040
|
9
|
+
}
|
10
|
+
|
11
|
+
describe Integer, 'dotted_decimal' do
|
12
|
+
|
13
|
+
addr.each { |s, i| example { i.to_dotted_decimal.should == s } }
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe String, 'dotted_decimal' do
|
18
|
+
|
19
|
+
addr.each { |s, i| example { s.from_dotted_decimal.should == i } }
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Array, 'dotted_decimal' do
|
24
|
+
|
25
|
+
example { addr.keys.sort_by_dotted_decimal.should == addr.sort_by { |k, v| v }.map(&:first) }
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'nuggets/enumerable/all_any_extended'
|
2
|
+
|
3
|
+
describe Enumerable, 'all_any_extended' do
|
4
|
+
|
5
|
+
example {
|
6
|
+
e = %w[quux quuux quix]
|
7
|
+
|
8
|
+
e.all?(String).should == true
|
9
|
+
e.any?(Numeric).should == false
|
10
|
+
}
|
11
|
+
|
12
|
+
example {
|
13
|
+
e = [:one, 'c', nil, 88]
|
14
|
+
|
15
|
+
e.all?(Object).should == true
|
16
|
+
e.any?(NilClass).should == true
|
17
|
+
}
|
18
|
+
|
19
|
+
example {
|
20
|
+
e = [0, 10, 20]
|
21
|
+
|
22
|
+
e.any?(9..99).should == true
|
23
|
+
e.any?(9, :<).should == true
|
24
|
+
e.any? { |i| i < 9 }.should == true
|
25
|
+
}
|
26
|
+
|
27
|
+
example {
|
28
|
+
lambda { [].any?(NilClass, &:nil?) }.should raise_error(ArgumentError, 'both block and object argument given')
|
29
|
+
}
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'nuggets/enumerable/minmax'
|
2
|
+
|
3
|
+
describe Enumerable, 'minmax' do
|
4
|
+
|
5
|
+
example {
|
6
|
+
e = %w[quux quuux quix]
|
7
|
+
|
8
|
+
e.max.should == 'quux'
|
9
|
+
e.max_by(:length).should == 'quuux'
|
10
|
+
e.max(:length).should == 5
|
11
|
+
}
|
12
|
+
|
13
|
+
example {
|
14
|
+
e, b = [3, 222, 45], lambda { |i| i % 10 }
|
15
|
+
|
16
|
+
e.max.should == 222
|
17
|
+
e.max_by(b).should == 45
|
18
|
+
e.max(b).should == 5
|
19
|
+
}
|
20
|
+
|
21
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/env/set'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { class << ENV; ancestors; end.should include(Nuggets::Env::SetMixin) }
|
3
|
+
describe_extended ENV, Nuggets::Env::SetMixin, true do
|
6
4
|
|
7
5
|
before do
|
8
6
|
@original = ENV.to_hash
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/env/user_encoding'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { class << ENV; ancestors; end.should include(Nuggets::Env::UserEncodingMixin) }
|
3
|
+
describe_extended ENV, Nuggets::Env::UserEncodingMixin, true do
|
6
4
|
|
7
5
|
before do
|
8
6
|
@old_env = ENV.to_hash
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/env/user_home'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { class << ENV; ancestors; end.should include(Nuggets::Env::UserHomeMixin) }
|
3
|
+
describe_extended ENV, Nuggets::Env::UserHomeMixin, true do
|
6
4
|
|
7
5
|
before do
|
8
6
|
@old_env = ENV.to_hash
|
@@ -27,14 +25,18 @@ describe ENV, 'when extended by', Nuggets::Env::UserHomeMixin do
|
|
27
25
|
ENV.user_home.should == 'foo'
|
28
26
|
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
unless RUBY_PLATFORM == 'java'
|
29
|
+
|
30
|
+
example do
|
31
|
+
ENV.clear
|
32
|
+
ENV.user_home('bar').should == 'bar'
|
33
|
+
end
|
34
|
+
|
35
|
+
example do
|
36
|
+
ENV.clear
|
37
|
+
ENV.user_home(nil).should be_nil
|
38
|
+
end
|
34
39
|
|
35
|
-
example do
|
36
|
-
ENV.clear
|
37
|
-
ENV.user_home(nil).should be_nil
|
38
40
|
end
|
39
41
|
|
40
42
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/file/ext'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { (class << File; ancestors; end).should include(Nuggets::File::ExtMixin) }
|
3
|
+
describe_extended File, Nuggets::File::ExtMixin, true do
|
6
4
|
|
7
5
|
[
|
8
6
|
['foo', nil, '.baz'],
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'nuggets/file/replace'
|
2
2
|
require 'nuggets/tempfile/open'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
it { (class << File; ancestors; end).should include(Nuggets::File::ReplaceMixin) }
|
4
|
+
describe_extended File, Nuggets::File::ReplaceMixin, true do
|
7
5
|
|
8
6
|
before :each do
|
9
7
|
@txt = <<-EOT.freeze
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'nuggets/file/sub'
|
2
2
|
require 'nuggets/tempfile/open'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
it { (class << File; ancestors; end).should include(Nuggets::File::SubMixin) }
|
4
|
+
describe_extended File, Nuggets::File::SubMixin, true do
|
7
5
|
|
8
6
|
before :each do
|
9
7
|
@txt = <<-EOT.freeze
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'nuggets/file/which'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
it { (class << File; ancestors; end).should include(Nuggets::File::WhichMixin) }
|
3
|
+
describe_extended File, Nuggets::File::WhichMixin, true do
|
6
4
|
|
7
5
|
%w[cat dog rat gcc /usr/bin/X11/gcc].each { |c|
|
8
6
|
example do
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'nuggets/hash/at'
|
2
|
+
|
3
|
+
describe Hash, 'at' do
|
4
|
+
|
5
|
+
let(:h) { { :a => 1, 2 => 3, nil => nil, 'foo' => %w[b a r] } }
|
6
|
+
|
7
|
+
example { h.first.should == { a: 1 } }
|
8
|
+
|
9
|
+
example { h.last.should == { 'foo' => %w[b a r] } }
|
10
|
+
|
11
|
+
example { h.rand.should be_a(Hash) }
|
12
|
+
|
13
|
+
example { h.at(0).should == { a: 1 } }
|
14
|
+
|
15
|
+
example { h.at(1).should == { 2 => 3 } }
|
16
|
+
|
17
|
+
example { h.at(-1).should == { 'foo' => %w[b a r] } }
|
18
|
+
|
19
|
+
end
|