much-boolean 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/much-boolean.rb +2 -2
- data/lib/much-boolean/version.rb +1 -1
- data/test/unit/much-boolean_tests.rb +13 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA512:
|
3
|
-
|
4
|
-
|
3
|
+
data.tar.gz: 588233b63b8c027278fe8091af197d7645793ba12f4d822370c565fc6bc5799007b9daa8a3339a89a58c7cda907689db1a574ad5fa51dcc150f2777c75be8f53
|
4
|
+
metadata.gz: c38027789951f97418399d4c9d6900948a9798398b41a896fbd2953d0545b79c8dd5e08fecb35a35172cca81a9bf7f97c88b5326eb097e60267551c9cdbbea37
|
5
5
|
SHA1:
|
6
|
-
|
7
|
-
|
6
|
+
data.tar.gz: cb6fb44dde93b2c682c5a52404cd19ac49954a56
|
7
|
+
metadata.gz: d4088ebb93b990f874936ccfbf0c01e10b5120e9
|
data/README.md
CHANGED
@@ -13,8 +13,9 @@ MuchBoolean::FALSE_VALUES # => [ 0, "0",
|
|
13
13
|
|
14
14
|
# convert human-friendly representative values to actual booleans
|
15
15
|
|
16
|
-
# nil values - theses are ignored
|
16
|
+
# nil and empty-string values - theses are ignored
|
17
17
|
MuchBoolean.convert(nil) # => nil
|
18
|
+
MuchBoolean.convert('') # => nil
|
18
19
|
|
19
20
|
# zero/one type values
|
20
21
|
MuchBoolean.convert(0) # => false
|
data/lib/much-boolean.rb
CHANGED
@@ -9,7 +9,7 @@ class MuchBoolean
|
|
9
9
|
].freeze
|
10
10
|
|
11
11
|
def self.convert(value)
|
12
|
-
return nil if value.nil
|
12
|
+
return nil if value.to_s.empty? # covers `nil` and `""`
|
13
13
|
!FALSE_VALUES.include?(value)
|
14
14
|
end
|
15
15
|
|
@@ -42,7 +42,7 @@ class MuchBoolean
|
|
42
42
|
|
43
43
|
module Mapping
|
44
44
|
def self.new(boolean_value, true_value, false_value)
|
45
|
-
return nil if boolean_value.nil
|
45
|
+
return nil if boolean_value.to_s.empty? # covers `nil` and `""`
|
46
46
|
return false_value if boolean_value == false
|
47
47
|
true_value
|
48
48
|
end
|
data/lib/much-boolean/version.rb
CHANGED
@@ -21,8 +21,9 @@ class MuchBoolean
|
|
21
21
|
assert_equal exp, subject::FALSE_VALUES
|
22
22
|
end
|
23
23
|
|
24
|
-
should "ignore nil values when converting" do
|
24
|
+
should "ignore nil and empty-string values when converting" do
|
25
25
|
assert_nil MuchBoolean.convert(nil)
|
26
|
+
assert_nil MuchBoolean.convert('')
|
26
27
|
end
|
27
28
|
|
28
29
|
should "convert 'zero-ish' values as `false`" do
|
@@ -71,6 +72,7 @@ class MuchBoolean
|
|
71
72
|
assert_equal 1, MuchBoolean.one_zero(true)
|
72
73
|
assert_equal 0, MuchBoolean.one_zero(false)
|
73
74
|
assert_equal nil, MuchBoolean.one_zero(nil)
|
75
|
+
assert_equal nil, MuchBoolean.one_zero('')
|
74
76
|
assert_equal 1, MuchBoolean.one_zero(Factory.string)
|
75
77
|
|
76
78
|
assert_true MuchBoolean.convert(MuchBoolean.one_zero(true))
|
@@ -81,22 +83,27 @@ class MuchBoolean
|
|
81
83
|
assert_equal 'true', MuchBoolean.true_false(true)
|
82
84
|
assert_equal 'false', MuchBoolean.true_false(false)
|
83
85
|
assert_equal nil, MuchBoolean.true_false(nil)
|
86
|
+
assert_equal nil, MuchBoolean.true_false('')
|
84
87
|
assert_equal 'true', MuchBoolean.true_false(Factory.string)
|
85
88
|
assert_equal 'True', MuchBoolean.True_False(true)
|
86
89
|
assert_equal 'False', MuchBoolean.True_False(false)
|
87
90
|
assert_equal nil, MuchBoolean.True_False(nil)
|
91
|
+
assert_equal nil, MuchBoolean.True_False('')
|
88
92
|
assert_equal 'True', MuchBoolean.True_False(Factory.string)
|
89
93
|
assert_equal 'TRUE', MuchBoolean.TRUE_FALSE(true)
|
90
94
|
assert_equal 'FALSE', MuchBoolean.TRUE_FALSE(false)
|
91
95
|
assert_equal nil, MuchBoolean.TRUE_FALSE(nil)
|
96
|
+
assert_equal nil, MuchBoolean.TRUE_FALSE('')
|
92
97
|
assert_equal 'TRUE', MuchBoolean.TRUE_FALSE(Factory.string)
|
93
98
|
assert_equal 't', MuchBoolean.t_f(true)
|
94
99
|
assert_equal 'f', MuchBoolean.t_f(false)
|
95
100
|
assert_equal nil, MuchBoolean.t_f(nil)
|
101
|
+
assert_equal nil, MuchBoolean.t_f('')
|
96
102
|
assert_equal 't', MuchBoolean.t_f(Factory.string)
|
97
103
|
assert_equal 'T', MuchBoolean.T_F(true)
|
98
104
|
assert_equal 'F', MuchBoolean.T_F(false)
|
99
105
|
assert_equal nil, MuchBoolean.T_F(nil)
|
106
|
+
assert_equal nil, MuchBoolean.T_F('')
|
100
107
|
assert_equal 'T', MuchBoolean.T_F(Factory.string)
|
101
108
|
|
102
109
|
assert_true MuchBoolean.convert(MuchBoolean.true_false(true))
|
@@ -115,22 +122,27 @@ class MuchBoolean
|
|
115
122
|
assert_equal 'yes', MuchBoolean.yes_no(true)
|
116
123
|
assert_equal 'no', MuchBoolean.yes_no(false)
|
117
124
|
assert_equal nil, MuchBoolean.yes_no(nil)
|
125
|
+
assert_equal nil, MuchBoolean.yes_no('')
|
118
126
|
assert_equal 'yes', MuchBoolean.yes_no(Factory.string)
|
119
127
|
assert_equal 'Yes', MuchBoolean.Yes_No(true)
|
120
128
|
assert_equal 'No', MuchBoolean.Yes_No(false)
|
121
129
|
assert_equal nil, MuchBoolean.Yes_No(nil)
|
130
|
+
assert_equal nil, MuchBoolean.Yes_No('')
|
122
131
|
assert_equal 'Yes', MuchBoolean.Yes_No(Factory.string)
|
123
132
|
assert_equal 'YES', MuchBoolean.YES_NO(true)
|
124
133
|
assert_equal 'NO', MuchBoolean.YES_NO(false)
|
125
134
|
assert_equal nil, MuchBoolean.YES_NO(nil)
|
135
|
+
assert_equal nil, MuchBoolean.YES_NO('')
|
126
136
|
assert_equal 'YES', MuchBoolean.YES_NO(Factory.string)
|
127
137
|
assert_equal 'y', MuchBoolean.y_n(true)
|
128
138
|
assert_equal 'n', MuchBoolean.y_n(false)
|
129
139
|
assert_equal nil, MuchBoolean.y_n(nil)
|
140
|
+
assert_equal nil, MuchBoolean.y_n('')
|
130
141
|
assert_equal 'y', MuchBoolean.y_n(Factory.string)
|
131
142
|
assert_equal 'Y', MuchBoolean.Y_N(true)
|
132
143
|
assert_equal 'N', MuchBoolean.Y_N(false)
|
133
144
|
assert_equal nil, MuchBoolean.Y_N(nil)
|
145
|
+
assert_equal nil, MuchBoolean.Y_N('')
|
134
146
|
assert_equal 'Y', MuchBoolean.Y_N(Factory.string)
|
135
147
|
|
136
148
|
assert_true MuchBoolean.convert(MuchBoolean.yes_no(true))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-boolean
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2016-02-
|
13
|
+
date: 2016-02-11 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|