nutella 0.7 → 0.8
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.
- data/lib/nutella/core_ext/file.rb +51 -0
- data/lib/nutella/core_ext/numeric.rb +43 -0
- data/lib/nutella/version.rb +1 -1
- data/spec/nutella/core_ext/enumerable_spec.rb +15 -15
- data/spec/nutella/core_ext/file_spec.rb +106 -0
- data/spec/nutella/core_ext/hash_spec.rb +6 -6
- data/spec/nutella/core_ext/integer_spec.rb +21 -21
- data/spec/nutella/core_ext/numeric_spec.rb +11 -0
- data/spec/nutella/core_ext/object_spec.rb +12 -12
- data/spec/nutella/core_ext/string_spec.rb +3 -3
- data/spec/support/alias.rb +1 -1
- metadata +9 -3
@@ -0,0 +1,51 @@
|
|
1
|
+
class File
|
2
|
+
# Gives the size of a file as a string including the unit. It will choose the
|
3
|
+
# unit to use based on how big the file is. Decimals will be rounded to the
|
4
|
+
# tenths. +size+ is either a Numeric containing the size in bytes, a File
|
5
|
+
# object, or a String with the name of the file.
|
6
|
+
#
|
7
|
+
# @example Calculates size from several numbers
|
8
|
+
# File.human_size 120 # => "120 Bytes"
|
9
|
+
# File.human_size 1234 # => "1.2 KB"
|
10
|
+
# File.human_size 1234567 # => "1.2 MB"
|
11
|
+
# File.human_size 1234567890 # => "1.1 GB"
|
12
|
+
#
|
13
|
+
# @example Calculates the size of a 3 kilobyte file "foo.txt"
|
14
|
+
# File.human_size "foo.txt" # => "3 KB"
|
15
|
+
#
|
16
|
+
# @see File#human_size
|
17
|
+
#
|
18
|
+
# @param [String, File, Numeric] size the file to measure or size in bytes
|
19
|
+
# @return [String] the human readable size
|
20
|
+
def self.human_size(size)
|
21
|
+
bytes = size.is_a?(Numeric) ? size : File.size(size) rescue nil
|
22
|
+
|
23
|
+
return "Empty" if bytes.blank? || bytes.zero?
|
24
|
+
return "1 Byte" if bytes == 1
|
25
|
+
|
26
|
+
divisor, unit =
|
27
|
+
if bytes < Numeric::KILOBYTE
|
28
|
+
[1, "Bytes"]
|
29
|
+
elsif bytes < Numeric::MEGABYTE
|
30
|
+
[Numeric::KILOBYTE, "KB"]
|
31
|
+
elsif bytes < Numeric::GIGABYTE
|
32
|
+
[Numeric::MEGABYTE, "MB"]
|
33
|
+
else
|
34
|
+
[Numeric::GIGABYTE, "GB"]
|
35
|
+
end
|
36
|
+
|
37
|
+
"%g #{unit}" % (bytes.to_f / divisor).round(1)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns the human readable form of the file's size.
|
41
|
+
#
|
42
|
+
# @example Calculates the size of a 4.2 megabyte file object
|
43
|
+
# f.human_size # => "4.2 MB"
|
44
|
+
#
|
45
|
+
# @see File::human_size
|
46
|
+
#
|
47
|
+
# @return [String] the human readable size
|
48
|
+
def human_size
|
49
|
+
File.human_size self
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Numeric
|
2
|
+
KILOBYTE = 1024
|
3
|
+
MEGABYTE = KILOBYTE * 1024
|
4
|
+
GIGABYTE = MEGABYTE * 1024
|
5
|
+
TERABYTE = GIGABYTE * 1024
|
6
|
+
PETABYTE = TERABYTE * 1024
|
7
|
+
EXABYTE = PETABYTE * 1024
|
8
|
+
|
9
|
+
def bytes
|
10
|
+
self
|
11
|
+
end
|
12
|
+
alias_method :byte, :bytes
|
13
|
+
|
14
|
+
def kilobytes
|
15
|
+
self * KILOBYTE
|
16
|
+
end
|
17
|
+
alias_method :kilobyte, :kilobytes
|
18
|
+
|
19
|
+
def megabytes
|
20
|
+
self * MEGABYTE
|
21
|
+
end
|
22
|
+
alias_method :megabyte, :megabytes
|
23
|
+
|
24
|
+
def gigabytes
|
25
|
+
self * GIGABYTE
|
26
|
+
end
|
27
|
+
alias_method :gigabyte, :gigabytes
|
28
|
+
|
29
|
+
def terabytes
|
30
|
+
self * TERABYTE
|
31
|
+
end
|
32
|
+
alias_method :terabyte, :terabytes
|
33
|
+
|
34
|
+
def petabytes
|
35
|
+
self * PETABYTE
|
36
|
+
end
|
37
|
+
alias_method :petabyte, :petabytes
|
38
|
+
|
39
|
+
def exabytes
|
40
|
+
self * EXABYTE
|
41
|
+
end
|
42
|
+
alias_method :exabyte, :exabytes
|
43
|
+
end
|
data/lib/nutella/version.rb
CHANGED
@@ -9,38 +9,38 @@ describe Enumerable do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#exclude?" do
|
12
|
-
it "
|
12
|
+
it "returns true if the collection does not contain the input" do
|
13
13
|
[1, 2, 3].exclude?(4).should be_true
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
16
|
+
it "returns false if the collection contains the input" do
|
17
17
|
[1, 2, 3].exclude?(2).should be_false
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#group" do
|
22
|
-
it "
|
22
|
+
it "groups elements" do
|
23
23
|
[].group(2).should == []
|
24
24
|
[1, 2].group(2).should == [[1, 2]]
|
25
25
|
(1..4).group(2).should == [[1, 2], [3, 4]]
|
26
26
|
(1..9).group(3).should == [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "puts all excess into the last group" do
|
30
30
|
[1, 2].group(4).should == [[1, 2]]
|
31
31
|
(1..8).group(3).should == [[1, 2, 3], [4, 5, 6], [7, 8]]
|
32
32
|
end
|
33
33
|
|
34
|
-
it "
|
34
|
+
it "discards all excess if instructed to" do
|
35
35
|
(1..3).group(2, true).should == [[1, 2]]
|
36
36
|
(1..8).group(3, true).should == [[1, 2, 3], [4, 5, 6]]
|
37
37
|
end
|
38
38
|
|
39
|
-
it "
|
39
|
+
it "does not discard anything if there is no excess" do
|
40
40
|
(1..4).group(2, true).should == [[1, 2], [3, 4]]
|
41
41
|
end
|
42
42
|
|
43
|
-
it "
|
43
|
+
it "does not modify in place" do
|
44
44
|
arr = (1..10).to_a
|
45
45
|
arr.group 2
|
46
46
|
arr.should == (1..10).to_a
|
@@ -50,48 +50,48 @@ describe Enumerable do
|
|
50
50
|
describe "#group!" do
|
51
51
|
let(:arr) { (1..10).to_a }
|
52
52
|
|
53
|
-
it "
|
53
|
+
it "modifies in place" do
|
54
54
|
arr.group! 2
|
55
55
|
arr.should == (1..10).group(2)
|
56
56
|
end
|
57
57
|
|
58
|
-
it "
|
58
|
+
it "returns the modified string" do
|
59
59
|
return_catcher = arr.group! 2
|
60
60
|
return_catcher.should == arr
|
61
61
|
end
|
62
62
|
|
63
|
-
it "
|
63
|
+
it "returns nil if nothing was modified" do
|
64
64
|
return_catcher = [].group! 2
|
65
65
|
return_catcher.should be_nil
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
describe "#sum" do
|
70
|
-
it "
|
70
|
+
it "returns the sum of elements" do
|
71
71
|
[].sum.should == 0
|
72
72
|
[5].sum.should == 5
|
73
73
|
[1, 2, 3].sum.should == 6
|
74
74
|
(1..4).sum.should == 10
|
75
75
|
end
|
76
76
|
|
77
|
-
it "
|
77
|
+
it "flattens the elements before adding" do
|
78
78
|
[[4, 5], 1].sum.should == 10
|
79
79
|
[[1, 2, 3], [4, 5]].sum.should == 15
|
80
80
|
end
|
81
81
|
|
82
|
-
it "
|
82
|
+
it "filters out all non-numbers" do
|
83
83
|
{ a: 2, b: 4 }.sum.should == 6
|
84
84
|
[1, "str", 4].sum.should == 5
|
85
85
|
["no numbers"].sum.should == 0
|
86
86
|
end
|
87
87
|
|
88
88
|
context "with a block" do
|
89
|
-
it "
|
89
|
+
it "returns the sum of the elements that pass the filter block" do
|
90
90
|
(1..10).sum(&:even?).should == 30
|
91
91
|
(1..10).sum { |n| n % 3 == 0 }.should == 18
|
92
92
|
end
|
93
93
|
|
94
|
-
it "
|
94
|
+
it "still filters out all non-numbers" do
|
95
95
|
{ a: 1, b: 2, c: 3 }.sum(&:odd?).should == 4
|
96
96
|
[2, "str", 4, 7].sum(&:even?).should == 6
|
97
97
|
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "nutella/core_ext/file"
|
3
|
+
require "nutella/core_ext/numeric"
|
4
|
+
|
5
|
+
describe File do
|
6
|
+
describe "::human_size" do
|
7
|
+
context "when given a Numeric" do
|
8
|
+
it "does not change bytes" do
|
9
|
+
File.human_size(150.bytes).should == "150 Bytes"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "changes kilobytes" do
|
13
|
+
File.human_size(1.5.kilobytes).should == "1.5 KB"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "changes megabytes" do
|
17
|
+
File.human_size(1.5.megabytes).should == "1.5 MB"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "changes gigabytes" do
|
21
|
+
File.human_size(1.5.gigabytes).should == "1.5 GB"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "rounds down properly to the tenths" do
|
25
|
+
File.human_size(1.72.megabytes).should == "1.7 MB"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "rounds up properly to the tenths" do
|
29
|
+
File.human_size(1.78.megabytes).should == "1.8 MB"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has a singular unit for 1 byte" do
|
33
|
+
File.human_size(1.byte).should == "1 Byte"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns 'Empty' for an empty file or a blank parameter" do
|
37
|
+
File.human_size(0).should == "Empty"
|
38
|
+
File.human_size(nil).should == "Empty"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "displays whole numbers without a decimal" do
|
42
|
+
File.human_size(1.megabyte).should == "1 MB"
|
43
|
+
File.human_size(24.gigabytes).should == "24 GB"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when given a File" do
|
48
|
+
it "detects empty files properly" do
|
49
|
+
begin
|
50
|
+
f = File.new("temp", "w")
|
51
|
+
File.human_size(f).should == "Empty"
|
52
|
+
ensure
|
53
|
+
File.delete "temp"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "detects the file size properly" do
|
58
|
+
begin
|
59
|
+
File.truncate(f = File.new("temp", "w"), 1.5.kilobytes)
|
60
|
+
File.human_size(f).should == "1.5 KB"
|
61
|
+
|
62
|
+
File.truncate(f = File.new("temp", "w"), 3.kilobytes)
|
63
|
+
File.human_size(f).should == "3 KB"
|
64
|
+
ensure
|
65
|
+
File.delete "temp"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when given a String" do
|
71
|
+
it "detects the file size properly" do
|
72
|
+
begin
|
73
|
+
File.truncate(f = File.new("temp", "w"), 1.5.kilobytes)
|
74
|
+
File.human_size("temp").should == "1.5 KB"
|
75
|
+
|
76
|
+
File.truncate(f = File.new("temp", "w"), 3.kilobytes)
|
77
|
+
File.human_size("temp").should == "3 KB"
|
78
|
+
ensure
|
79
|
+
File.delete "temp"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#human_size" do
|
86
|
+
it "detects empty files properly" do
|
87
|
+
begin
|
88
|
+
File.new("temp", "w").human_size.should == "Empty"
|
89
|
+
ensure
|
90
|
+
File.delete "temp"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "detects the file size properly" do
|
95
|
+
begin
|
96
|
+
File.truncate(f = File.new("temp", "w"), 1.5.kilobytes)
|
97
|
+
f.human_size.should == "1.5 KB"
|
98
|
+
|
99
|
+
File.truncate(f = File.new("temp", "w"), 3.kilobytes)
|
100
|
+
f.human_size.should == "3 KB"
|
101
|
+
ensure
|
102
|
+
File.delete "temp"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -10,15 +10,15 @@ describe Hash do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#grab" do
|
13
|
-
it "
|
13
|
+
it "selects the given items from a hash" do
|
14
14
|
hash.slice(:a, :c).should == { a: 1, c: 3 }
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
17
|
+
it "skips items that do not exist in the hash" do
|
18
18
|
hash.slice(:a, :d, :f).should == { a: 1, d: 4 }
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "does not modify in place" do
|
22
22
|
start = hash
|
23
23
|
hash.slice :a, :b
|
24
24
|
hash.should == start
|
@@ -26,16 +26,16 @@ describe Hash do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "#grab!" do
|
29
|
-
it "
|
29
|
+
it "modifies in place" do
|
30
30
|
hash.slice! :a, :c
|
31
31
|
hash.should == { a: 1, c: 3 }
|
32
32
|
end
|
33
33
|
|
34
|
-
it "
|
34
|
+
it "returns the removed pairs" do
|
35
35
|
hash.slice!(:a, :c).should == { b: 2, d: 4 }
|
36
36
|
end
|
37
37
|
|
38
|
-
it "
|
38
|
+
it "ignores pairs that did not affect the hash" do
|
39
39
|
hash.slice!(:a, :c, :g).should == { b: 2, d: 4 }
|
40
40
|
hash.should == { a: 1, c: 3 }
|
41
41
|
end
|
@@ -8,7 +8,7 @@ describe Integer do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "#ordinalize" do
|
11
|
-
it "
|
11
|
+
it "returns the ordinal form of the integer" do
|
12
12
|
NUMBER_FORMATS.each do |cardinal, ordinal|
|
13
13
|
cardinal.ordinalize.should == ordinal
|
14
14
|
end
|
@@ -16,41 +16,41 @@ describe Integer do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#goes_into?" do
|
19
|
-
it "
|
19
|
+
it "returns true if the number goes evenly into the argument" do
|
20
20
|
5.goes_into?(10).should be_true
|
21
21
|
3.goes_into?(21).should be_true
|
22
22
|
25.goes_into?(100).should be_true
|
23
23
|
end
|
24
24
|
|
25
|
-
it "
|
25
|
+
it "returns false if the number does not go evenly in" do
|
26
26
|
3.goes_into?(10).should be_false
|
27
27
|
9.goes_into?(40).should be_false
|
28
28
|
10.goes_into?(5).should be_false
|
29
29
|
end
|
30
30
|
|
31
31
|
context "when passing in zero" do
|
32
|
-
it "
|
32
|
+
it "returns false if one tries to divide by zero" do
|
33
33
|
0.goes_into?(20).should be_false
|
34
34
|
0.goes_into?(30).should be_false
|
35
35
|
end
|
36
36
|
|
37
|
-
it "
|
37
|
+
it "allows zero to go into zero" do
|
38
38
|
0.goes_into?(0).should be_true
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context "with multiple arguments" do
|
43
|
-
it "
|
43
|
+
it "returns true if all arguments succeed" do
|
44
44
|
5.goes_into?(10, 15, 50).should be_true
|
45
45
|
2.goes_into?(2, 4, 10).should be_true
|
46
46
|
end
|
47
47
|
|
48
|
-
it "
|
48
|
+
it "returns false if only some arguments succeed" do
|
49
49
|
5.goes_into?(10, 12, 15).should be_false
|
50
50
|
8.goes_into?(4, 16).should be_false
|
51
51
|
end
|
52
52
|
|
53
|
-
it "
|
53
|
+
it "returns false if no arguments succeed" do
|
54
54
|
3.goes_into?(8, 16, 20).should be_false
|
55
55
|
6.goes_into?(5, 10, 15).should be_false
|
56
56
|
end
|
@@ -58,31 +58,31 @@ describe Integer do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
describe "#goes_into_any?" do
|
61
|
-
it "
|
61
|
+
it "returns true if all arguments succeed" do
|
62
62
|
5.goes_into_any?(10, 15, 50).should be_true
|
63
63
|
2.goes_into_any?(2, 4, 10).should be_true
|
64
64
|
end
|
65
65
|
|
66
|
-
it "
|
66
|
+
it "returns true if only some arguments succeed" do
|
67
67
|
5.goes_into_any?(10, 12, 15).should be_true
|
68
68
|
8.goes_into_any?(4, 16).should be_true
|
69
69
|
end
|
70
70
|
|
71
|
-
it "
|
71
|
+
it "returns false if no arguments succeed" do
|
72
72
|
3.goes_into_any?(8, 16, 20).should be_false
|
73
73
|
6.goes_into_any?(5, 10, 15).should be_false
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
describe "#multiple_of?" do
|
78
|
-
it "
|
78
|
+
it "returns true if the number is evenly divisible" do
|
79
79
|
5.multiple_of?(5).should be_true
|
80
80
|
15.multiple_of?(5).should be_true
|
81
81
|
10.multiple_of?(2).should be_true
|
82
82
|
6000.multiple_of?(6).should be_true
|
83
83
|
end
|
84
84
|
|
85
|
-
it "
|
85
|
+
it "returns false if the number is not evenly divisible" do
|
86
86
|
20.multiple_of?(7).should be_false
|
87
87
|
4.multiple_of?(3).should be_false
|
88
88
|
5.multiple_of?(15).should be_false
|
@@ -90,30 +90,30 @@ describe Integer do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
context "when passing in zero" do
|
93
|
-
it "
|
93
|
+
it "returns false if one tries to divide by zero" do
|
94
94
|
20.multiple_of?(0).should be_false
|
95
95
|
30.multiple_of?(0).should be_false
|
96
96
|
end
|
97
97
|
|
98
|
-
it "
|
98
|
+
it "allows zero to go into zero" do
|
99
99
|
0.multiple_of?(0).should be_true
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
context "with multiple arguments" do
|
104
|
-
it "
|
104
|
+
it "returns true if evenly divisible by all arguments" do
|
105
105
|
15.multiple_of?(3, 15).should be_true
|
106
106
|
100.multiple_of?(2, 5, 25).should be_true
|
107
107
|
0.multiple_of?(0, 1, 2).should be_true
|
108
108
|
end
|
109
109
|
|
110
|
-
it "
|
110
|
+
it "returns false if evenly divisible by only some arguments" do
|
111
111
|
15.multiple_of?(2, 3).should be_false
|
112
112
|
12.multiple_of?(3, 4, 6, 8).should be_false
|
113
113
|
10.multiple_of?(0, 5).should be_false
|
114
114
|
end
|
115
115
|
|
116
|
-
it "
|
116
|
+
it "returns false if evenly divisible by none of the arguments" do
|
117
117
|
6.multiple_of?(4, 5).should be_false
|
118
118
|
17.multiple_of?(2, 4).should be_false
|
119
119
|
end
|
@@ -121,19 +121,19 @@ describe Integer do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
describe "#multiple_of_any?" do
|
124
|
-
it "
|
124
|
+
it "returns true if evenly divisible by all arguments" do
|
125
125
|
15.multiple_of_any?(3, 15).should be_true
|
126
126
|
100.multiple_of_any?(2, 5, 25).should be_true
|
127
127
|
0.multiple_of_any?(0, 1, 2).should be_true
|
128
128
|
end
|
129
129
|
|
130
|
-
it "
|
130
|
+
it "returns true if evenly divisible by only some arguments" do
|
131
131
|
15.multiple_of_any?(2, 3).should be_true
|
132
132
|
12.multiple_of_any?(3, 4, 6, 8).should be_true
|
133
133
|
10.multiple_of_any?(0, 5).should be_true
|
134
134
|
end
|
135
135
|
|
136
|
-
it "
|
136
|
+
it "returns false if evenly divisible by none of the arguments" do
|
137
137
|
6.multiple_of_any?(4, 5).should be_false
|
138
138
|
17.multiple_of_any?(2, 4).should be_false
|
139
139
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "nutella/core_ext/numeric"
|
3
|
+
|
4
|
+
describe Numeric do
|
5
|
+
describe "aliases" do
|
6
|
+
# Test the singular aliases- byte for bytes, kilobyte for kilobytes, etc.
|
7
|
+
([""] + %w[kilo mega giga tera peta exa]).each do |prefix|
|
8
|
+
test_alias Numeric, (name = "#{prefix}byte").to_sym, "#{name}s".to_sym
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -7,43 +7,43 @@ describe Object do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#blank?" do
|
10
|
-
it "
|
10
|
+
it "is blank when nil" do
|
11
11
|
nil.blank?.should be_true
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "is blank when false" do
|
15
15
|
false.blank?.should be_true
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
18
|
+
it "is not blank when true" do
|
19
19
|
true.blank?.should be_false
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
22
|
+
it "is not blank when numeric" do
|
23
23
|
[0, 1].each { |n| n.blank?.should be_false }
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when a string" do
|
27
|
-
it "
|
27
|
+
it "is blank if the string is empty" do
|
28
28
|
"".blank?.should be_true
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
31
|
+
it "is blank if only whitespace" do
|
32
32
|
[" ", "\n \t"].each { |str| str.blank?.should be_true }
|
33
33
|
" something here ".blank?.should be_false
|
34
34
|
end
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "is not blank if the string has content" do
|
37
37
|
"string".blank?.should be_false
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
context "when a collection" do
|
42
|
-
it "
|
42
|
+
it "is blank if the collection is empty" do
|
43
43
|
[[], {}].each { |collection| collection.blank?.should be_true }
|
44
44
|
end
|
45
45
|
|
46
|
-
it "
|
46
|
+
it "is not blank if there are elements in the collection" do
|
47
47
|
[[1, 2, 3], { 1 => 2, 3 => 4 }].each do |collection|
|
48
48
|
collection.blank?.should be_false
|
49
49
|
end
|
@@ -52,7 +52,7 @@ describe Object do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
describe "#present?" do
|
55
|
-
it "
|
55
|
+
it "is the inverse of #blank?" do
|
56
56
|
[0, 1].each { |n| n.present?.should be_true }
|
57
57
|
[[], {}].each { |collection| collection.present?.should be_false }
|
58
58
|
["", " "].each { |str| str.present?.should be_false }
|
@@ -61,12 +61,12 @@ describe Object do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe "#presence" do
|
64
|
-
it "
|
64
|
+
it "returns the object if the object is present" do
|
65
65
|
1.presence.should == 1
|
66
66
|
"str".presence.should == "str"
|
67
67
|
end
|
68
68
|
|
69
|
-
it "
|
69
|
+
it "returns nil if the object is not present" do
|
70
70
|
"".presence.should be_nil
|
71
71
|
false.presence.should be_nil
|
72
72
|
end
|
@@ -14,11 +14,11 @@ describe Enumerable do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#exclude?" do
|
17
|
-
it "
|
17
|
+
it "returns true if the string does not contain the input string" do
|
18
18
|
"hello".exclude?("test").should be_true
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "returns false if the string contains the input string" do
|
22
22
|
"hello".exclude?("llo").should be_false
|
23
23
|
end
|
24
24
|
end
|
@@ -48,7 +48,7 @@ Left-aligned again.
|
|
48
48
|
EOS
|
49
49
|
end
|
50
50
|
|
51
|
-
it "
|
51
|
+
it "strips all excess whitespace from the left" do
|
52
52
|
test.should == expected
|
53
53
|
end
|
54
54
|
end
|
data/spec/support/alias.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Tests if +method_a+ is an alias to +method_b+ in the class +cls+.
|
2
2
|
def test_alias(cls, method_a, method_b)
|
3
3
|
describe "##{method_a.to_s}" do
|
4
|
-
it "
|
4
|
+
it "is an alias of ##{method_b.to_s}" do
|
5
5
|
cls.instance_method(method_a).should === cls.instance_method(method_b)
|
6
6
|
end
|
7
7
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nutella
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.8'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fuubar
|
@@ -116,10 +116,12 @@ files:
|
|
116
116
|
- lib/nutella.rb
|
117
117
|
- lib/nutella/version.rb
|
118
118
|
- lib/nutella/input.rb
|
119
|
+
- lib/nutella/core_ext/numeric.rb
|
119
120
|
- lib/nutella/core_ext/integer/multiples.rb
|
120
121
|
- lib/nutella/core_ext/integer/format.rb
|
121
122
|
- lib/nutella/core_ext/object.rb
|
122
123
|
- lib/nutella/core_ext/string.rb
|
124
|
+
- lib/nutella/core_ext/file.rb
|
123
125
|
- lib/nutella/core_ext/integer.rb
|
124
126
|
- lib/nutella/core_ext/hash.rb
|
125
127
|
- lib/nutella/core_ext/object/blank.rb
|
@@ -130,9 +132,11 @@ files:
|
|
130
132
|
- spec/support/number_formats.rb
|
131
133
|
- spec/nutella/core_ext/object_spec.rb
|
132
134
|
- spec/nutella/core_ext/hash_spec.rb
|
135
|
+
- spec/nutella/core_ext/numeric_spec.rb
|
133
136
|
- spec/nutella/core_ext/enumerable_spec.rb
|
134
137
|
- spec/nutella/core_ext/integer_spec.rb
|
135
138
|
- spec/nutella/core_ext/string_spec.rb
|
139
|
+
- spec/nutella/core_ext/file_spec.rb
|
136
140
|
- spec/spec_helper.rb
|
137
141
|
- .rspec
|
138
142
|
- LICENSE
|
@@ -160,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
164
|
version: '0'
|
161
165
|
segments:
|
162
166
|
- 0
|
163
|
-
hash:
|
167
|
+
hash: 2449410360859195033
|
164
168
|
requirements: []
|
165
169
|
rubyforge_project:
|
166
170
|
rubygems_version: 1.8.24
|
@@ -172,8 +176,10 @@ test_files:
|
|
172
176
|
- spec/support/number_formats.rb
|
173
177
|
- spec/nutella/core_ext/object_spec.rb
|
174
178
|
- spec/nutella/core_ext/hash_spec.rb
|
179
|
+
- spec/nutella/core_ext/numeric_spec.rb
|
175
180
|
- spec/nutella/core_ext/enumerable_spec.rb
|
176
181
|
- spec/nutella/core_ext/integer_spec.rb
|
177
182
|
- spec/nutella/core_ext/string_spec.rb
|
183
|
+
- spec/nutella/core_ext/file_spec.rb
|
178
184
|
- spec/spec_helper.rb
|
179
185
|
has_rdoc:
|