wannabe_bool 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +26 -0
- data/.rspec +1 -0
- data/.ruby-gemset.example +1 -0
- data/.ruby-version.example +1 -0
- data/CHANGELOG.rdoc +5 -0
- data/Gemfile +2 -0
- data/README.rdoc +160 -0
- data/Rakefile +2 -0
- data/lib/wannabe_bool.rb +5 -0
- data/lib/wannabe_bool/boolean.rb +16 -0
- data/lib/wannabe_bool/integer.rb +12 -0
- data/lib/wannabe_bool/nil.rb +12 -0
- data/lib/wannabe_bool/object.rb +18 -0
- data/lib/wannabe_bool/version.rb +4 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/wannabe_bool/boolean_spec.rb +20 -0
- data/spec/wannabe_bool/integer_spec.rb +25 -0
- data/spec/wannabe_bool/nil_spec.rb +12 -0
- data/spec/wannabe_bool/object_spec.rb +81 -0
- data/wannabe_bool.gemspec +25 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 544d88e5cd01ccb05eb1f92f5c2ac2e452f20847
|
4
|
+
data.tar.gz: 299444ce40a3d1a49a46ca9dcff627c42335cf1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7bb5db69297393fbb4b0acf3bb81985c4204ad67256b71c3289432a2004478d9e90dd17d3fad0575d7a4e2964d99e91c5c670afc141a9920203579c3c497f69d
|
7
|
+
data.tar.gz: 13c18c233bf9311fbd079cb6ade863f3ff122fd113463d8094c1a7e37515f5c452b87be7dadded1d3fd1a9beb741af9649814032ebbf1042258a3e9bb158912f
|
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.ruby-gemset
|
6
|
+
.ruby-version
|
7
|
+
.yardoc
|
8
|
+
Gemfile.lock
|
9
|
+
InstalledFiles
|
10
|
+
_yardoc
|
11
|
+
coverage
|
12
|
+
doc/
|
13
|
+
lib/bundler/man
|
14
|
+
pkg
|
15
|
+
rdoc
|
16
|
+
spec/reports
|
17
|
+
test/tmp
|
18
|
+
test/version_tmp
|
19
|
+
tmp
|
20
|
+
TODO
|
21
|
+
|
22
|
+
# For MacOS:
|
23
|
+
.DS_Store
|
24
|
+
|
25
|
+
# For vim:
|
26
|
+
*.sw*
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
@@ -0,0 +1 @@
|
|
1
|
+
wannabe_bool
|
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.2
|
data/CHANGELOG.rdoc
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
= Wannabe Bool
|
2
|
+
|
3
|
+
If string, integer, symbol and nil values wanna be a boolean value, they can.
|
4
|
+
|
5
|
+
== Installing
|
6
|
+
|
7
|
+
=== Gemfile
|
8
|
+
gem 'wannabe_bool'
|
9
|
+
|
10
|
+
=== Direct installation
|
11
|
+
$ gem install wannabe_bool
|
12
|
+
|
13
|
+
|
14
|
+
== Using
|
15
|
+
|
16
|
+
Method <b>to_b</b> method is available on String, Symbol, Integer, TrueClass, FalseClass and NilClass.
|
17
|
+
|
18
|
+
require 'wannabe_bool'
|
19
|
+
|
20
|
+
# ----------------------------------------
|
21
|
+
# String
|
22
|
+
# ----------------------------------------
|
23
|
+
'1'.to_b # => true
|
24
|
+
't'.to_b # => true
|
25
|
+
'T'.to_b # => true
|
26
|
+
'true'.to_b # => true
|
27
|
+
'TRUE'.to_b # => true
|
28
|
+
'on'.to_b # => true
|
29
|
+
'ON'.to_b # => true
|
30
|
+
'y'.to_b # => true
|
31
|
+
'yes'.to_b # => true
|
32
|
+
'YES'.to_b # => true
|
33
|
+
|
34
|
+
' 1 '.to_b # => true
|
35
|
+
' t '.to_b # => true
|
36
|
+
' T '.to_b # => true
|
37
|
+
' true '.to_b # => true
|
38
|
+
' TRUE '.to_b # => true
|
39
|
+
' on '.to_b # => true
|
40
|
+
' ON '.to_b # => true
|
41
|
+
' y '.to_b # => true
|
42
|
+
'Y'.to_b # => true
|
43
|
+
' Y '.to_b # => true
|
44
|
+
' yes '.to_b # => true
|
45
|
+
' YES '.to_b # => true
|
46
|
+
|
47
|
+
''.to_b # => false
|
48
|
+
'0'.to_b # => false
|
49
|
+
'2'.to_b # => false
|
50
|
+
'f'.to_b # => false
|
51
|
+
'F'.to_b # => false
|
52
|
+
'false'.to_b # => false
|
53
|
+
'FALSE'.to_b # => false
|
54
|
+
'off'.to_b # => false
|
55
|
+
'OFF'.to_b # => false
|
56
|
+
'n'.to_b # => false
|
57
|
+
'N'.to_b # => false
|
58
|
+
'no'.to_b # => false
|
59
|
+
'NO'.to_b # => false
|
60
|
+
'not'.to_b # => false
|
61
|
+
'NOT'.to_b # => false
|
62
|
+
'wherever'.to_b # => false
|
63
|
+
|
64
|
+
# ----------------------------------------
|
65
|
+
# Symbol
|
66
|
+
# ----------------------------------------
|
67
|
+
:1.to_b # => true
|
68
|
+
:t.to_b # => true
|
69
|
+
:T.to_b # => true
|
70
|
+
:true.to_b # => true
|
71
|
+
:TRUE.to_b # => true
|
72
|
+
:on.to_b # => true
|
73
|
+
:ON.to_b # => true
|
74
|
+
:y.to_b # => true
|
75
|
+
:Y.to_b # => true
|
76
|
+
:yes.to_b # => true
|
77
|
+
:YES.to_b # => true
|
78
|
+
|
79
|
+
:f.to_b # => false
|
80
|
+
:F.to_b # => false
|
81
|
+
:false.to_b # => false
|
82
|
+
:FALSE.to_b # => false
|
83
|
+
:off.to_b # => false
|
84
|
+
:OFF.to_b # => false
|
85
|
+
:n.to_b # => false
|
86
|
+
:N.to_b # => false
|
87
|
+
:no.to_b # => false
|
88
|
+
:NO.to_b # => false
|
89
|
+
:not.to_b # => false
|
90
|
+
:NOT.to_b # => false
|
91
|
+
:wherever.to_b # => false
|
92
|
+
|
93
|
+
# ----------------------------------------
|
94
|
+
# Integer
|
95
|
+
# ----------------------------------------
|
96
|
+
1.to_b # => true
|
97
|
+
|
98
|
+
0.to_b # => false
|
99
|
+
2.to_b # => false
|
100
|
+
|
101
|
+
# ----------------------------------------
|
102
|
+
# TrueClass
|
103
|
+
# ----------------------------------------
|
104
|
+
true.to_b # => true
|
105
|
+
|
106
|
+
# ----------------------------------------
|
107
|
+
# FalseClass
|
108
|
+
# ----------------------------------------
|
109
|
+
false.to_b # => false
|
110
|
+
|
111
|
+
# ----------------------------------------
|
112
|
+
# NilClass
|
113
|
+
# ----------------------------------------
|
114
|
+
nil.to_b # => false
|
115
|
+
|
116
|
+
== Author
|
117
|
+
- {Fernando Hamasaki de Amorim (prodis)}[http://prodis.blog.br]
|
118
|
+
|
119
|
+
|
120
|
+
== Contributing to wannabe_bool
|
121
|
+
|
122
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
123
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
124
|
+
* Fork the project.
|
125
|
+
* Start a feature/bugfix branch.
|
126
|
+
* Commit and push until you are happy with your contribution.
|
127
|
+
* Don't forget to rebase with branch master in main project before submit the pull request.
|
128
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
129
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
130
|
+
|
131
|
+
|
132
|
+
== Copyright
|
133
|
+
|
134
|
+
(The MIT License)
|
135
|
+
|
136
|
+
{Prodis a.k.a. Fernando Hamasaki de Amorim}[http://prodis.blog.br]
|
137
|
+
|
138
|
+
http://prodis.net.br/images/prodis_150.gif
|
139
|
+
|
140
|
+
Copyright (c) 2014 Prodis
|
141
|
+
|
142
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
143
|
+
a copy of this software and associated documentation files (the
|
144
|
+
"Software"), to deal in the Software without restriction, including
|
145
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
146
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
147
|
+
permit persons to whom the Software is furnished to do so, subject to
|
148
|
+
the following conditions:
|
149
|
+
|
150
|
+
The above copyright notice and this permission notice shall be
|
151
|
+
included in all copies or substantial portions of the Software.
|
152
|
+
|
153
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
154
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
155
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
156
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
157
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
158
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
159
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
160
|
+
|
data/Rakefile
ADDED
data/lib/wannabe_bool.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module WannabeBool
|
3
|
+
module Object
|
4
|
+
TRUE_VALUES = %W{1 t true on y yes}.freeze
|
5
|
+
|
6
|
+
def to_b
|
7
|
+
TRUE_VALUES.include?(self.to_s.strip.downcase)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class String
|
13
|
+
include WannabeBool::Object
|
14
|
+
end
|
15
|
+
|
16
|
+
class Symbol
|
17
|
+
include WannabeBool::Object
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe WannabeBool::Boolean do
|
5
|
+
context TrueClass do
|
6
|
+
subject { true }
|
7
|
+
|
8
|
+
describe '#to_b' do
|
9
|
+
it { expect(subject.to_b).to eq true }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context FalseClass do
|
14
|
+
subject { false }
|
15
|
+
|
16
|
+
describe '#to_b' do
|
17
|
+
it { expect(subject.to_b).to eq false }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe WannabeBool::Integer do
|
5
|
+
context Integer do
|
6
|
+
describe '#to_b' do
|
7
|
+
context 'when value is 0' do
|
8
|
+
subject { 0 }
|
9
|
+
it { expect(subject.to_b).to eq false }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when value is 1' do
|
13
|
+
subject { 1 }
|
14
|
+
it { expect(subject.to_b).to eq true }
|
15
|
+
end
|
16
|
+
|
17
|
+
(2..9).each do |value|
|
18
|
+
context "when value is #{value}" do
|
19
|
+
subject { value }
|
20
|
+
it { expect(subject.to_b).to eq false }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe WannabeBool::Object do
|
5
|
+
context String do
|
6
|
+
describe '#to_b' do
|
7
|
+
[ '1', '1 ', ' 1', ' 1 ',
|
8
|
+
't', 't ', ' t', ' t ',
|
9
|
+
'T', 'T ', ' T', ' T ',
|
10
|
+
'true', 'true ', ' true', ' true ',
|
11
|
+
'TRUE', 'TRUE ', ' TRUE', ' TRUE ',
|
12
|
+
'on', 'on ', ' on', ' on ',
|
13
|
+
'ON', 'ON ', ' ON ', ' ON ',
|
14
|
+
'y', 'y ', ' y', ' y ',
|
15
|
+
'Y', 'Y ', ' Y', ' Y ',
|
16
|
+
'yes', 'yes ', ' yes', ' yes ',
|
17
|
+
'YES', 'YES ', ' YES', ' YES '
|
18
|
+
].each do |value|
|
19
|
+
context "when value is '#{value}'" do
|
20
|
+
subject { value }
|
21
|
+
it { expect(subject.to_b).to eq true }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
[ '',
|
26
|
+
'0', '2',
|
27
|
+
'f', 'F',
|
28
|
+
'false', 'FALSE',
|
29
|
+
'off', 'OFF',
|
30
|
+
'n', 'N',
|
31
|
+
'no', 'NO',
|
32
|
+
'not', 'NOT',
|
33
|
+
'wherever', 'Prodis'
|
34
|
+
].each do |value|
|
35
|
+
context "when value is '#{value}'" do
|
36
|
+
subject { value }
|
37
|
+
it { expect(subject.to_b).to eq false }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context Symbol do
|
44
|
+
describe '#to_b' do
|
45
|
+
[ :"1", :"1 ", :" 1 ", :" 1",
|
46
|
+
:t, :"t ", :" t", :" t ",
|
47
|
+
:T, :"T ", :" T", :" T ",
|
48
|
+
:true, :"true ", :" true", :" true ",
|
49
|
+
:TRUE, :"TRUE ", :" TRUE", :" TRUE ",
|
50
|
+
:on, :"on ", :" on", :" on ",
|
51
|
+
:ON, :"ON ", :" ON ", :" ON ",
|
52
|
+
:y, :"y ", :" y", :" y ",
|
53
|
+
:Y, :"Y ", :" Y", :" Y ",
|
54
|
+
:yes, :"yes ", :" yes", :" yes ",
|
55
|
+
:YES, :"YES ", :" YES", :" YES "
|
56
|
+
].each do |value|
|
57
|
+
context "when value is '#{value}'" do
|
58
|
+
subject { value }
|
59
|
+
it { expect(subject.to_b).to eq true }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
[ :"",
|
64
|
+
:"0", :"2",
|
65
|
+
:f, :F,
|
66
|
+
:false,
|
67
|
+
:FALSE,
|
68
|
+
:off, :OFF,
|
69
|
+
:n, :N,
|
70
|
+
:no, :NO,
|
71
|
+
:not, :NOT,
|
72
|
+
:wherever, :Prodis
|
73
|
+
].each do |value|
|
74
|
+
context "when value is '#{value}'" do
|
75
|
+
subject { value }
|
76
|
+
it { expect(subject.to_b).to eq false }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'wannabe_bool/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'wannabe_bool'
|
7
|
+
spec.version = WannabeBool::VERSION
|
8
|
+
spec.authors = ['Prodis a.k.a. Fernando Hamasaki de Amorim']
|
9
|
+
spec.email = ['prodis@gmail.com']
|
10
|
+
spec.description = 'If string, integer, symbol and nil values wanna be a boolean value, they can.'
|
11
|
+
spec.summary = spec.description
|
12
|
+
spec.homepage = 'https://github.com/prodis/wannabe_bool'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.platform = Gem::Platform::RUBY
|
21
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 1.9.3')
|
22
|
+
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wannabe_bool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Prodis a.k.a. Fernando Hamasaki de Amorim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
description: If string, integer, symbol and nil values wanna be a boolean value, they
|
42
|
+
can.
|
43
|
+
email:
|
44
|
+
- prodis@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- ".ruby-gemset.example"
|
52
|
+
- ".ruby-version.example"
|
53
|
+
- CHANGELOG.rdoc
|
54
|
+
- Gemfile
|
55
|
+
- README.rdoc
|
56
|
+
- Rakefile
|
57
|
+
- lib/wannabe_bool.rb
|
58
|
+
- lib/wannabe_bool/boolean.rb
|
59
|
+
- lib/wannabe_bool/integer.rb
|
60
|
+
- lib/wannabe_bool/nil.rb
|
61
|
+
- lib/wannabe_bool/object.rb
|
62
|
+
- lib/wannabe_bool/version.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
- spec/wannabe_bool/boolean_spec.rb
|
65
|
+
- spec/wannabe_bool/integer_spec.rb
|
66
|
+
- spec/wannabe_bool/nil_spec.rb
|
67
|
+
- spec/wannabe_bool/object_spec.rb
|
68
|
+
- wannabe_bool.gemspec
|
69
|
+
homepage: https://github.com/prodis/wannabe_bool
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.9.3
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: If string, integer, symbol and nil values wanna be a boolean value, they
|
93
|
+
can.
|
94
|
+
test_files:
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/wannabe_bool/boolean_spec.rb
|
97
|
+
- spec/wannabe_bool/integer_spec.rb
|
98
|
+
- spec/wannabe_bool/nil_spec.rb
|
99
|
+
- spec/wannabe_bool/object_spec.rb
|