to_bool 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/README.md +8 -1
- data/lib/to_bool.rb +17 -1
- data/spec/to_bool_spec.rb +41 -10
- data/to_bool.gemspec +3 -3
- metadata +11 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 04a652783b660a09e1e4ee760a7b0cfd33ee5b59d40007014801220519c00031
|
4
|
+
data.tar.gz: ec92c3478486cec25f766c5a8edcfcad4774f2ff203a89433326bbe257c89c8a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc02600d89b7800a3519f7412727e2a437b7a57cc2c73b4ad6669b422b7e833254f9f3de13067af7ccc3693787d748026661e36dec863e7216c4f10c7ec8e0d1
|
7
|
+
data.tar.gz: e22d990b2df6806629134f78aaabd20bb46c399cc9ce194c5a41652c08fef836bc2d8ea9993b3f47159f597d78ab8f7a1d6c05b8a64d5b436b366b7c35df86ab
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -15,12 +15,19 @@ Call `to_bool` on any object. It will *usually* return false, except:
|
|
15
15
|
* String: `"true"`, `"1"`, and `"yes"` are true
|
16
16
|
* Integer: `1` is true
|
17
17
|
* TrueClass: `true` is true
|
18
|
+
* Symbol: :true is true
|
18
19
|
|
19
20
|
See the spec, it pretty much maps it out.
|
20
21
|
|
21
22
|
## Contributing
|
22
23
|
|
23
|
-
Yes
|
24
|
+
Yes!
|
25
|
+
|
26
|
+
### Running Tests
|
27
|
+
|
28
|
+
```
|
29
|
+
bundle exec rspec
|
30
|
+
```
|
24
31
|
|
25
32
|
|
26
33
|
## License
|
data/lib/to_bool.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
class String
|
2
2
|
def to_bool
|
3
|
-
%w{ 1 true yes }.include? self.downcase
|
3
|
+
%w{ 1 true yes t }.include? self.downcase
|
4
4
|
end
|
5
|
+
|
6
|
+
alias_method :to_boolean, :to_bool
|
5
7
|
end
|
6
8
|
|
7
9
|
class Integer
|
8
10
|
def to_bool
|
9
11
|
self == 1
|
10
12
|
end
|
13
|
+
|
14
|
+
alias_method :to_boolean, :to_bool
|
11
15
|
end
|
12
16
|
|
13
17
|
|
@@ -15,10 +19,22 @@ class TrueClass
|
|
15
19
|
def to_bool
|
16
20
|
self
|
17
21
|
end
|
22
|
+
|
23
|
+
alias_method :to_boolean, :to_bool
|
18
24
|
end
|
19
25
|
|
20
26
|
class Object
|
21
27
|
def to_bool
|
22
28
|
false
|
23
29
|
end
|
30
|
+
|
31
|
+
alias_method :to_boolean, :to_bool
|
32
|
+
end
|
33
|
+
|
34
|
+
class Symbol
|
35
|
+
def to_bool
|
36
|
+
self == :true
|
37
|
+
end
|
38
|
+
|
39
|
+
alias_method :to_boolean, :to_bool
|
24
40
|
end
|
data/spec/to_bool_spec.rb
CHANGED
@@ -3,42 +3,73 @@ Bundler.require
|
|
3
3
|
|
4
4
|
describe "String" do
|
5
5
|
it "is true if yes" do
|
6
|
-
"yes".to_bool.
|
6
|
+
expect("yes".to_bool).to eq true
|
7
7
|
end
|
8
8
|
|
9
9
|
it "is true if '1'" do
|
10
|
-
"1".to_bool.
|
10
|
+
expect("1".to_bool).to eq true
|
11
11
|
end
|
12
12
|
|
13
13
|
it "is true if 'true'" do
|
14
|
-
"true".to_bool.
|
14
|
+
expect("true".to_bool).to eq true
|
15
15
|
end
|
16
16
|
|
17
17
|
it "is false otherwise" do
|
18
|
-
"no".to_bool.
|
19
|
-
"false".to_bool.
|
20
|
-
"0".to_bool.
|
18
|
+
expect("no".to_bool).to eq false
|
19
|
+
expect("false".to_bool).to eq false
|
20
|
+
expect("0".to_bool).to eq false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is true when using to_boolean" do
|
24
|
+
expect("true".to_boolean).to eq true
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
28
|
describe "Integer" do
|
25
29
|
it "is true if 1" do
|
26
|
-
1.to_bool.
|
30
|
+
expect(1.to_bool).to eq true
|
27
31
|
end
|
28
32
|
|
29
33
|
it "is false otherwise" do
|
30
|
-
0.to_bool.
|
34
|
+
expect(0.to_bool).to eq false
|
35
|
+
end
|
36
|
+
|
37
|
+
it "is true when using to_boolean" do
|
38
|
+
expect(1.to_boolean).to eq true
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
34
42
|
describe "TrueClass" do
|
35
43
|
it "is true" do
|
36
|
-
true.to_bool.
|
44
|
+
expect(true.to_bool).to eq true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "is true when using to_boolean" do
|
48
|
+
expect(true.to_boolean).to eq true
|
37
49
|
end
|
38
50
|
end
|
39
51
|
|
40
52
|
describe "Object" do
|
41
53
|
it "is false by default" do
|
42
|
-
Object.new.to_bool.
|
54
|
+
expect(Object.new.to_bool).to eq false
|
55
|
+
end
|
56
|
+
|
57
|
+
it "is false when using to_boolean" do
|
58
|
+
expect(Object.new.to_boolean).to eq false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "Symbol" do
|
63
|
+
it "is true if :true" do
|
64
|
+
expect(:true.to_bool).to eq true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "is false otherwise" do
|
68
|
+
expect(:false.to_bool).to eq false
|
69
|
+
expect(:hoge.to_bool).to eq false
|
70
|
+
end
|
71
|
+
|
72
|
+
it "is true when using to_boolean" do
|
73
|
+
expect(:true.to_bool).to eq true
|
43
74
|
end
|
44
75
|
end
|
data/to_bool.gemspec
CHANGED
@@ -4,9 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "to_bool"
|
7
|
-
gem.version = "1.0
|
7
|
+
gem.version = "1.1.0"
|
8
8
|
gem.authors = ["Bryan Ricker"]
|
9
|
-
gem.email = ["
|
9
|
+
gem.email = ["bryancricker@gmail.com"]
|
10
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
11
|
gem.summary = %q{Convert any object naturally into a boolean}
|
12
12
|
gem.homepage = "http://github.com/bricker/to_bool"
|
@@ -15,6 +15,6 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
17
|
gem.require_paths = ["lib"]
|
18
|
-
|
18
|
+
|
19
19
|
gem.add_development_dependency "rspec", [">= 0"]
|
20
20
|
end
|
metadata
CHANGED
@@ -1,41 +1,38 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_bool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bryan Ricker
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-08-18 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: Super-simple gem that extends some Ruby classes with a "to_bool" method,
|
31
28
|
which converts any object naturally into a boolean.
|
32
29
|
email:
|
33
|
-
-
|
30
|
+
- bryancricker@gmail.com
|
34
31
|
executables: []
|
35
32
|
extensions: []
|
36
33
|
extra_rdoc_files: []
|
37
34
|
files:
|
38
|
-
- .gitignore
|
35
|
+
- ".gitignore"
|
39
36
|
- Gemfile
|
40
37
|
- README.md
|
41
38
|
- Rakefile
|
@@ -44,27 +41,26 @@ files:
|
|
44
41
|
- to_bool.gemspec
|
45
42
|
homepage: http://github.com/bricker/to_bool
|
46
43
|
licenses: []
|
44
|
+
metadata: {}
|
47
45
|
post_install_message:
|
48
46
|
rdoc_options: []
|
49
47
|
require_paths:
|
50
48
|
- lib
|
51
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
50
|
requirements:
|
54
|
-
- -
|
51
|
+
- - ">="
|
55
52
|
- !ruby/object:Gem::Version
|
56
53
|
version: '0'
|
57
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
55
|
requirements:
|
60
|
-
- -
|
56
|
+
- - ">="
|
61
57
|
- !ruby/object:Gem::Version
|
62
58
|
version: '0'
|
63
59
|
requirements: []
|
64
60
|
rubyforge_project:
|
65
|
-
rubygems_version:
|
61
|
+
rubygems_version: 2.7.6
|
66
62
|
signing_key:
|
67
|
-
specification_version:
|
63
|
+
specification_version: 4
|
68
64
|
summary: Convert any object naturally into a boolean
|
69
65
|
test_files:
|
70
66
|
- spec/to_bool_spec.rb
|