much-boolean 0.1.0 → 0.2.1

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