to_bool 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/spec/to_bool_spec.rb +44 -104
- metadata +7 -26
- data/.gitignore +0 -18
- data/CHANGELOG.md +0 -4
- data/Gemfile +0 -4
- data/README.md +0 -35
- data/Rakefile +0 -3
- data/to_bool.gemspec +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ac619060f8d31344eb7690663105cf9f70dc0dbde03baf7638039ff26d0f821
|
4
|
+
data.tar.gz: 68c4d0360c67d7e851c4c9765718d5e653efe553c70c2ab7ada53e5cc047b8bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85c97a718b42dd6a241c0d27a7aebec592624c237fef131aea87dcea3735680a722686d36702e9813296651863fa30c748bb8b31787b31b4a70b5ed775659944
|
7
|
+
data.tar.gz: e2c748c117fc2561d31ad201370f4b1d101be3ac3b9502c5fb86583e537cd4803df7e5490b0ceb7af76ee240eacddc246de754a4108f825261d03e756e6c3998
|
data/spec/to_bool_spec.rb
CHANGED
@@ -1,109 +1,49 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
Bundler.require
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
expect("yes".to_bool).to eq true
|
7
|
-
end
|
8
|
-
|
9
|
-
it "is true if 'YES'" do
|
10
|
-
expect("YES".to_bool).to eq true
|
11
|
-
end
|
12
|
-
|
13
|
-
it "is true if 'y'" do
|
14
|
-
expect("y".to_bool).to eq true
|
15
|
-
end
|
16
|
-
|
17
|
-
it "is true if 'Y'" do
|
18
|
-
expect("Y".to_bool).to eq true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "is true if '1'" do
|
22
|
-
expect("1".to_bool).to eq true
|
23
|
-
end
|
24
|
-
|
25
|
-
it "is true if 'true'" do
|
26
|
-
expect("true".to_bool).to eq true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "is true if 'TRUE'" do
|
30
|
-
expect("TRUE".to_bool).to eq true
|
31
|
-
end
|
32
|
-
|
33
|
-
it "is true if 't'" do
|
34
|
-
expect("t".to_bool).to eq true
|
35
|
-
end
|
36
|
-
|
37
|
-
it "is true if 'T'" do
|
38
|
-
expect("T".to_bool).to eq true
|
39
|
-
end
|
40
|
-
|
41
|
-
it "is false otherwise" do
|
42
|
-
expect("no".to_bool).to eq false
|
43
|
-
expect("NO".to_bool).to eq false
|
44
|
-
expect("n".to_bool).to eq false
|
45
|
-
expect("N".to_bool).to eq false
|
46
|
-
expect("false".to_bool).to eq false
|
47
|
-
expect("FALSE".to_bool).to eq false
|
48
|
-
expect("f".to_bool).to eq false
|
49
|
-
expect("F".to_bool).to eq false
|
50
|
-
expect("0".to_bool).to eq false
|
51
|
-
end
|
52
|
-
|
53
|
-
it "is true when using to_boolean" do
|
54
|
-
expect("true".to_boolean).to eq true
|
55
|
-
end
|
4
|
+
def assert(expected, actual)
|
5
|
+
raise "Failed Assertion" if expected != actual
|
56
6
|
end
|
57
7
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
it "is false otherwise" do
|
102
|
-
expect(:false.to_bool).to eq false
|
103
|
-
expect(:hoge.to_bool).to eq false
|
104
|
-
end
|
105
|
-
|
106
|
-
it "is true when using to_boolean" do
|
107
|
-
expect(:true.to_bool).to eq true
|
108
|
-
end
|
109
|
-
end
|
8
|
+
# String
|
9
|
+
assert(true, "yes".to_bool)
|
10
|
+
assert(true, "YES".to_bool)
|
11
|
+
assert(true, "y".to_bool)
|
12
|
+
assert(true, "Y".to_bool)
|
13
|
+
assert(true, "1".to_bool)
|
14
|
+
assert(true, "true".to_bool)
|
15
|
+
assert(true, "TRUE".to_bool)
|
16
|
+
assert(true, "t".to_bool)
|
17
|
+
assert(true, "T".to_bool)
|
18
|
+
assert(true, "true".to_boolean)
|
19
|
+
|
20
|
+
assert(false, "no".to_bool)
|
21
|
+
assert(false, "NO".to_bool)
|
22
|
+
assert(false, "n".to_bool)
|
23
|
+
assert(false, "N".to_bool)
|
24
|
+
assert(false, "false".to_bool)
|
25
|
+
assert(false, "FALSE".to_bool)
|
26
|
+
assert(false, "f".to_bool)
|
27
|
+
assert(false, "F".to_bool)
|
28
|
+
assert(false, "0".to_bool)
|
29
|
+
|
30
|
+
# Integer
|
31
|
+
assert(true, 1.to_bool)
|
32
|
+
assert(true, 1.to_boolean)
|
33
|
+
assert(false, 0.to_bool)
|
34
|
+
|
35
|
+
# TrueClass
|
36
|
+
assert(true, true.to_bool)
|
37
|
+
assert(true, true.to_boolean)
|
38
|
+
assert(false, false.to_boolean)
|
39
|
+
|
40
|
+
# Object
|
41
|
+
assert(false, Object.new.to_bool)
|
42
|
+
assert(false, Object.new.to_boolean)
|
43
|
+
|
44
|
+
# Symbol
|
45
|
+
assert(true, :true.to_bool)
|
46
|
+
assert(true, :TRUE.to_bool)
|
47
|
+
assert(false, :false.to_bool)
|
48
|
+
assert(false, :hoge.to_bool)
|
49
|
+
assert(true, :true.to_boolean)
|
metadata
CHANGED
@@ -1,47 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_bool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Ricker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rspec
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
11
|
+
date: 2023-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: Super-simple gem that extends some Ruby classes with a "to_bool" method,
|
28
14
|
which converts any object naturally into a boolean.
|
29
15
|
email:
|
30
|
-
-
|
16
|
+
- rubygems@bryanricker.com
|
31
17
|
executables: []
|
32
18
|
extensions: []
|
33
19
|
extra_rdoc_files: []
|
34
20
|
files:
|
35
|
-
- ".gitignore"
|
36
|
-
- CHANGELOG.md
|
37
|
-
- Gemfile
|
38
|
-
- README.md
|
39
|
-
- Rakefile
|
40
21
|
- lib/to_bool.rb
|
41
22
|
- spec/to_bool_spec.rb
|
42
|
-
- to_bool.gemspec
|
43
23
|
homepage: http://github.com/bricker/to_bool
|
44
|
-
licenses:
|
24
|
+
licenses:
|
25
|
+
- MIT
|
45
26
|
metadata: {}
|
46
27
|
post_install_message:
|
47
28
|
rdoc_options: []
|
@@ -58,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
39
|
- !ruby/object:Gem::Version
|
59
40
|
version: '0'
|
60
41
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
42
|
+
rubygems_version: 3.4.10
|
62
43
|
signing_key:
|
63
44
|
specification_version: 4
|
64
45
|
summary: Convert any object naturally into a boolean
|
data/.gitignore
DELETED
data/CHANGELOG.md
DELETED
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# ToBool
|
2
|
-
|
3
|
-
Natural coercion into boolean (true / false). Useful for API interaction.
|
4
|
-
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
`gem "to_bool"`
|
9
|
-
|
10
|
-
|
11
|
-
## Usage
|
12
|
-
|
13
|
-
Call `to_bool` on any object. It will *usually* return false, except:
|
14
|
-
|
15
|
-
* String: `"true"`, `"1"`, `"y"`, and `"yes"` are true
|
16
|
-
* Integer: `1` is true
|
17
|
-
* TrueClass: `true` is true
|
18
|
-
* Symbol: `:true` is true
|
19
|
-
|
20
|
-
See the spec, it pretty much maps it out.
|
21
|
-
|
22
|
-
## Contributing
|
23
|
-
|
24
|
-
Yes!
|
25
|
-
|
26
|
-
### Running Tests
|
27
|
-
|
28
|
-
```
|
29
|
-
bundle exec rspec
|
30
|
-
```
|
31
|
-
|
32
|
-
|
33
|
-
## License
|
34
|
-
|
35
|
-
MIT
|
data/Rakefile
DELETED
data/to_bool.gemspec
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
-
Gem::Specification.new do |gem|
|
6
|
-
gem.name = "to_bool"
|
7
|
-
gem.version = "2.0.0"
|
8
|
-
gem.authors = ["Bryan Ricker"]
|
9
|
-
gem.email = ["bryancricker@gmail.com"]
|
10
|
-
gem.description = %q{Super-simple gem that extends some Ruby classes with a "to_bool" method, which converts any object naturally into a boolean.}
|
11
|
-
gem.summary = %q{Convert any object naturally into a boolean}
|
12
|
-
gem.homepage = "http://github.com/bricker/to_bool"
|
13
|
-
|
14
|
-
gem.files = `git ls-files`.split($/)
|
15
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
-
gem.require_paths = ["lib"]
|
18
|
-
|
19
|
-
gem.add_development_dependency "rspec", [">= 0"]
|
20
|
-
end
|