much-boolean 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA512:
3
- data.tar.gz: 588233b63b8c027278fe8091af197d7645793ba12f4d822370c565fc6bc5799007b9daa8a3339a89a58c7cda907689db1a574ad5fa51dcc150f2777c75be8f53
4
- metadata.gz: c38027789951f97418399d4c9d6900948a9798398b41a896fbd2953d0545b79c8dd5e08fecb35a35172cca81a9bf7f97c88b5326eb097e60267551c9cdbbea37
5
- SHA1:
6
- data.tar.gz: cb6fb44dde93b2c682c5a52404cd19ac49954a56
7
- metadata.gz: d4088ebb93b990f874936ccfbf0c01e10b5120e9
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
@@ -1,5 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ ruby "~> 2.5"
4
+
3
5
  gemspec
4
6
 
5
- gem 'pry', "~> 0.9.0"
7
+ gem "pry"
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 'much-boolean'
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 - theses are ignored
17
- MuchBoolean.convert(nil) # => nil
18
- MuchBoolean.convert('') # => nil
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) # => false
22
- MuchBoolean.convert('0') # => false
23
- MuchBoolean.convert(1) # => true
24
- MuchBoolean.convert('1') # => true
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("f") # => false
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("t") # => true
38
- MuchBoolean.convert("T") # => true
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("n") # => false
45
- MuchBoolean.convert("N") # => false
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("y") # => true
50
- MuchBoolean.convert("Y") # => true
88
+ MuchBoolean.convert(:YES) # => true
51
89
 
52
90
  # all other values always interpreted as `true`
53
- MuchBoolean.convert('some-string') # => true
54
- MuchBoolean.convert('1938') # => true
55
- MuchBoolean.convert('1938.5') # => true
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 # => '1'
66
- MuchBoolean.one_zero(false).to_s # => '0'
67
-
68
- MuchBoolean.true_false(true) # => 'true'
69
- MuchBoolean.true_false(false) # => 'false'
70
- MuchBoolean.True_False(true) # => 'True'
71
- MuchBoolean.True_False(false) # => 'False'
72
- MuchBoolean.TRUE_FALSE(true) # => 'TRUE'
73
- MuchBoolean.TRUE_FALSE(false) # => 'FALSE'
74
- MuchBoolean.t_f(true) # => 't'
75
- MuchBoolean.t_f(false) # => 'f'
76
- MuchBoolean.T_F(true) # => 'T'
77
- MuchBoolean.T_F(false) # => 'F'
78
-
79
- MuchBoolean.yes_no(true) # => 'yes'
80
- MuchBoolean.yes_no(false) # => 'no'
81
- MuchBoolean.Yes_No(true) # => 'Yes'
82
- MuchBoolean.Yes_No(false) # => 'No'
83
- MuchBoolean.YES_NO(true) # => 'YES'
84
- MuchBoolean.YES_NO(false) # => 'NO'
85
- MuchBoolean.y_n(true) # => 'y'
86
- MuchBoolean.y_n(false) # => 'n'
87
- MuchBoolean.Y_N(true) # => 'Y'
88
- MuchBoolean.Y_N(false) # => '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
- ['some-string', '1938', '1938.5', Date.today, Time.now].each do |val|
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 'much-boolean'
162
+ gem "much-boolean"
120
163
 
121
164
  And then execute:
122
165
 
@@ -1,29 +1,104 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "much-boolean/version"
2
4
 
3
5
  class MuchBoolean
4
-
5
- FALSE_VALUES = [
6
- 0, '0',
7
- false, 'false', 'False', 'FALSE', 'f', 'F',
8
- 'no', 'No', 'NO', 'n', 'N'
9
- ].freeze
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); Mapping.new(boolean, 1, 0); end
17
- def self.true_false(boolean); Mapping.new(boolean, 'true', 'false'); end
18
- def self.True_False(boolean); Mapping.new(boolean, 'True', 'False'); end
19
- def self.TRUE_FALSE(boolean); Mapping.new(boolean, 'TRUE', 'FALSE'); end
20
- def self.t_f(boolean); Mapping.new(boolean, 't', 'f'); end
21
- def self.T_F(boolean); Mapping.new(boolean, 'T', 'F'); end
22
- def self.yes_no(boolean); Mapping.new(boolean, 'yes', 'no'); end
23
- def self.Yes_No(boolean); Mapping.new(boolean, 'Yes', 'No'); end
24
- def self.YES_NO(boolean); Mapping.new(boolean, 'YES', 'NO'); end
25
- def self.y_n(boolean); Mapping.new(boolean, 'y', 'n'); end
26
- def self.Y_N(boolean); Mapping.new(boolean, 'Y', 'N'); end
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 nil if boolean_value.to_s.empty? # covers `nil` and `""`
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MuchBoolean
2
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
3
5
  end
File without changes
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
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 = 'MIT'
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.15.0"])
22
-
21
+ gem.add_development_dependency("assert", ["~> 2.19.0"])
23
22
  end
@@ -5,6 +5,6 @@
5
5
  $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
6
6
 
7
7
  # require pry for debugging (`binding.pry`)
8
- require 'pry'
8
+ require "pry"
9
9
 
10
- require 'test/support/factory'
10
+ require "test/support/factory"
@@ -1,6 +1,5 @@
1
- require 'assert/factory'
1
+ require "assert/factory"
2
2
 
3
3
  module Factory
4
4
  extend Assert::Factory
5
-
6
5
  end
File without changes
@@ -1,5 +1,5 @@
1
- require 'assert'
2
- require 'much-boolean'
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 :true_false, :True_False, :TRUE_FALSE, :t_f, :T_F
13
- should have_imeths :yes_no, :Yes_No, :YES_NO, :y_n, :Y_N
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
- 0, '0',
18
- false, 'false', 'False', 'FALSE', 'f', 'F',
19
- 'no', 'No', 'NO', 'n', 'N'
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 "ignore nil and empty-string values when converting" do
25
- assert_nil MuchBoolean.convert(nil)
26
- assert_nil MuchBoolean.convert('')
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 'zero-ish' values as `false`" do
30
- [0, '0'].each do |val|
31
- assert_false MuchBoolean.convert(val)
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 'false-ish' values as `false`" do
36
- [false, 'false', 'False', 'FALSE', 'f', 'F'].each do |val|
37
- assert_false MuchBoolean.convert(val)
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 'no-ish' values as `false`" do
42
- ['no', 'No', 'NO', 'n', 'N'].each do |val|
43
- assert_false MuchBoolean.convert(val)
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 'one-ish' values as `true`" do
48
- [1, '1'].each do |val|
49
- assert_true MuchBoolean.convert(val)
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 'true-ish' values as `true`" do
54
- [true, 'true', 'True', 'TRUE', 't', 'T'].each do |val|
55
- assert_true MuchBoolean.convert(val)
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 'yes-ish' values as `true`" do
60
- ['yes', 'Yes', 'YES', 'y', 'Y'].each do |val|
61
- assert_true MuchBoolean.convert(val)
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
- assert_true MuchBoolean.convert(val)
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
- assert_equal 1, MuchBoolean.one_zero(true)
73
- assert_equal 0, MuchBoolean.one_zero(false)
74
- assert_equal nil, MuchBoolean.one_zero(nil)
75
- assert_equal nil, MuchBoolean.one_zero('')
76
- assert_equal 1, MuchBoolean.one_zero(Factory.string)
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
- assert_true MuchBoolean.convert(MuchBoolean.one_zero(true))
79
- assert_false MuchBoolean.convert(MuchBoolean.one_zero(false))
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
- assert_equal 'true', MuchBoolean.true_false(true)
84
- assert_equal 'false', MuchBoolean.true_false(false)
85
- assert_equal nil, MuchBoolean.true_false(nil)
86
- assert_equal nil, MuchBoolean.true_false('')
87
- assert_equal 'true', MuchBoolean.true_false(Factory.string)
88
- assert_equal 'True', MuchBoolean.True_False(true)
89
- assert_equal 'False', MuchBoolean.True_False(false)
90
- assert_equal nil, MuchBoolean.True_False(nil)
91
- assert_equal nil, MuchBoolean.True_False('')
92
- assert_equal 'True', MuchBoolean.True_False(Factory.string)
93
- assert_equal 'TRUE', MuchBoolean.TRUE_FALSE(true)
94
- assert_equal 'FALSE', MuchBoolean.TRUE_FALSE(false)
95
- assert_equal nil, MuchBoolean.TRUE_FALSE(nil)
96
- assert_equal nil, MuchBoolean.TRUE_FALSE('')
97
- assert_equal 'TRUE', MuchBoolean.TRUE_FALSE(Factory.string)
98
- assert_equal 't', MuchBoolean.t_f(true)
99
- assert_equal 'f', MuchBoolean.t_f(false)
100
- assert_equal nil, MuchBoolean.t_f(nil)
101
- assert_equal nil, MuchBoolean.t_f('')
102
- assert_equal 't', MuchBoolean.t_f(Factory.string)
103
- assert_equal 'T', MuchBoolean.T_F(true)
104
- assert_equal 'F', MuchBoolean.T_F(false)
105
- assert_equal nil, MuchBoolean.T_F(nil)
106
- assert_equal nil, MuchBoolean.T_F('')
107
- assert_equal 'T', MuchBoolean.T_F(Factory.string)
108
-
109
- assert_true MuchBoolean.convert(MuchBoolean.true_false(true))
110
- assert_false MuchBoolean.convert(MuchBoolean.true_false(false))
111
- assert_true MuchBoolean.convert(MuchBoolean.True_False(true))
112
- assert_false MuchBoolean.convert(MuchBoolean.True_False(false))
113
- assert_true MuchBoolean.convert(MuchBoolean.TRUE_FALSE(true))
114
- assert_false MuchBoolean.convert(MuchBoolean.TRUE_FALSE(false))
115
- assert_true MuchBoolean.convert(MuchBoolean.t_f(true))
116
- assert_false MuchBoolean.convert(MuchBoolean.t_f(false))
117
- assert_true MuchBoolean.convert(MuchBoolean.T_F(true))
118
- assert_false MuchBoolean.convert(MuchBoolean.T_F(false))
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 yes/no strings" do
122
- assert_equal 'yes', MuchBoolean.yes_no(true)
123
- assert_equal 'no', MuchBoolean.yes_no(false)
124
- assert_equal nil, MuchBoolean.yes_no(nil)
125
- assert_equal nil, MuchBoolean.yes_no('')
126
- assert_equal 'yes', MuchBoolean.yes_no(Factory.string)
127
- assert_equal 'Yes', MuchBoolean.Yes_No(true)
128
- assert_equal 'No', MuchBoolean.Yes_No(false)
129
- assert_equal nil, MuchBoolean.Yes_No(nil)
130
- assert_equal nil, MuchBoolean.Yes_No('')
131
- assert_equal 'Yes', MuchBoolean.Yes_No(Factory.string)
132
- assert_equal 'YES', MuchBoolean.YES_NO(true)
133
- assert_equal 'NO', MuchBoolean.YES_NO(false)
134
- assert_equal nil, MuchBoolean.YES_NO(nil)
135
- assert_equal nil, MuchBoolean.YES_NO('')
136
- assert_equal 'YES', MuchBoolean.YES_NO(Factory.string)
137
- assert_equal 'y', MuchBoolean.y_n(true)
138
- assert_equal 'n', MuchBoolean.y_n(false)
139
- assert_equal nil, MuchBoolean.y_n(nil)
140
- assert_equal nil, MuchBoolean.y_n('')
141
- assert_equal 'y', MuchBoolean.y_n(Factory.string)
142
- assert_equal 'Y', MuchBoolean.Y_N(true)
143
- assert_equal 'N', MuchBoolean.Y_N(false)
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
- assert_equal @actual, subject.given
174
- assert_equal @actual, subject.actual
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
- assert_equal str, bool.given
179
- assert_true bool.actual
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
- assert_nil bool.given
185
- assert_nil bool.actual
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
- assert_equal equal_bool, subject
193
- assert_not_equal not_bool, subject
194
- assert_equal subject, @actual
195
- assert_not_equal subject, !@actual
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.1.3
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
- date: 2016-02-11 00:00:00 Z
14
- dependencies:
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
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
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
- version_requirements: *id001
25
- description: An API for friendly boolean conversion, interpretation and handling
26
- email:
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
- - "collin.redding@me.com "
31
+ - 'collin.redding@me.com '
29
32
  executables: []
30
-
31
33
  extensions: []
32
-
33
34
  extra_rdoc_files: []
34
-
35
- files:
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/.gitkeep
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
- - &id002
61
- - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- required_rubygems_version: !ruby/object:Gem::Requirement
65
- requirements:
66
- - *id002
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