much-boolean 0.1.3 → 0.2.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 +7 -7
- data/Gemfile +3 -1
- data/README.md +90 -47
- data/lib/much-boolean.rb +94 -21
- data/lib/much-boolean/version.rb +3 -1
- data/log/{.gitkeep → .keep} +0 -0
- data/much-boolean.gemspec +5 -6
- data/test/helper.rb +2 -2
- data/test/support/factory.rb +1 -2
- data/test/system/.keep +0 -0
- data/test/unit/much-boolean_tests.rb +216 -124
- metadata +41 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d1fc3165719932c28dd78776ec526e4f0f0b72b61f987271396003e2e17a4354
|
4
|
+
data.tar.gz: 190c8c50385772aa25101e0a2a2e04948d56ae9df8056a3c57f1e74dc4b99fb2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5596cac8da12906767898be162b6dae6f03f64f63e72c882907b03a4819f04241596d299ae6485c01595d87362852621d93f2bedd985e6e41b54a4cfa863aca
|
7
|
+
data.tar.gz: ace459e19aeebf53ad35c5a69f13c6d07cf1d6b56c2dc47c9ff011909239d0f337d61cbbe9a36670e0f3f7259ad0bc783c93a27c703fc2da2f17eab7dc38dfa0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -5,88 +5,131 @@ An API for friendly boolean conversion, interpretation and handling
|
|
5
5
|
## Usage
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
require
|
8
|
+
require "much-boolean"
|
9
9
|
MuchBoolean::FALSE_VALUES # => [ 0, "0",
|
10
10
|
# false, "false", "False", "FALSE", "f", "F",
|
11
11
|
# "no", "No", "NO", "n", "N"
|
12
12
|
# ]
|
13
13
|
|
14
|
+
|
14
15
|
# convert human-friendly representative values to actual booleans
|
15
16
|
|
16
|
-
# nil and empty-string values
|
17
|
-
MuchBoolean.convert(nil) # =>
|
18
|
-
MuchBoolean.convert(
|
17
|
+
# nil and empty-string values
|
18
|
+
MuchBoolean.convert(nil) # => false
|
19
|
+
MuchBoolean.convert("") # => false
|
20
|
+
MuchBoolean.convert(:"") # => false
|
19
21
|
|
20
22
|
# zero/one type values
|
21
|
-
MuchBoolean.convert(0)
|
22
|
-
MuchBoolean.convert(
|
23
|
-
MuchBoolean.convert(
|
24
|
-
MuchBoolean.convert(
|
23
|
+
MuchBoolean.convert(0) # => false
|
24
|
+
MuchBoolean.convert("0") # => false
|
25
|
+
MuchBoolean.convert(:"0") # => false
|
26
|
+
MuchBoolean.convert(1) # => true
|
27
|
+
MuchBoolean.convert("1") # => true
|
28
|
+
MuchBoolean.convert(:"1") # => true
|
25
29
|
|
26
30
|
# true/false type values
|
27
31
|
MuchBoolean.convert(false) # => false
|
32
|
+
MuchBoolean.convert("f") # => false
|
33
|
+
MuchBoolean.convert(:f) # => false
|
34
|
+
MuchBoolean.convert("F") # => false
|
35
|
+
MuchBoolean.convert(:F) # => false
|
28
36
|
MuchBoolean.convert("false") # => false
|
37
|
+
MuchBoolean.convert(:false) # => false
|
29
38
|
MuchBoolean.convert("False") # => false
|
39
|
+
MuchBoolean.convert(:False) # => false
|
30
40
|
MuchBoolean.convert("FALSE") # => false
|
31
|
-
MuchBoolean.convert(
|
32
|
-
MuchBoolean.convert("F") # => false
|
41
|
+
MuchBoolean.convert(:FALSE) # => false
|
33
42
|
MuchBoolean.convert(true) # => true
|
43
|
+
MuchBoolean.convert("t") # => true
|
44
|
+
MuchBoolean.convert(:t) # => true
|
45
|
+
MuchBoolean.convert("T") # => true
|
46
|
+
MuchBoolean.convert(:T) # => true
|
34
47
|
MuchBoolean.convert("true") # => true
|
48
|
+
MuchBoolean.convert(:true) # => true
|
35
49
|
MuchBoolean.convert("True") # => true
|
50
|
+
MuchBoolean.convert(:True) # => true
|
36
51
|
MuchBoolean.convert("TRUE") # => true
|
37
|
-
MuchBoolean.convert(
|
38
|
-
|
52
|
+
MuchBoolean.convert(:TRUE) # => true
|
53
|
+
|
54
|
+
# on/off type values
|
55
|
+
MuchBoolean.convert("off") # => false
|
56
|
+
MuchBoolean.convert(:off) # => false
|
57
|
+
MuchBoolean.convert("Off") # => false
|
58
|
+
MuchBoolean.convert(:Off) # => false
|
59
|
+
MuchBoolean.convert("OFF") # => false
|
60
|
+
MuchBoolean.convert(:OFF) # => false
|
61
|
+
MuchBoolean.convert("on") # => true
|
62
|
+
MuchBoolean.convert(:on) # => true
|
63
|
+
MuchBoolean.convert("On") # => true
|
64
|
+
MuchBoolean.convert(:On) # => true
|
65
|
+
MuchBoolean.convert("ON") # => true
|
66
|
+
MuchBoolean.convert(:ON) # => true
|
39
67
|
|
40
68
|
# yes/no type values
|
69
|
+
MuchBoolean.convert("n") # => false
|
70
|
+
MuchBoolean.convert(:n) # => false
|
71
|
+
MuchBoolean.convert("N") # => false
|
72
|
+
MuchBoolean.convert(:N) # => false
|
41
73
|
MuchBoolean.convert("no") # => false
|
74
|
+
MuchBoolean.convert(:no) # => false
|
42
75
|
MuchBoolean.convert("No") # => false
|
76
|
+
MuchBoolean.convert(:No) # => false
|
43
77
|
MuchBoolean.convert("NO") # => false
|
44
|
-
MuchBoolean.convert(
|
45
|
-
MuchBoolean.convert("
|
78
|
+
MuchBoolean.convert(:NO) # => false
|
79
|
+
MuchBoolean.convert("y") # => true
|
80
|
+
MuchBoolean.convert(:y) # => true
|
81
|
+
MuchBoolean.convert("Y") # => true
|
82
|
+
MuchBoolean.convert(:Y) # => true
|
46
83
|
MuchBoolean.convert("yes") # => true
|
84
|
+
MuchBoolean.convert(:yes) # => true
|
47
85
|
MuchBoolean.convert("Yes") # => true
|
86
|
+
MuchBoolean.convert(:Yes) # => true
|
48
87
|
MuchBoolean.convert("YES") # => true
|
49
|
-
MuchBoolean.convert(
|
50
|
-
MuchBoolean.convert("Y") # => true
|
88
|
+
MuchBoolean.convert(:YES) # => true
|
51
89
|
|
52
90
|
# all other values always interpreted as `true`
|
53
|
-
MuchBoolean.convert(
|
54
|
-
MuchBoolean.convert(
|
55
|
-
MuchBoolean.convert(
|
91
|
+
MuchBoolean.convert("some-string") # => true
|
92
|
+
MuchBoolean.convert(1938) # => true
|
93
|
+
MuchBoolean.convert(1938.5) # => true
|
56
94
|
MuchBoolean.convert(Date.today) # => true
|
57
95
|
MuchBoolean.convert(Time.now) # => true
|
58
96
|
|
59
97
|
|
60
|
-
|
61
98
|
# convert actual booleans back to human-friendly representative values
|
62
99
|
|
63
100
|
MuchBoolean.one_zero(true) # => 1
|
64
101
|
MuchBoolean.one_zero(false) # => 0
|
65
|
-
MuchBoolean.one_zero(true).to_s # =>
|
66
|
-
MuchBoolean.one_zero(false).to_s # =>
|
67
|
-
|
68
|
-
MuchBoolean.
|
69
|
-
MuchBoolean.
|
70
|
-
MuchBoolean.
|
71
|
-
MuchBoolean.
|
72
|
-
MuchBoolean.
|
73
|
-
MuchBoolean.
|
74
|
-
MuchBoolean.
|
75
|
-
MuchBoolean.
|
76
|
-
MuchBoolean.
|
77
|
-
MuchBoolean.
|
78
|
-
|
79
|
-
MuchBoolean.
|
80
|
-
MuchBoolean.
|
81
|
-
MuchBoolean.
|
82
|
-
MuchBoolean.
|
83
|
-
MuchBoolean.
|
84
|
-
MuchBoolean.
|
85
|
-
|
86
|
-
MuchBoolean.y_n(
|
87
|
-
MuchBoolean.
|
88
|
-
MuchBoolean.Y_N(
|
89
|
-
|
102
|
+
MuchBoolean.one_zero(true).to_s # => "1"
|
103
|
+
MuchBoolean.one_zero(false).to_s # => "0"
|
104
|
+
|
105
|
+
MuchBoolean.t_f(true) # => "t"
|
106
|
+
MuchBoolean.t_f(false) # => "f"
|
107
|
+
MuchBoolean.T_F(true) # => "T"
|
108
|
+
MuchBoolean.T_F(false) # => "F"
|
109
|
+
MuchBoolean.true_false(true) # => "true"
|
110
|
+
MuchBoolean.true_false(false) # => "false"
|
111
|
+
MuchBoolean.True_False(true) # => "True"
|
112
|
+
MuchBoolean.True_False(false) # => "False"
|
113
|
+
MuchBoolean.TRUE_FALSE(true) # => "TRUE"
|
114
|
+
MuchBoolean.TRUE_FALSE(false) # => "FALSE"
|
115
|
+
|
116
|
+
MuchBoolean.on_off(true) # => "on"
|
117
|
+
MuchBoolean.on_off(false) # => "off"
|
118
|
+
MuchBoolean.On_Off(true) # => "On"
|
119
|
+
MuchBoolean.On_Off(false) # => "Off"
|
120
|
+
MuchBoolean.ON_OFF(true) # => "ON"
|
121
|
+
MuchBoolean.ON_OFF(false) # => "OFF"
|
122
|
+
|
123
|
+
MuchBoolean.y_n(true) # => "y"
|
124
|
+
MuchBoolean.y_n(false) # => "n"
|
125
|
+
MuchBoolean.Y_N(true) # => "Y"
|
126
|
+
MuchBoolean.Y_N(false) # => "N"
|
127
|
+
MuchBoolean.yes_no(true) # => "yes"
|
128
|
+
MuchBoolean.yes_no(false) # => "no"
|
129
|
+
MuchBoolean.Yes_No(true) # => "Yes"
|
130
|
+
MuchBoolean.Yes_No(false) # => "No"
|
131
|
+
MuchBoolean.YES_NO(true) # => "YES"
|
132
|
+
MuchBoolean.YES_NO(false) # => "NO"
|
90
133
|
|
91
134
|
|
92
135
|
# create instances to track given human-friendly values and the boolean values they map to
|
@@ -103,7 +146,7 @@ MuchBoolean::FALSE_VALUES.each do |val|
|
|
103
146
|
bool == true # => false
|
104
147
|
end
|
105
148
|
|
106
|
-
[
|
149
|
+
["some-string", 1938, 1938.5, Date.today, Time.now].each do |val|
|
107
150
|
bool = MuchBoolean.new(val)
|
108
151
|
bool.given # => {val}
|
109
152
|
bool.actual # => true
|
@@ -116,7 +159,7 @@ end
|
|
116
159
|
|
117
160
|
Add this line to your application's Gemfile:
|
118
161
|
|
119
|
-
gem
|
162
|
+
gem "much-boolean"
|
120
163
|
|
121
164
|
And then execute:
|
122
165
|
|
data/lib/much-boolean.rb
CHANGED
@@ -1,29 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "much-boolean/version"
|
2
4
|
|
3
5
|
class MuchBoolean
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
FALSE_VALUES =
|
7
|
+
[
|
8
|
+
nil,
|
9
|
+
"",
|
10
|
+
:"",
|
11
|
+
0,
|
12
|
+
"0",
|
13
|
+
:"0",
|
14
|
+
false,
|
15
|
+
"f",
|
16
|
+
:f,
|
17
|
+
"F",
|
18
|
+
:F,
|
19
|
+
"false",
|
20
|
+
:false,
|
21
|
+
"False",
|
22
|
+
:False,
|
23
|
+
"FALSE",
|
24
|
+
:FALSE,
|
25
|
+
"off",
|
26
|
+
:off,
|
27
|
+
"Off",
|
28
|
+
:Off,
|
29
|
+
"OFF",
|
30
|
+
:OFF,
|
31
|
+
"n",
|
32
|
+
:n,
|
33
|
+
"N",
|
34
|
+
:N,
|
35
|
+
"no",
|
36
|
+
:no,
|
37
|
+
"No",
|
38
|
+
:No,
|
39
|
+
"NO",
|
40
|
+
:NO,
|
41
|
+
].freeze
|
10
42
|
|
11
43
|
def self.convert(value)
|
12
|
-
return nil if value.to_s.empty? # covers `nil` and `""`
|
13
44
|
!FALSE_VALUES.include?(value)
|
14
45
|
end
|
15
46
|
|
16
|
-
def self.one_zero(boolean)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def self.t_f(boolean)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def self.
|
25
|
-
|
26
|
-
|
47
|
+
def self.one_zero(boolean)
|
48
|
+
Mapping.new(boolean, 1, 0)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.t_f(boolean)
|
52
|
+
Mapping.new(boolean, "t", "f")
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.T_F(boolean)
|
56
|
+
Mapping.new(boolean, "T", "F")
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.true_false(boolean)
|
60
|
+
Mapping.new(boolean, "true", "false")
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.True_False(boolean)
|
64
|
+
Mapping.new(boolean, "True", "False")
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.TRUE_FALSE(boolean)
|
68
|
+
Mapping.new(boolean, "TRUE", "FALSE")
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.on_off(boolean)
|
72
|
+
Mapping.new(boolean, "on", "off")
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.On_Off(boolean)
|
76
|
+
Mapping.new(boolean, "On", "Off")
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.ON_OFF(boolean)
|
80
|
+
Mapping.new(boolean, "ON", "OFF")
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.y_n(boolean)
|
84
|
+
Mapping.new(boolean, "y", "n")
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.Y_N(boolean)
|
88
|
+
Mapping.new(boolean, "Y", "N")
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.yes_no(boolean)
|
92
|
+
Mapping.new(boolean, "yes", "no")
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.Yes_No(boolean)
|
96
|
+
Mapping.new(boolean, "Yes", "No")
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.YES_NO(boolean)
|
100
|
+
Mapping.new(boolean, "YES", "NO")
|
101
|
+
end
|
27
102
|
|
28
103
|
attr_reader :given, :actual
|
29
104
|
|
@@ -42,10 +117,8 @@ class MuchBoolean
|
|
42
117
|
|
43
118
|
module Mapping
|
44
119
|
def self.new(boolean_value, true_value, false_value)
|
45
|
-
return
|
46
|
-
return false_value if boolean_value == false
|
120
|
+
return false_value if MuchBoolean.convert(boolean_value) == false
|
47
121
|
true_value
|
48
122
|
end
|
49
123
|
end
|
50
|
-
|
51
124
|
end
|
data/lib/much-boolean/version.rb
CHANGED
data/log/{.gitkeep → .keep}
RENAMED
File without changes
|
data/much-boolean.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require "much-boolean/version"
|
5
5
|
|
@@ -8,16 +8,15 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = MuchBoolean::VERSION
|
9
9
|
gem.authors = ["Kelly Redding", "Collin Redding"]
|
10
10
|
gem.email = ["kelly@kellyredding.com", "collin.redding@me.com "]
|
11
|
-
gem.summary = "An API for friendly boolean conversion, interpretation and handling"
|
12
|
-
gem.description = "An API for friendly boolean conversion, interpretation and handling"
|
11
|
+
gem.summary = "An API for friendly boolean conversion, interpretation, and handling."
|
12
|
+
gem.description = "An API for friendly boolean conversion, interpretation, and handling."
|
13
13
|
gem.homepage = "https://github.com/redding/much-boolean"
|
14
|
-
gem.license =
|
14
|
+
gem.license = "MIT"
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($/)
|
17
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_development_dependency("assert", ["~> 2.
|
22
|
-
|
21
|
+
gem.add_development_dependency("assert", ["~> 2.19.0"])
|
23
22
|
end
|
data/test/helper.rb
CHANGED
data/test/support/factory.rb
CHANGED
data/test/system/.keep
ADDED
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert"
|
2
|
+
require "much-boolean"
|
3
3
|
|
4
4
|
class MuchBoolean
|
5
5
|
|
@@ -9,192 +9,284 @@ class MuchBoolean
|
|
9
9
|
|
10
10
|
should have_imeths :convert
|
11
11
|
should have_imeths :one_zero
|
12
|
-
should have_imeths :
|
13
|
-
should have_imeths :
|
12
|
+
should have_imeths :t_f, :T_F, :true_false, :True_False, :TRUE_FALSE
|
13
|
+
should have_imeths :on_off, :On_Off, :ON_OFF
|
14
|
+
should have_imeths :y_n, :Y_N, :yes_no, :Yes_No, :YES_NO
|
14
15
|
|
15
16
|
should "know its false values" do
|
16
|
-
exp =
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
exp =
|
18
|
+
[
|
19
|
+
nil,
|
20
|
+
"",
|
21
|
+
:"",
|
22
|
+
0,
|
23
|
+
"0",
|
24
|
+
:"0",
|
25
|
+
false,
|
26
|
+
"f",
|
27
|
+
:f,
|
28
|
+
"F",
|
29
|
+
:F,
|
30
|
+
"false",
|
31
|
+
:false,
|
32
|
+
"False",
|
33
|
+
:False,
|
34
|
+
"FALSE",
|
35
|
+
:FALSE,
|
36
|
+
"off",
|
37
|
+
:off,
|
38
|
+
"Off",
|
39
|
+
:Off,
|
40
|
+
"OFF",
|
41
|
+
:OFF,
|
42
|
+
"n",
|
43
|
+
:n,
|
44
|
+
"N",
|
45
|
+
:N,
|
46
|
+
"no",
|
47
|
+
:no,
|
48
|
+
"No",
|
49
|
+
:No,
|
50
|
+
"NO",
|
51
|
+
:NO,
|
52
|
+
]
|
21
53
|
assert_equal exp, subject::FALSE_VALUES
|
22
54
|
end
|
23
55
|
|
24
|
-
should "
|
25
|
-
|
26
|
-
|
56
|
+
should "convert nil and empty-string values as `false`" do
|
57
|
+
[nil, "", :""].each do |val|
|
58
|
+
assert_that(MuchBoolean.convert(val)).is_false
|
59
|
+
end
|
27
60
|
end
|
28
61
|
|
29
|
-
should "convert
|
30
|
-
[0,
|
31
|
-
|
62
|
+
should "convert zero-ish values as `false`" do
|
63
|
+
[0, "0", :"0"].each do |val|
|
64
|
+
assert_that(MuchBoolean.convert(val)).is_false
|
32
65
|
end
|
33
66
|
end
|
34
67
|
|
35
|
-
should "convert
|
36
|
-
[
|
37
|
-
|
68
|
+
should "convert false-ish values as `false`" do
|
69
|
+
[
|
70
|
+
false,
|
71
|
+
"f",
|
72
|
+
:f,
|
73
|
+
"F",
|
74
|
+
:F,
|
75
|
+
"false",
|
76
|
+
:false,
|
77
|
+
"False",
|
78
|
+
:False,
|
79
|
+
"FALSE",
|
80
|
+
:FALSE,
|
81
|
+
].each do |val|
|
82
|
+
assert_that(MuchBoolean.convert(val)).is_false
|
38
83
|
end
|
39
84
|
end
|
40
85
|
|
41
|
-
should "convert
|
42
|
-
[
|
43
|
-
|
86
|
+
should "convert off-ish values as `false`" do
|
87
|
+
["off", :off, "Off", :Off, "OFF", :OFF].each do |val|
|
88
|
+
assert_that(MuchBoolean.convert(val)).is_false
|
44
89
|
end
|
45
90
|
end
|
46
91
|
|
47
|
-
should "convert
|
48
|
-
[
|
49
|
-
|
92
|
+
should "convert no-ish values as `false`" do
|
93
|
+
["n", :n, "N", :N, "no", :no, "No", :No, "NO", :NO].each do |val|
|
94
|
+
assert_that(MuchBoolean.convert(val)).is_false
|
50
95
|
end
|
51
96
|
end
|
52
97
|
|
53
|
-
should "convert
|
54
|
-
[
|
55
|
-
|
98
|
+
should "convert one-ish values as `true`" do
|
99
|
+
[1, "1", :"1"].each do |val|
|
100
|
+
assert_that(MuchBoolean.convert(val)).is_true
|
56
101
|
end
|
57
102
|
end
|
58
103
|
|
59
|
-
should "convert
|
60
|
-
[
|
61
|
-
|
104
|
+
should "convert true-ish values as `true`" do
|
105
|
+
[
|
106
|
+
true,
|
107
|
+
"t",
|
108
|
+
:t,
|
109
|
+
"T",
|
110
|
+
:T,
|
111
|
+
"true",
|
112
|
+
:true,
|
113
|
+
"True",
|
114
|
+
:True,
|
115
|
+
"TRUE",
|
116
|
+
:TRUE,
|
117
|
+
].each do |val|
|
118
|
+
assert_that(MuchBoolean.convert(val)).is_true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
should "convert on-ish values as `false`" do
|
123
|
+
["on", :on, "On", :On, "ON", :ON].each do |val|
|
124
|
+
assert_that(MuchBoolean.convert(val)).is_true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
should "convert yes-ish values as `true`" do
|
129
|
+
["y", :y, "Y", :Y, "yes", :yes, "Yes", :Yes, "YES", :YES].each do |val|
|
130
|
+
assert_that(MuchBoolean.convert(val)).is_true
|
62
131
|
end
|
63
132
|
end
|
64
133
|
|
65
134
|
should "convert all other values as `true`" do
|
66
135
|
[Factory.string, Factory.integer, Factory.date, Factory.time].each do |val|
|
67
|
-
|
136
|
+
assert_that(MuchBoolean.convert(val)).is_true
|
68
137
|
end
|
69
138
|
end
|
70
139
|
|
71
140
|
should "encode booleans as ones and zeros" do
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
141
|
+
assert_that(MuchBoolean.one_zero(true)).equals(1)
|
142
|
+
assert_that(MuchBoolean.one_zero(false)).equals(0)
|
143
|
+
assert_that(MuchBoolean.one_zero(nil)).equals(0)
|
144
|
+
assert_that(MuchBoolean.one_zero("")).equals(0)
|
145
|
+
assert_that(MuchBoolean.one_zero(Factory.string)).equals(1)
|
77
146
|
|
78
|
-
|
79
|
-
|
147
|
+
assert_that(MuchBoolean.convert(MuchBoolean.one_zero(true))).is_true
|
148
|
+
assert_that(MuchBoolean.convert(MuchBoolean.one_zero(false))).is_false
|
80
149
|
end
|
81
150
|
|
82
151
|
should "encode booleans as true/false strings" do
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
152
|
+
assert_that(MuchBoolean.t_f(true)).equals("t")
|
153
|
+
assert_that(MuchBoolean.t_f(false)).equals("f")
|
154
|
+
assert_that(MuchBoolean.t_f(nil)).equals("f")
|
155
|
+
assert_that(MuchBoolean.t_f("")).equals("f")
|
156
|
+
assert_that(MuchBoolean.t_f(Factory.string)).equals("t")
|
157
|
+
assert_that(MuchBoolean.T_F(true)).equals("T")
|
158
|
+
assert_that(MuchBoolean.T_F(false)).equals("F")
|
159
|
+
assert_that(MuchBoolean.T_F(nil)).equals("F")
|
160
|
+
assert_that(MuchBoolean.T_F("")).equals("F")
|
161
|
+
assert_that(MuchBoolean.T_F(Factory.string)).equals("T")
|
162
|
+
assert_that(MuchBoolean.true_false(true)).equals("true")
|
163
|
+
assert_that(MuchBoolean.true_false(false)).equals("false")
|
164
|
+
assert_that(MuchBoolean.true_false(nil)).equals("false")
|
165
|
+
assert_that(MuchBoolean.true_false("")).equals("false")
|
166
|
+
assert_that(MuchBoolean.true_false(Factory.string)).equals("true")
|
167
|
+
assert_that(MuchBoolean.True_False(true)).equals("True")
|
168
|
+
assert_that(MuchBoolean.True_False(false)).equals("False")
|
169
|
+
assert_that(MuchBoolean.True_False(nil)).equals("False")
|
170
|
+
assert_that(MuchBoolean.True_False("")).equals("False")
|
171
|
+
assert_that(MuchBoolean.True_False(Factory.string)).equals("True")
|
172
|
+
assert_that(MuchBoolean.TRUE_FALSE(true)).equals("TRUE")
|
173
|
+
assert_that(MuchBoolean.TRUE_FALSE(false)).equals("FALSE")
|
174
|
+
assert_that(MuchBoolean.TRUE_FALSE(nil)).equals("FALSE")
|
175
|
+
assert_that(MuchBoolean.TRUE_FALSE("")).equals("FALSE")
|
176
|
+
assert_that(MuchBoolean.TRUE_FALSE(Factory.string)).equals("TRUE")
|
177
|
+
|
178
|
+
assert_that(MuchBoolean.convert(MuchBoolean.t_f(true))).is_true
|
179
|
+
assert_that(MuchBoolean.convert(MuchBoolean.t_f(false))).is_false
|
180
|
+
assert_that(MuchBoolean.convert(MuchBoolean.T_F(true))).is_true
|
181
|
+
assert_that(MuchBoolean.convert(MuchBoolean.T_F(false))).is_false
|
182
|
+
assert_that(MuchBoolean.convert(MuchBoolean.true_false(true))).is_true
|
183
|
+
assert_that(MuchBoolean.convert(MuchBoolean.true_false(false))).is_false
|
184
|
+
assert_that(MuchBoolean.convert(MuchBoolean.True_False(true))).is_true
|
185
|
+
assert_that(MuchBoolean.convert(MuchBoolean.True_False(false))).is_false
|
186
|
+
assert_that(MuchBoolean.convert(MuchBoolean.TRUE_FALSE(true))).is_true
|
187
|
+
assert_that(MuchBoolean.convert(MuchBoolean.TRUE_FALSE(false))).is_false
|
119
188
|
end
|
120
189
|
|
121
|
-
should "encode booleans as
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
assert_equal nil, MuchBoolean.Y_N(nil)
|
145
|
-
assert_equal nil, MuchBoolean.Y_N('')
|
146
|
-
assert_equal 'Y', MuchBoolean.Y_N(Factory.string)
|
147
|
-
|
148
|
-
assert_true MuchBoolean.convert(MuchBoolean.yes_no(true))
|
149
|
-
assert_false MuchBoolean.convert(MuchBoolean.yes_no(false))
|
150
|
-
assert_true MuchBoolean.convert(MuchBoolean.Yes_No(true))
|
151
|
-
assert_false MuchBoolean.convert(MuchBoolean.Yes_No(false))
|
152
|
-
assert_true MuchBoolean.convert(MuchBoolean.YES_NO(true))
|
153
|
-
assert_false MuchBoolean.convert(MuchBoolean.YES_NO(false))
|
154
|
-
assert_true MuchBoolean.convert(MuchBoolean.y_n(true))
|
155
|
-
assert_false MuchBoolean.convert(MuchBoolean.y_n(false))
|
156
|
-
assert_true MuchBoolean.convert(MuchBoolean.Y_N(true))
|
157
|
-
assert_false MuchBoolean.convert(MuchBoolean.Y_N(false))
|
190
|
+
should "encode booleans as on/off strings" do
|
191
|
+
assert_that(MuchBoolean.on_off(true)).equals("on")
|
192
|
+
assert_that(MuchBoolean.on_off(false)).equals("off")
|
193
|
+
assert_that(MuchBoolean.on_off(nil)).equals("off")
|
194
|
+
assert_that(MuchBoolean.on_off("")).equals("off")
|
195
|
+
assert_that(MuchBoolean.on_off(Factory.string)).equals("on")
|
196
|
+
assert_that(MuchBoolean.On_Off(true)).equals("On")
|
197
|
+
assert_that(MuchBoolean.On_Off(false)).equals("Off")
|
198
|
+
assert_that(MuchBoolean.On_Off(nil)).equals("Off")
|
199
|
+
assert_that(MuchBoolean.On_Off("")).equals("Off")
|
200
|
+
assert_that(MuchBoolean.On_Off(Factory.string)).equals("On")
|
201
|
+
assert_that(MuchBoolean.ON_OFF(true)).equals("ON")
|
202
|
+
assert_that(MuchBoolean.ON_OFF(false)).equals("OFF")
|
203
|
+
assert_that(MuchBoolean.ON_OFF(nil)).equals("OFF")
|
204
|
+
assert_that(MuchBoolean.ON_OFF("")).equals("OFF")
|
205
|
+
assert_that(MuchBoolean.ON_OFF(Factory.string)).equals("ON")
|
206
|
+
|
207
|
+
assert_that(MuchBoolean.convert(MuchBoolean.on_off(true))).is_true
|
208
|
+
assert_that(MuchBoolean.convert(MuchBoolean.on_off(false))).is_false
|
209
|
+
assert_that(MuchBoolean.convert(MuchBoolean.On_Off(true))).is_true
|
210
|
+
assert_that(MuchBoolean.convert(MuchBoolean.On_Off(false))).is_false
|
211
|
+
assert_that(MuchBoolean.convert(MuchBoolean.ON_OFF(true))).is_true
|
212
|
+
assert_that(MuchBoolean.convert(MuchBoolean.ON_OFF(false))).is_false
|
158
213
|
end
|
159
214
|
|
215
|
+
should "encode booleans as yes/no strings" do
|
216
|
+
assert_that(MuchBoolean.y_n(true)).equals("y")
|
217
|
+
assert_that(MuchBoolean.y_n(false)).equals("n")
|
218
|
+
assert_that(MuchBoolean.y_n(nil)).equals("n")
|
219
|
+
assert_that(MuchBoolean.y_n("")).equals("n")
|
220
|
+
assert_that(MuchBoolean.y_n(Factory.string)).equals("y")
|
221
|
+
assert_that(MuchBoolean.Y_N(true)).equals("Y")
|
222
|
+
assert_that(MuchBoolean.Y_N(false)).equals("N")
|
223
|
+
assert_that(MuchBoolean.Y_N(nil)).equals("N")
|
224
|
+
assert_that(MuchBoolean.Y_N("")).equals("N")
|
225
|
+
assert_that(MuchBoolean.Y_N(Factory.string)).equals("Y")
|
226
|
+
assert_that(MuchBoolean.yes_no(true)).equals("yes")
|
227
|
+
assert_that(MuchBoolean.yes_no(false)).equals("no")
|
228
|
+
assert_that(MuchBoolean.yes_no(nil)).equals("no")
|
229
|
+
assert_that(MuchBoolean.yes_no("")).equals("no")
|
230
|
+
assert_that(MuchBoolean.yes_no(Factory.string)).equals("yes")
|
231
|
+
assert_that(MuchBoolean.Yes_No(true)).equals("Yes")
|
232
|
+
assert_that(MuchBoolean.Yes_No(false)).equals("No")
|
233
|
+
assert_that(MuchBoolean.Yes_No(nil)).equals("No")
|
234
|
+
assert_that(MuchBoolean.Yes_No("")).equals("No")
|
235
|
+
assert_that(MuchBoolean.Yes_No(Factory.string)).equals("Yes")
|
236
|
+
assert_that(MuchBoolean.YES_NO(true)).equals("YES")
|
237
|
+
assert_that(MuchBoolean.YES_NO(false)).equals("NO")
|
238
|
+
assert_that(MuchBoolean.YES_NO(nil)).equals("NO")
|
239
|
+
assert_that(MuchBoolean.YES_NO("")).equals("NO")
|
240
|
+
assert_that(MuchBoolean.YES_NO(Factory.string)).equals("YES")
|
241
|
+
|
242
|
+
assert_that(MuchBoolean.convert(MuchBoolean.y_n(true))).is_true
|
243
|
+
assert_that(MuchBoolean.convert(MuchBoolean.y_n(false))).is_false
|
244
|
+
assert_that(MuchBoolean.convert(MuchBoolean.Y_N(true))).is_true
|
245
|
+
assert_that(MuchBoolean.convert(MuchBoolean.Y_N(false))).is_false
|
246
|
+
assert_that(MuchBoolean.convert(MuchBoolean.yes_no(true))).is_true
|
247
|
+
assert_that(MuchBoolean.convert(MuchBoolean.yes_no(false))).is_false
|
248
|
+
assert_that(MuchBoolean.convert(MuchBoolean.Yes_No(true))).is_true
|
249
|
+
assert_that(MuchBoolean.convert(MuchBoolean.Yes_No(false))).is_false
|
250
|
+
assert_that(MuchBoolean.convert(MuchBoolean.YES_NO(true))).is_true
|
251
|
+
assert_that(MuchBoolean.convert(MuchBoolean.YES_NO(false))).is_false
|
252
|
+
end
|
160
253
|
end
|
161
254
|
|
162
255
|
class InitTests < UnitTests
|
163
256
|
desc "when init"
|
257
|
+
subject{ @bool }
|
258
|
+
|
164
259
|
setup do
|
165
260
|
@actual = Factory.boolean
|
166
261
|
@bool = MuchBoolean.new(@actual)
|
167
262
|
end
|
168
|
-
subject{ @bool }
|
169
263
|
|
170
264
|
should have_reader :given, :actual
|
171
265
|
|
172
266
|
should "know its given and actual boolean values" do
|
173
|
-
|
174
|
-
|
267
|
+
assert_that(subject.given).equals(@actual)
|
268
|
+
assert_that(subject.actual).equals(@actual)
|
175
269
|
|
176
270
|
str = Factory.string
|
177
271
|
bool = MuchBoolean.new(str)
|
178
|
-
|
179
|
-
|
272
|
+
assert_that(bool.given).equals(str)
|
273
|
+
assert_that(bool.actual).is_true
|
180
274
|
end
|
181
275
|
|
182
276
|
should "default its actual value to nil when given nil" do
|
183
277
|
bool = MuchBoolean.new
|
184
|
-
|
185
|
-
|
278
|
+
assert_that(bool.given).is_nil
|
279
|
+
assert_that(bool.actual).is_false
|
186
280
|
end
|
187
281
|
|
188
282
|
should "know if it is equal to another much boolean or not" do
|
189
283
|
equal_bool = MuchBoolean.new(@actual)
|
190
284
|
not_bool = MuchBoolean.new(!@actual)
|
191
285
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
286
|
+
assert_that(subject).equals(equal_bool)
|
287
|
+
assert_that(subject).does_not_equal(not_bool)
|
288
|
+
assert_that(subject).equals(@actual)
|
289
|
+
assert_that(subject).does_not_equal(!@actual)
|
196
290
|
end
|
197
|
-
|
198
291
|
end
|
199
|
-
|
200
292
|
end
|
metadata
CHANGED
@@ -1,77 +1,76 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-boolean
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Kelly Redding
|
8
8
|
- Collin Redding
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2020-12-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: assert
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
version: 2.15.0
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.19.0
|
23
21
|
type: :development
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.19.0
|
28
|
+
description: An API for friendly boolean conversion, interpretation, and handling.
|
29
|
+
email:
|
27
30
|
- kelly@kellyredding.com
|
28
|
-
-
|
31
|
+
- 'collin.redding@me.com '
|
29
32
|
executables: []
|
30
|
-
|
31
33
|
extensions: []
|
32
|
-
|
33
34
|
extra_rdoc_files: []
|
34
|
-
|
35
|
-
|
36
|
-
- .gitignore
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
37
|
- Gemfile
|
38
38
|
- LICENSE
|
39
39
|
- README.md
|
40
40
|
- lib/much-boolean.rb
|
41
41
|
- lib/much-boolean/version.rb
|
42
|
-
- log/.
|
42
|
+
- log/.keep
|
43
43
|
- much-boolean.gemspec
|
44
44
|
- test/helper.rb
|
45
45
|
- test/support/factory.rb
|
46
|
+
- test/system/.keep
|
46
47
|
- test/unit/much-boolean_tests.rb
|
47
48
|
- tmp/.gitkeep
|
48
49
|
homepage: https://github.com/redding/much-boolean
|
49
|
-
licenses:
|
50
|
+
licenses:
|
50
51
|
- MIT
|
51
52
|
metadata: {}
|
52
|
-
|
53
53
|
post_install_message:
|
54
54
|
rdoc_options: []
|
55
|
-
|
56
|
-
require_paths:
|
55
|
+
require_paths:
|
57
56
|
- lib
|
58
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
-
|
61
|
-
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
67
|
requirements: []
|
68
|
-
|
69
|
-
rubyforge_project:
|
70
|
-
rubygems_version: 2.5.1
|
68
|
+
rubygems_version: 3.1.2
|
71
69
|
signing_key:
|
72
70
|
specification_version: 4
|
73
|
-
summary: An API for friendly boolean conversion, interpretation and handling
|
74
|
-
test_files:
|
71
|
+
summary: An API for friendly boolean conversion, interpretation, and handling.
|
72
|
+
test_files:
|
75
73
|
- test/helper.rb
|
76
74
|
- test/support/factory.rb
|
75
|
+
- test/system/.keep
|
77
76
|
- test/unit/much-boolean_tests.rb
|