much-boolean 0.0.1 → 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
1
  ---
2
- SHA1:
3
- metadata.gz: 19242c1105e248ee22d620f3753f9df082af7a07
4
- data.tar.gz: c2da6ded6b3ff22e1c7999e81ad7bebe1c4c9be5
2
+ SHA256:
3
+ metadata.gz: d1fc3165719932c28dd78776ec526e4f0f0b72b61f987271396003e2e17a4354
4
+ data.tar.gz: 190c8c50385772aa25101e0a2a2e04948d56ae9df8056a3c57f1e74dc4b99fb2
5
5
  SHA512:
6
- metadata.gz: c5df601f8ee5f18616f19fd2e3257daae376ec8e8d41bfc45066b96cbdedad74ee61a4483c964b4af47f8da933868e5312b301ff1a4108174172d328300b906a
7
- data.tar.gz: 3f087f6b1a4bbc1b27a9894d6771a409c0ba0868c33e4e91a5b25f21830d079f2135f67ca5814646a2767df4f0964a8db7a321ca532b61e3594ad757605d4c40
6
+ metadata.gz: e5596cac8da12906767898be162b6dae6f03f64f63e72c882907b03a4819f04241596d299ae6485c01595d87362852621d93f2bedd985e6e41b54a4cfa863aca
7
+ data.tar.gz: ace459e19aeebf53ad35c5a69f13c6d07cf1d6b56c2dc47c9ff011909239d0f337d61cbbe9a36670e0f3f7259ad0bc783c93a27c703fc2da2f17eab7dc38dfa0
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ ruby "~> 2.5"
4
+
3
5
  gemspec
4
6
 
5
- gem 'rake', "~> 10.4.0"
6
- gem 'pry', "~> 0.9.0"
7
+ gem "pry"
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-Present Kelly Redding and Collin Redding
1
+ Copyright (c) 2016-Present Kelly Redding and Collin Redding
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,16 +1,165 @@
1
1
  # MuchBoolean
2
2
 
3
- TODO: Write a gem description
3
+ An API for friendly boolean conversion, interpretation and handling
4
4
 
5
5
  ## Usage
6
6
 
7
- TODO: Write code samples and usage instructions here
7
+ ```ruby
8
+ require "much-boolean"
9
+ MuchBoolean::FALSE_VALUES # => [ 0, "0",
10
+ # false, "false", "False", "FALSE", "f", "F",
11
+ # "no", "No", "NO", "n", "N"
12
+ # ]
13
+
14
+
15
+ # convert human-friendly representative values to actual booleans
16
+
17
+ # nil and empty-string values
18
+ MuchBoolean.convert(nil) # => false
19
+ MuchBoolean.convert("") # => false
20
+ MuchBoolean.convert(:"") # => false
21
+
22
+ # zero/one type values
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
29
+
30
+ # true/false type values
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
36
+ MuchBoolean.convert("false") # => false
37
+ MuchBoolean.convert(:false) # => false
38
+ MuchBoolean.convert("False") # => false
39
+ MuchBoolean.convert(:False) # => false
40
+ MuchBoolean.convert("FALSE") # => false
41
+ MuchBoolean.convert(:FALSE) # => false
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
47
+ MuchBoolean.convert("true") # => true
48
+ MuchBoolean.convert(:true) # => true
49
+ MuchBoolean.convert("True") # => true
50
+ MuchBoolean.convert(:True) # => true
51
+ MuchBoolean.convert("TRUE") # => 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
67
+
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
73
+ MuchBoolean.convert("no") # => false
74
+ MuchBoolean.convert(:no) # => false
75
+ MuchBoolean.convert("No") # => false
76
+ MuchBoolean.convert(:No) # => false
77
+ MuchBoolean.convert("NO") # => 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
83
+ MuchBoolean.convert("yes") # => true
84
+ MuchBoolean.convert(:yes) # => true
85
+ MuchBoolean.convert("Yes") # => true
86
+ MuchBoolean.convert(:Yes) # => true
87
+ MuchBoolean.convert("YES") # => true
88
+ MuchBoolean.convert(:YES) # => true
89
+
90
+ # all other values always interpreted as `true`
91
+ MuchBoolean.convert("some-string") # => true
92
+ MuchBoolean.convert(1938) # => true
93
+ MuchBoolean.convert(1938.5) # => true
94
+ MuchBoolean.convert(Date.today) # => true
95
+ MuchBoolean.convert(Time.now) # => true
96
+
97
+
98
+ # convert actual booleans back to human-friendly representative values
99
+
100
+ MuchBoolean.one_zero(true) # => 1
101
+ MuchBoolean.one_zero(false) # => 0
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"
133
+
134
+
135
+ # create instances to track given human-friendly values and the boolean values they map to
136
+
137
+ bool = MuchBoolean.new
138
+ bool.given # => nil
139
+ bool.actual # => nil
140
+
141
+ MuchBoolean::FALSE_VALUES.each do |val|
142
+ bool = MuchBoolean.new(val)
143
+ bool.given # => {val}
144
+ bool.actual # => false
145
+ bool == false # => true
146
+ bool == true # => false
147
+ end
148
+
149
+ ["some-string", 1938, 1938.5, Date.today, Time.now].each do |val|
150
+ bool = MuchBoolean.new(val)
151
+ bool.given # => {val}
152
+ bool.actual # => true
153
+ bool == true # => true
154
+ bool == false # => false
155
+ end
156
+ ```
8
157
 
9
158
  ## Installation
10
159
 
11
160
  Add this line to your application's Gemfile:
12
161
 
13
- gem 'much-boolean'
162
+ gem "much-boolean"
14
163
 
15
164
  And then execute:
16
165
 
@@ -1,5 +1,124 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "much-boolean/version"
2
4
 
3
- module MuchBoolean
4
- # TODO: your code goes here...
5
+ class MuchBoolean
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
42
+
43
+ def self.convert(value)
44
+ !FALSE_VALUES.include?(value)
45
+ end
46
+
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
102
+
103
+ attr_reader :given, :actual
104
+
105
+ def initialize(given = nil)
106
+ @given = given
107
+ @actual = self.class.convert(@given)
108
+ end
109
+
110
+ def ==(other_boolean)
111
+ if other_boolean.kind_of?(MuchBoolean)
112
+ self.actual == other_boolean.actual
113
+ else
114
+ self.actual == other_boolean
115
+ end
116
+ end
117
+
118
+ module Mapping
119
+ def self.new(boolean_value, true_value, false_value)
120
+ return false_value if MuchBoolean.convert(boolean_value) == false
121
+ true_value
122
+ end
123
+ end
5
124
  end
@@ -1,3 +1,5 @@
1
- module MuchBoolean
2
- VERSION = "0.0.1"
1
+ # frozen_string_literal: true
2
+
3
+ class MuchBoolean
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
 
@@ -7,17 +7,16 @@ Gem::Specification.new do |gem|
7
7
  gem.name = "much-boolean"
8
8
  gem.version = MuchBoolean::VERSION
9
9
  gem.authors = ["Kelly Redding", "Collin Redding"]
10
- gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
11
- gem.description = %q{Much boolean}
12
- gem.summary = %q{Much boolean}
13
- gem.homepage = "http://github.com/redding/much-boolean"
14
- gem.license = 'MIT'
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."
13
+ gem.homepage = "https://github.com/redding/much-boolean"
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.14"])
22
-
21
+ gem.add_development_dependency("assert", ["~> 2.19.0"])
23
22
  end
@@ -5,8 +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'
11
-
12
- # TODO: put test helpers here...
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
@@ -0,0 +1,292 @@
1
+ require "assert"
2
+ require "much-boolean"
3
+
4
+ class MuchBoolean
5
+
6
+ class UnitTests < Assert::Context
7
+ desc "MuchBoolean"
8
+ subject{ MuchBoolean }
9
+
10
+ should have_imeths :convert
11
+ should have_imeths :one_zero
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
15
+
16
+ should "know its false values" do
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
+ ]
53
+ assert_equal exp, subject::FALSE_VALUES
54
+ end
55
+
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
60
+ end
61
+
62
+ should "convert zero-ish values as `false`" do
63
+ [0, "0", :"0"].each do |val|
64
+ assert_that(MuchBoolean.convert(val)).is_false
65
+ end
66
+ end
67
+
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
83
+ end
84
+ end
85
+
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
89
+ end
90
+ end
91
+
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
95
+ end
96
+ end
97
+
98
+ should "convert one-ish values as `true`" do
99
+ [1, "1", :"1"].each do |val|
100
+ assert_that(MuchBoolean.convert(val)).is_true
101
+ end
102
+ end
103
+
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
131
+ end
132
+ end
133
+
134
+ should "convert all other values as `true`" do
135
+ [Factory.string, Factory.integer, Factory.date, Factory.time].each do |val|
136
+ assert_that(MuchBoolean.convert(val)).is_true
137
+ end
138
+ end
139
+
140
+ should "encode booleans as ones and zeros" do
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)
146
+
147
+ assert_that(MuchBoolean.convert(MuchBoolean.one_zero(true))).is_true
148
+ assert_that(MuchBoolean.convert(MuchBoolean.one_zero(false))).is_false
149
+ end
150
+
151
+ should "encode booleans as true/false strings" do
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
188
+ end
189
+
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
213
+ end
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
253
+ end
254
+
255
+ class InitTests < UnitTests
256
+ desc "when init"
257
+ subject{ @bool }
258
+
259
+ setup do
260
+ @actual = Factory.boolean
261
+ @bool = MuchBoolean.new(@actual)
262
+ end
263
+
264
+ should have_reader :given, :actual
265
+
266
+ should "know its given and actual boolean values" do
267
+ assert_that(subject.given).equals(@actual)
268
+ assert_that(subject.actual).equals(@actual)
269
+
270
+ str = Factory.string
271
+ bool = MuchBoolean.new(str)
272
+ assert_that(bool.given).equals(str)
273
+ assert_that(bool.actual).is_true
274
+ end
275
+
276
+ should "default its actual value to nil when given nil" do
277
+ bool = MuchBoolean.new
278
+ assert_that(bool.given).is_nil
279
+ assert_that(bool.actual).is_false
280
+ end
281
+
282
+ should "know if it is equal to another much boolean or not" do
283
+ equal_bool = MuchBoolean.new(@actual)
284
+ not_bool = MuchBoolean.new(!@actual)
285
+
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)
290
+ end
291
+ end
292
+ end
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.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-17 00:00:00.000000000 Z
12
+ date: 2020-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: assert
@@ -17,35 +17,36 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '2.14'
20
+ version: 2.19.0
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '2.14'
28
- description: Much boolean
27
+ version: 2.19.0
28
+ description: An API for friendly boolean conversion, interpretation, and handling.
29
29
  email:
30
30
  - kelly@kellyredding.com
31
- - collin.redding@me.com
31
+ - 'collin.redding@me.com '
32
32
  executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
36
  - ".gitignore"
37
37
  - Gemfile
38
- - LICENSE.txt
38
+ - LICENSE
39
39
  - README.md
40
- - Rakefile
41
40
  - lib/much-boolean.rb
42
41
  - lib/much-boolean/version.rb
43
- - log/.gitkeep
42
+ - log/.keep
44
43
  - much-boolean.gemspec
45
44
  - test/helper.rb
46
45
  - test/support/factory.rb
46
+ - test/system/.keep
47
+ - test/unit/much-boolean_tests.rb
47
48
  - tmp/.gitkeep
48
- homepage: http://github.com/redding/much-boolean
49
+ homepage: https://github.com/redding/much-boolean
49
50
  licenses:
50
51
  - MIT
51
52
  metadata: {}
@@ -64,11 +65,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
65
  - !ruby/object:Gem::Version
65
66
  version: '0'
66
67
  requirements: []
67
- rubyforge_project:
68
- rubygems_version: 2.4.5
68
+ rubygems_version: 3.1.2
69
69
  signing_key:
70
70
  specification_version: 4
71
- summary: Much boolean
71
+ summary: An API for friendly boolean conversion, interpretation, and handling.
72
72
  test_files:
73
73
  - test/helper.rb
74
74
  - test/support/factory.rb
75
+ - test/system/.keep
76
+ - test/unit/much-boolean_tests.rb
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"