much-boolean 0.0.1 → 0.1.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 +0 -1
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +72 -2
- data/lib/much-boolean.rb +28 -2
- data/lib/much-boolean/version.rb +2 -2
- data/much-boolean.gemspec +5 -5
- data/test/helper.rb +0 -2
- data/test/unit/much-boolean_tests.rb +108 -0
- metadata +44 -41
- data/Rakefile +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48aafb38b7e679d55b28931ecdd3faaecdf9002b
|
4
|
+
data.tar.gz: c4e0ffce78e57e3dc90c99cc057c100ba62cc39a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8327489713a0b0ddece4c7ba41977d780f3050c532d6a7fdc4e9c85a89544797ec2ef0bb62f1255f56ccf1aec62d11ac65e3d8b7aaad6a7f36df53d37dd5db0
|
7
|
+
data.tar.gz: f9fafdee5f32d913d492ff660e6c5c68fbead9788f9055c8cd88ba73717eb53d094e65649fa96dc7b37b02de7b22bcb5bec77aa664fbfe1a839c0c5439789848
|
data/Gemfile
CHANGED
data/{LICENSE.txt → LICENSE}
RENAMED
data/README.md
CHANGED
@@ -1,10 +1,80 @@
|
|
1
1
|
# MuchBoolean
|
2
2
|
|
3
|
-
|
3
|
+
An API for friendly boolean conversion, interpretation and handling
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
|
7
|
+
```ruby
|
8
|
+
require 'much-boolean'
|
9
|
+
MuchBoolean::FALSE_VALUES # => [ nil, 0, "0",
|
10
|
+
# false, "false", "False", "FALSE", "f", "F",
|
11
|
+
# "no", "No", "NO", "n", "N"
|
12
|
+
# ]
|
13
|
+
|
14
|
+
# nil, zero/one type values
|
15
|
+
MuchBoolean.convert(nil) # => false
|
16
|
+
MuchBoolean.convert(0) # => false
|
17
|
+
MuchBoolean.convert('0') # => false
|
18
|
+
MuchBoolean.convert(1) # => true
|
19
|
+
MuchBoolean.convert('1') # => true
|
20
|
+
|
21
|
+
# true/false type values
|
22
|
+
MuchBoolean.convert(false) # => false
|
23
|
+
MuchBoolean.convert("false") # => false
|
24
|
+
MuchBoolean.convert("False") # => false
|
25
|
+
MuchBoolean.convert("FALSE") # => false
|
26
|
+
MuchBoolean.convert("f") # => false
|
27
|
+
MuchBoolean.convert("F") # => false
|
28
|
+
MuchBoolean.convert(true) # => true
|
29
|
+
MuchBoolean.convert("true") # => true
|
30
|
+
MuchBoolean.convert("True") # => true
|
31
|
+
MuchBoolean.convert("TRUE") # => true
|
32
|
+
MuchBoolean.convert("t") # => true
|
33
|
+
MuchBoolean.convert("T") # => true
|
34
|
+
|
35
|
+
# yes/no type values
|
36
|
+
MuchBoolean.convert("no") # => false
|
37
|
+
MuchBoolean.convert("No") # => false
|
38
|
+
MuchBoolean.convert("NO") # => false
|
39
|
+
MuchBoolean.convert("n") # => false
|
40
|
+
MuchBoolean.convert("N") # => false
|
41
|
+
MuchBoolean.convert("yes") # => true
|
42
|
+
MuchBoolean.convert("Yes") # => true
|
43
|
+
MuchBoolean.convert("YES") # => true
|
44
|
+
MuchBoolean.convert("y") # => true
|
45
|
+
MuchBoolean.convert("Y") # => true
|
46
|
+
|
47
|
+
# all other values always interpreted as `true`
|
48
|
+
MuchBoolean.convert('some-string') # => true
|
49
|
+
MuchBoolean.convert('1938') # => true
|
50
|
+
MuchBoolean.convert('1938.5') # => true
|
51
|
+
MuchBoolean.convert(Date.today) # => true
|
52
|
+
MuchBoolean.convert(Time.now) # => true
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
# create instances to track given values and the actually boolean values they map to
|
57
|
+
|
58
|
+
bool = MuchBoolean.new
|
59
|
+
bool.given # => nil
|
60
|
+
bool.actual # => false
|
61
|
+
|
62
|
+
MuchBoolean::FALSE_VALUES.each do |val|
|
63
|
+
bool = MuchBoolean.new(val)
|
64
|
+
bool.given # => {val}
|
65
|
+
bool.actual # => false
|
66
|
+
bool == false # => true
|
67
|
+
bool == true # => false
|
68
|
+
end
|
69
|
+
|
70
|
+
['some-string', '1938', '1938.5', Date.today, Time.now].each do |val|
|
71
|
+
bool = MuchBoolean.new(val)
|
72
|
+
bool.given # => {val}
|
73
|
+
bool.actual # => true
|
74
|
+
bool == true # => true
|
75
|
+
bool == false # => false
|
76
|
+
end
|
77
|
+
```
|
8
78
|
|
9
79
|
## Installation
|
10
80
|
|
data/lib/much-boolean.rb
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
require "much-boolean/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
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
|
11
|
+
|
12
|
+
def self.convert(value)
|
13
|
+
!FALSE_VALUES.include?(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :given, :actual
|
17
|
+
|
18
|
+
def initialize(given = nil)
|
19
|
+
@given = given
|
20
|
+
@actual = self.class.convert(@given)
|
21
|
+
end
|
22
|
+
|
23
|
+
def ==(other_boolean)
|
24
|
+
if other_boolean.kind_of?(MuchBoolean)
|
25
|
+
self.actual == other_boolean.actual
|
26
|
+
else
|
27
|
+
self.actual == other_boolean
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
5
31
|
end
|
data/lib/much-boolean/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0
|
1
|
+
class MuchBoolean
|
2
|
+
VERSION = "0.1.0"
|
3
3
|
end
|
data/much-boolean.gemspec
CHANGED
@@ -7,10 +7,10 @@ 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.
|
12
|
-
gem.
|
13
|
-
gem.homepage = "
|
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
14
|
gem.license = 'MIT'
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($/)
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |gem|
|
|
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.
|
21
|
+
gem.add_development_dependency("assert", ["~> 2.15.0"])
|
22
22
|
|
23
23
|
end
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,108 @@
|
|
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_imeth :convert
|
11
|
+
|
12
|
+
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
|
+
]
|
19
|
+
assert_equal exp, subject::FALSE_VALUES
|
20
|
+
end
|
21
|
+
|
22
|
+
should "convert nil values as `false`" do
|
23
|
+
assert_false MuchBoolean.convert(nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "convert 'zero-ish' values as `false`" do
|
27
|
+
[0, '0'].each do |val|
|
28
|
+
assert_false MuchBoolean.convert(val)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
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)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
should "convert 'no-ish' values as `false`" do
|
39
|
+
['no', 'No', 'NO', 'n', 'N'].each do |val|
|
40
|
+
assert_false MuchBoolean.convert(val)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
should "convert 'one-ish' values as `true`" do
|
45
|
+
[1, '1'].each do |val|
|
46
|
+
assert_true MuchBoolean.convert(val)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
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)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
should "convert 'yes-ish' values as `true`" do
|
57
|
+
['yes', 'Yes', 'YES', 'y', 'Y'].each do |val|
|
58
|
+
assert_true MuchBoolean.convert(val)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
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)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
class InitTests < UnitTests
|
71
|
+
desc "when init"
|
72
|
+
setup do
|
73
|
+
@actual = Factory.boolean
|
74
|
+
@bool = MuchBoolean.new(@actual)
|
75
|
+
end
|
76
|
+
subject{ @bool }
|
77
|
+
|
78
|
+
should have_reader :given, :actual
|
79
|
+
|
80
|
+
should "know its given and actual boolean values" do
|
81
|
+
assert_equal @actual, subject.given
|
82
|
+
assert_equal @actual, subject.actual
|
83
|
+
|
84
|
+
str = Factory.string
|
85
|
+
bool = MuchBoolean.new(str)
|
86
|
+
assert_equal str, bool.given
|
87
|
+
assert_true bool.actual
|
88
|
+
end
|
89
|
+
|
90
|
+
should "default its actual value to `false` when given nothing" do
|
91
|
+
bool = MuchBoolean.new
|
92
|
+
assert_nil bool.given
|
93
|
+
assert_false bool.actual
|
94
|
+
end
|
95
|
+
|
96
|
+
should "know if it is equal to another much boolean or not" do
|
97
|
+
equal_bool = MuchBoolean.new(@actual)
|
98
|
+
not_bool = MuchBoolean.new(!@actual)
|
99
|
+
|
100
|
+
assert_equal equal_bool, subject
|
101
|
+
assert_not_equal not_bool, subject
|
102
|
+
assert_equal subject, @actual
|
103
|
+
assert_not_equal subject, !@actual
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
metadata
CHANGED
@@ -1,74 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-boolean
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.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
|
-
|
12
|
+
|
13
|
+
date: 2016-01-11 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
15
16
|
name: assert
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '2.14'
|
21
|
-
type: :development
|
22
17
|
prerelease: false
|
23
|
-
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
|
29
|
-
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.15.0
|
23
|
+
type: :development
|
24
|
+
version_requirements: *id001
|
25
|
+
description: An API for friendly boolean conversion, interpretation and handling
|
26
|
+
email:
|
30
27
|
- kelly@kellyredding.com
|
31
|
-
- collin.redding@me.com
|
28
|
+
- "collin.redding@me.com "
|
32
29
|
executables: []
|
30
|
+
|
33
31
|
extensions: []
|
32
|
+
|
34
33
|
extra_rdoc_files: []
|
35
|
-
|
36
|
-
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
37
|
- Gemfile
|
38
|
-
- LICENSE
|
38
|
+
- LICENSE
|
39
39
|
- README.md
|
40
|
-
- Rakefile
|
41
40
|
- lib/much-boolean.rb
|
42
41
|
- lib/much-boolean/version.rb
|
43
42
|
- log/.gitkeep
|
44
43
|
- much-boolean.gemspec
|
45
44
|
- test/helper.rb
|
46
45
|
- test/support/factory.rb
|
46
|
+
- test/unit/much-boolean_tests.rb
|
47
47
|
- tmp/.gitkeep
|
48
|
-
homepage:
|
49
|
-
licenses:
|
48
|
+
homepage: https://github.com/redding/much-boolean
|
49
|
+
licenses:
|
50
50
|
- MIT
|
51
51
|
metadata: {}
|
52
|
+
|
52
53
|
post_install_message:
|
53
54
|
rdoc_options: []
|
54
|
-
|
55
|
+
|
56
|
+
require_paths:
|
55
57
|
- lib
|
56
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
-
|
59
|
-
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
version: '0'
|
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
|
66
67
|
requirements: []
|
68
|
+
|
67
69
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.
|
70
|
+
rubygems_version: 2.5.1
|
69
71
|
signing_key:
|
70
72
|
specification_version: 4
|
71
|
-
summary:
|
72
|
-
test_files:
|
73
|
+
summary: An API for friendly boolean conversion, interpretation and handling
|
74
|
+
test_files:
|
73
75
|
- test/helper.rb
|
74
76
|
- test/support/factory.rb
|
77
|
+
- test/unit/much-boolean_tests.rb
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|