to_bool 1.2.0 → 2.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 +4 -4
- data/lib/to_bool.rb +1 -1
- data/spec/to_bool_spec.rb +44 -90
- metadata +7 -26
- data/.gitignore +0 -18
- 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/lib/to_bool.rb
CHANGED
data/spec/to_bool_spec.rb
CHANGED
@@ -1,95 +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 '1'" do
|
14
|
-
expect("1".to_bool).to eq true
|
15
|
-
end
|
16
|
-
|
17
|
-
it "is true if 'true'" do
|
18
|
-
expect("true".to_bool).to eq true
|
19
|
-
end
|
20
|
-
|
21
|
-
it "is true if 'TRUE'" do
|
22
|
-
expect("TRUE".to_bool).to eq true
|
23
|
-
end
|
24
|
-
|
25
|
-
it "is true if 't'" do
|
26
|
-
expect("t".to_bool).to eq true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "is true if 'T'" do
|
30
|
-
expect("T".to_bool).to eq true
|
31
|
-
end
|
32
|
-
|
33
|
-
it "is false otherwise" do
|
34
|
-
expect("no".to_bool).to eq false
|
35
|
-
expect("false".to_bool).to eq false
|
36
|
-
expect("0".to_bool).to eq false
|
37
|
-
end
|
38
|
-
|
39
|
-
it "is true when using to_boolean" do
|
40
|
-
expect("true".to_boolean).to eq true
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "Integer" do
|
45
|
-
it "is true if 1" do
|
46
|
-
expect(1.to_bool).to eq true
|
47
|
-
end
|
48
|
-
|
49
|
-
it "is false otherwise" do
|
50
|
-
expect(0.to_bool).to eq false
|
51
|
-
end
|
52
|
-
|
53
|
-
it "is true when using to_boolean" do
|
54
|
-
expect(1.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
|
-
|
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,46 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_bool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
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
|
-
- Gemfile
|
37
|
-
- README.md
|
38
|
-
- Rakefile
|
39
21
|
- lib/to_bool.rb
|
40
22
|
- spec/to_bool_spec.rb
|
41
|
-
- to_bool.gemspec
|
42
23
|
homepage: http://github.com/bricker/to_bool
|
43
|
-
licenses:
|
24
|
+
licenses:
|
25
|
+
- MIT
|
44
26
|
metadata: {}
|
45
27
|
post_install_message:
|
46
28
|
rdoc_options: []
|
@@ -57,8 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
39
|
- !ruby/object:Gem::Version
|
58
40
|
version: '0'
|
59
41
|
requirements: []
|
60
|
-
|
61
|
-
rubygems_version: 2.7.6
|
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/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"`, 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 = "1.2.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
|