wannabe_bool 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90543acc9ffc1a5322b89291adfbb46e9de1beb7
4
- data.tar.gz: 823e9aaed07940f9c33e4128cbe234a0ad9ec1e6
3
+ metadata.gz: 86d39d1ce9b9db3cad81264483b7d0cedd5149cd
4
+ data.tar.gz: b7816a5392945862c9e2c40adf8cf9a54831f345
5
5
  SHA512:
6
- metadata.gz: 9139f1b720b76f1dbad81c62f2573331e592a6072ee88f0685c06bde5fad2d4eee6511c489d9082dafab2216639d99129752a3b7d5eabf956b47ec08a104cd94
7
- data.tar.gz: d022be0abce8d6ac2e6d24709ef4a74161f26fc8f59ab39e8e2a736042c3f2bfbf96a0712f92ac3eec544883ce4405b17114ebf57483c74739a2dc7c68b2565c
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 # => true
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
- 1.to_b # => true
109
-
110
- 0.to_b # => false
111
- 2.to_b # => false
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
@@ -1,7 +1,7 @@
1
1
  module WannabeBool
2
2
  module Integer
3
3
  def to_b
4
- self == 1
4
+ self != 0
5
5
  end
6
6
  end
7
7
  end
@@ -1,9 +1,15 @@
1
1
  module WannabeBool
2
2
  module Object
3
- TRUE_VALUES = %W{1 t true on y yes}.freeze
3
+ TRUE_VALUES = %W{t true on y yes}.freeze
4
4
 
5
5
  def to_b
6
- TRUE_VALUES.include?(self.to_s.strip.downcase)
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
@@ -1,3 +1,3 @@
1
1
  module WannabeBool
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -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 eq false }
6
+ it { expect(subject.to_b).to eql false }
7
7
  end
8
8
 
9
- context 'when value is 1' do
10
- subject { 1 }
11
- it { expect(subject.to_b).to eq true }
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
- (2..9).each do |value|
15
- context "when value is #{value}" do
16
- subject { value }
17
- it { expect(subject.to_b).to eq false }
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 eq true }
21
+ it { expect(subject.to_b).to eql true }
19
22
  end
20
23
  end
21
24
 
22
25
  [ '',
23
- '0', '2',
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 eq false }
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
- [ :"1", :"1 ", :" 1 ", :" 1",
43
- :t, :"t ", :" t", :" t ",
44
- :T, :"T ", :" T", :" T ",
45
- :true, :"true ", :" true", :" true ",
46
- :TRUE, :"TRUE ", :" TRUE", :" TRUE ",
47
- :on, :"on ", :" on", :" on ",
48
- :ON, :"ON ", :" ON ", :" ON ",
49
- :y, :"y ", :" y", :" y ",
50
- :Y, :"Y ", :" Y", :" Y ",
51
- :yes, :"yes ", :" yes", :" yes ",
52
- :YES, :"YES ", :" YES", :" YES "
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 eq true }
62
+ it { expect(subject.to_b).to eql true }
57
63
  end
58
64
  end
59
65
 
60
- [ :"",
61
- :"0", :"2",
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 eq false }
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.2.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-09-28 00:00:00.000000000 Z
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.5.1
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