wannabe_bool 0.2.0 → 0.3.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/CHANGELOG.md +1 -0
- data/README.md +13 -7
- data/lib/wannabe_bool/integer.rb +1 -1
- data/lib/wannabe_bool/object.rb +8 -2
- data/lib/wannabe_bool/version.rb +1 -1
- data/spec/wannabe_bool/integer_spec.rb +14 -8
- data/spec/wannabe_bool/object_spec.rb +24 -18
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86d39d1ce9b9db3cad81264483b7d0cedd5149cd
|
4
|
+
data.tar.gz: b7816a5392945862c9e2c40adf8cf9a54831f345
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e6bbfb88c6fe95f364ab6637b64bc09c56ff33a0a93e99db0415c12d77c2325c7a78c93acf628899f954e17b1bd3c7c508bca6960a016a0498bf8fd874e74ab
|
7
|
+
data.tar.gz: ec10d991c5f04f89c1e3687833bf774682c7bc12a1c13cd07b78785167c2b90bf55f6921e3e73e7038bfe4e842f16b1a1b344734b6eb7409cf1002c38a67f5cd
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
| Version | Changes |
|
2
2
|
| ------- | ------- |
|
3
|
+
| 0.3.0 | Fix integer to boolean conversion. [Issue #2](https://github.com/prodis/wannabe_bool/issues/2) |
|
3
4
|
| 0.2.0 | Minimal required Ruby version is 2.0.0 from now. |
|
4
5
|
| 0.1.1 | Remove post install message. |
|
5
6
|
| 0.1.0 | New `WannabeBool::Attributes` module to create predicate methods. |
|
data/README.md
CHANGED
@@ -33,6 +33,9 @@ require 'wannabe_bool'
|
|
33
33
|
#### String
|
34
34
|
```ruby
|
35
35
|
'1'.to_b # => true
|
36
|
+
'2'.to_b # => true
|
37
|
+
'-1'.to_b # => true
|
38
|
+
'-2'.to_b # => true
|
36
39
|
't'.to_b # => true
|
37
40
|
'T'.to_b # => true
|
38
41
|
'true'.to_b # => true
|
@@ -44,6 +47,9 @@ require 'wannabe_bool'
|
|
44
47
|
'YES'.to_b # => true
|
45
48
|
|
46
49
|
' 1 '.to_b # => true
|
50
|
+
' 2 '.to_b # => true
|
51
|
+
' -1 '.to_b # => true
|
52
|
+
' -2 '.to_b # => true
|
47
53
|
' t '.to_b # => true
|
48
54
|
' T '.to_b # => true
|
49
55
|
' true '.to_b # => true
|
@@ -58,7 +64,6 @@ require 'wannabe_bool'
|
|
58
64
|
|
59
65
|
''.to_b # => false
|
60
66
|
'0'.to_b # => false
|
61
|
-
'2'.to_b # => false
|
62
67
|
'f'.to_b # => false
|
63
68
|
'F'.to_b # => false
|
64
69
|
'false'.to_b # => false
|
@@ -76,7 +81,7 @@ require 'wannabe_bool'
|
|
76
81
|
|
77
82
|
#### Symbol
|
78
83
|
```ruby
|
79
|
-
:1.to_b
|
84
|
+
:'1'.to_b # => true
|
80
85
|
:t.to_b # => true
|
81
86
|
:T.to_b # => true
|
82
87
|
:true.to_b # => true
|
@@ -105,10 +110,11 @@ require 'wannabe_bool'
|
|
105
110
|
|
106
111
|
#### Integer
|
107
112
|
```ruby
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
113
|
+
0.to_b # => false
|
114
|
+
1.to_b # => true
|
115
|
+
2.to_b # => true
|
116
|
+
-1.to_b # => true
|
117
|
+
-2.to_b # => true
|
112
118
|
```
|
113
119
|
|
114
120
|
#### TrueClass
|
@@ -126,7 +132,7 @@ false.to_b # => false
|
|
126
132
|
nil.to_b # => false
|
127
133
|
```
|
128
134
|
|
129
|
-
Creating predicate methods
|
135
|
+
#### Creating predicate methods
|
130
136
|
|
131
137
|
```ruby
|
132
138
|
class Fake
|
data/lib/wannabe_bool/integer.rb
CHANGED
data/lib/wannabe_bool/object.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
module WannabeBool
|
2
2
|
module Object
|
3
|
-
TRUE_VALUES = %W{
|
3
|
+
TRUE_VALUES = %W{t true on y yes}.freeze
|
4
4
|
|
5
5
|
def to_b
|
6
|
-
|
6
|
+
value = self.to_s.strip.downcase
|
7
|
+
|
8
|
+
if TRUE_VALUES.include?(value)
|
9
|
+
true
|
10
|
+
else
|
11
|
+
value.to_i.to_b
|
12
|
+
end
|
7
13
|
end
|
8
14
|
end
|
9
15
|
end
|
data/lib/wannabe_bool/version.rb
CHANGED
@@ -3,18 +3,24 @@ describe WannabeBool::Integer do
|
|
3
3
|
describe '#to_b' do
|
4
4
|
context 'when value is 0' do
|
5
5
|
subject { 0 }
|
6
|
-
it { expect(subject.to_b).to
|
6
|
+
it { expect(subject.to_b).to eql false }
|
7
7
|
end
|
8
8
|
|
9
|
-
context '
|
10
|
-
|
11
|
-
|
9
|
+
context 'positive values' do
|
10
|
+
(1..9).each do |value|
|
11
|
+
context "when value is #{value}" do
|
12
|
+
subject { value }
|
13
|
+
it { expect(subject.to_b).to eql true }
|
14
|
+
end
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
context 'negative values' do
|
19
|
+
(-9..-1).each do |value|
|
20
|
+
context "when value is #{value}" do
|
21
|
+
subject { value }
|
22
|
+
it { expect(subject.to_b).to eql true }
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
@@ -2,6 +2,9 @@ describe WannabeBool::Object do
|
|
2
2
|
context String do
|
3
3
|
describe '#to_b' do
|
4
4
|
[ '1', '1 ', ' 1', ' 1 ',
|
5
|
+
'2', '2 ', ' 2', ' 2 ',
|
6
|
+
'-1', '-1 ', ' -1', ' -1 ',
|
7
|
+
'-2', '-2 ', ' -2', ' -2 ',
|
5
8
|
't', 't ', ' t', ' t ',
|
6
9
|
'T', 'T ', ' T', ' T ',
|
7
10
|
'true', 'true ', ' true', ' true ',
|
@@ -15,12 +18,12 @@ describe WannabeBool::Object do
|
|
15
18
|
].each do |value|
|
16
19
|
context "when value is '#{value}'" do
|
17
20
|
subject { value }
|
18
|
-
it { expect(subject.to_b).to
|
21
|
+
it { expect(subject.to_b).to eql true }
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
25
|
[ '',
|
23
|
-
'0',
|
26
|
+
'0',
|
24
27
|
'f', 'F',
|
25
28
|
'false', 'FALSE',
|
26
29
|
'off', 'OFF',
|
@@ -31,7 +34,7 @@ describe WannabeBool::Object do
|
|
31
34
|
].each do |value|
|
32
35
|
context "when value is '#{value}'" do
|
33
36
|
subject { value }
|
34
|
-
it { expect(subject.to_b).to
|
37
|
+
it { expect(subject.to_b).to eql false }
|
35
38
|
end
|
36
39
|
end
|
37
40
|
end
|
@@ -39,26 +42,29 @@ describe WannabeBool::Object do
|
|
39
42
|
|
40
43
|
context Symbol do
|
41
44
|
describe '#to_b' do
|
42
|
-
[ :
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
45
|
+
[ :'1', :'1 ', :' 1 ', :' 1',
|
46
|
+
:'2', :'2 ', :' 2 ', :' 2',
|
47
|
+
:'-1', :'-1 ', :' -1 ', :' -1',
|
48
|
+
:'-2', :'-2 ', :' -2 ', :' -2',
|
49
|
+
:t, :'t ', :' t', :' t ',
|
50
|
+
:T, :'T ', :' T', :' T ',
|
51
|
+
:true, :'true ', :' true', :' true ',
|
52
|
+
:TRUE, :'TRUE ', :' TRUE', :' TRUE ',
|
53
|
+
:on, :'on ', :' on', :' on ',
|
54
|
+
:ON, :'ON ', :' ON ', :' ON ',
|
55
|
+
:y, :'y ', :' y', :' y ',
|
56
|
+
:Y, :'Y ', :' Y', :' Y ',
|
57
|
+
:yes, :'yes ', :' yes', :' yes ',
|
58
|
+
:YES, :'YES ', :' YES', :' YES '
|
53
59
|
].each do |value|
|
54
60
|
context "when value is '#{value}'" do
|
55
61
|
subject { value }
|
56
|
-
it { expect(subject.to_b).to
|
62
|
+
it { expect(subject.to_b).to eql true }
|
57
63
|
end
|
58
64
|
end
|
59
65
|
|
60
|
-
[ :
|
61
|
-
:
|
66
|
+
[ :'',
|
67
|
+
:'0',
|
62
68
|
:f, :F,
|
63
69
|
:false,
|
64
70
|
:FALSE,
|
@@ -70,7 +76,7 @@ describe WannabeBool::Object do
|
|
70
76
|
].each do |value|
|
71
77
|
context "when value is '#{value}'" do
|
72
78
|
subject { value }
|
73
|
-
it { expect(subject.to_b).to
|
79
|
+
it { expect(subject.to_b).to eql false }
|
74
80
|
end
|
75
81
|
end
|
76
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wannabe_bool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Prodis a.k.a. Fernando Hamasaki de Amorim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.4.
|
104
|
+
rubygems_version: 2.4.6
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: 'If string, integer, symbol and nil values wanna be a boolean value, they
|