boolean_class 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.yardopts +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/boolean_class.gemspec +40 -0
- data/lib/boolean_class.rb +4 -0
- data/lib/boolean_class/boolean.rb +15 -0
- data/lib/boolean_class/conversion.rb +23 -0
- data/lib/boolean_class/core_ext/all.rb +41 -0
- data/lib/boolean_class/version.rb +3 -0
- data/spec/conversion_spec.rb +14 -0
- data/spec/inheritance_spec.rb +19 -0
- data/spec/spec_helper.rb +12 -0
- metadata +141 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Leo Gallucci
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# BooleanClass
|
2
|
+
|
3
|
+
Performs type conversion from anything to true:TrueClass / false:FalseClass
|
4
|
+
|
5
|
+
Similar to [boolean][] gem but:
|
6
|
+
|
7
|
+
- without parse_bool()
|
8
|
+
- without raising exceptions
|
9
|
+
- without to_bool() to_b() methods
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'boolean_class'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install boolean_class
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Just `require 'boolean_class'` and then use it.
|
28
|
+
|
29
|
+
### As a conversion method Boolean()
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'boolean_class'
|
33
|
+
|
34
|
+
# Example true values
|
35
|
+
Boolean(true) #=> true
|
36
|
+
Boolean(999) #=> true
|
37
|
+
Boolean(0) #=> true
|
38
|
+
|
39
|
+
# Example false values
|
40
|
+
Boolean(false) #=> false
|
41
|
+
Boolean(nil) #=> false
|
42
|
+
```
|
43
|
+
|
44
|
+
### As data type checking / validation
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
require 'boolean_class'
|
48
|
+
|
49
|
+
# Instance type checking
|
50
|
+
true.is_a?(Boolean) #=> true
|
51
|
+
false.is_a?(Boolean) #=> true
|
52
|
+
0.is_a?(Boolean) #=> false
|
53
|
+
nil.is_a?(Boolean) #=> false
|
54
|
+
(0==1).is_a?(Boolean) #=> true
|
55
|
+
|
56
|
+
# Class type checking
|
57
|
+
Object < Boolean #=> nil (false)
|
58
|
+
NilClass < Boolean #=> nil (false)
|
59
|
+
Class < Boolean #=> nil (false)
|
60
|
+
TrueClass < Boolean #=> true
|
61
|
+
FalseClass < Boolean #=> true
|
62
|
+
```
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create new Pull Request
|
71
|
+
|
72
|
+
[boolean]: http://rubygems.org/gems/boolean
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'boolean_class/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
|
8
|
+
gem.platform = Gem::Platform::RUBY
|
9
|
+
gem.name = "boolean_class"
|
10
|
+
gem.version = BooleanClass::VERSION
|
11
|
+
gem.summary = %q{Performs type conversion from anything to true:TrueClass / false:FalseClass}
|
12
|
+
gem.description = <<-DESC
|
13
|
+
Performs type conversion from anything to true:TrueClass / false:FalseClass
|
14
|
+
|
15
|
+
Similar to boolean gem but:
|
16
|
+
- without parse_bool()
|
17
|
+
- without raising exceptions
|
18
|
+
- without to_bool() to_b() methods
|
19
|
+
DESC
|
20
|
+
|
21
|
+
gem.required_ruby_version = '>= 1.9.3'
|
22
|
+
gem.required_rubygems_version = '>= 1.8.11'
|
23
|
+
|
24
|
+
gem.license = 'MIT'
|
25
|
+
|
26
|
+
gem.authors = ["Leo Gallucci"]
|
27
|
+
gem.email = ["elgalu3@gmail.com"]
|
28
|
+
gem.homepage = "https://github.com/elgalu/boolean_class"
|
29
|
+
|
30
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
31
|
+
gem.files = `git ls-files`.split($/)
|
32
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
33
|
+
gem.require_paths = ["lib"]
|
34
|
+
|
35
|
+
gem.add_development_dependency "rake", "~> 10.0"
|
36
|
+
gem.add_development_dependency "rspec", "~> 2.12"
|
37
|
+
gem.add_development_dependency "redcarpet", "~> 2.2"
|
38
|
+
gem.add_development_dependency "yard", "~> 0.8"
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# A module with no code within it.
|
2
|
+
# Just meant to be included, that's all.
|
3
|
+
#
|
4
|
+
# @example Instance type checking
|
5
|
+
# 0.is_a?(Boolean) #=> false
|
6
|
+
# nil.is_a?(Boolean) #=> false
|
7
|
+
#
|
8
|
+
# @example Class type checking
|
9
|
+
# Object < Boolean #=> nil (false)
|
10
|
+
# NilClass < Boolean #=> nil (false)
|
11
|
+
# Class < Boolean #=> nil (false)
|
12
|
+
#
|
13
|
+
# @see TrueClass
|
14
|
+
# @see FalseClass
|
15
|
+
module Boolean; end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module BooleanClass
|
2
|
+
module Conversion
|
3
|
+
# Performs type conversion from anything to true/false
|
4
|
+
#
|
5
|
+
# @param [Object] value the object to coerce
|
6
|
+
#
|
7
|
+
# @return [Boolean] false when *value* is either false or nil
|
8
|
+
# otherwise returns true
|
9
|
+
#
|
10
|
+
# @example True values
|
11
|
+
# Boolean(true) #=> true
|
12
|
+
# Boolean(999) #=> true
|
13
|
+
# Boolean(0) #=> true
|
14
|
+
#
|
15
|
+
# @example False values
|
16
|
+
# Boolean(false) #=> false
|
17
|
+
# Boolean(nil) #=> false
|
18
|
+
#
|
19
|
+
def Boolean(value)
|
20
|
+
value ? true : false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'boolean_class/boolean'
|
2
|
+
require "boolean_class/conversion"
|
3
|
+
|
4
|
+
# Make Boolean() conversion method possible on any scope
|
5
|
+
#
|
6
|
+
# @see BooleanClass::Conversion
|
7
|
+
class Object
|
8
|
+
# Polite monkey patching:
|
9
|
+
# Instead of defining Boolean() directly in Kernel i explicitly inlude a module
|
10
|
+
# So anyone can track later on monkey patches to core modules
|
11
|
+
include BooleanClass::Conversion
|
12
|
+
end
|
13
|
+
|
14
|
+
# Make possible instance type and class inheritance checking
|
15
|
+
#
|
16
|
+
# @example Instance type checking
|
17
|
+
# true.is_a?(Boolean) #=> true
|
18
|
+
#
|
19
|
+
# @example Class type checking
|
20
|
+
# TrueClass < Boolean #=> true
|
21
|
+
#
|
22
|
+
# @see Boolean
|
23
|
+
# @see FalseClass
|
24
|
+
class TrueClass
|
25
|
+
include Boolean
|
26
|
+
end
|
27
|
+
|
28
|
+
# Make possible instance type and class inheritance checking
|
29
|
+
#
|
30
|
+
# @example Instance type checking
|
31
|
+
# false.is_a?(Boolean) #=> true
|
32
|
+
# (0==1).is_a?(Boolean) #=> true
|
33
|
+
#
|
34
|
+
# @example Class type checking
|
35
|
+
# FalseClass < Boolean #=> true
|
36
|
+
#
|
37
|
+
# @see Boolean
|
38
|
+
# @see TrueClass
|
39
|
+
class FalseClass
|
40
|
+
include Boolean
|
41
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#Boolean' do
|
4
|
+
it 'converts true expressions to true:TrueClass' do
|
5
|
+
Boolean(true).should be(true)
|
6
|
+
Boolean(999).should be(true)
|
7
|
+
Boolean(0).should be(true)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'converts false expressions to false:FalseClass' do
|
11
|
+
Boolean(false).should be(false)
|
12
|
+
Boolean(nil).should be(false)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Inheritance' do
|
4
|
+
it 'allows instance type checking' do
|
5
|
+
true.is_a?(Boolean).should be_true
|
6
|
+
false.is_a?(Boolean).should be_true
|
7
|
+
0.is_a?(Boolean).should be_false
|
8
|
+
nil.is_a?(Boolean).should be_false
|
9
|
+
(0==1).is_a?(Boolean).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'allows class type checking' do
|
13
|
+
(Object < Boolean).should be_false
|
14
|
+
(NilClass < Boolean).should be_false
|
15
|
+
(Class < Boolean).should be_false
|
16
|
+
(TrueClass < Boolean).should be_true
|
17
|
+
(FalseClass < Boolean).should be_true
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'boolean_class'
|
2
|
+
|
3
|
+
# Require this file using `require "spec_helper"` within each of your specs
|
4
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
config.filter_run :focus
|
9
|
+
|
10
|
+
# Run specs in random order to surface order dependencies.
|
11
|
+
config.order = 'random'
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boolean_class
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leo Gallucci
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '10.0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '10.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: redcarpet
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.2'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.2'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: yard
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.8'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.8'
|
78
|
+
description: ! 'Performs type conversion from anything to true:TrueClass / false:FalseClass
|
79
|
+
|
80
|
+
|
81
|
+
Similar to boolean gem but:
|
82
|
+
|
83
|
+
- without parse_bool()
|
84
|
+
|
85
|
+
- without raising exceptions
|
86
|
+
|
87
|
+
- without to_bool() to_b() methods
|
88
|
+
|
89
|
+
'
|
90
|
+
email:
|
91
|
+
- elgalu3@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- .gitignore
|
97
|
+
- .rspec
|
98
|
+
- .yardopts
|
99
|
+
- Gemfile
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.md
|
102
|
+
- Rakefile
|
103
|
+
- boolean_class.gemspec
|
104
|
+
- lib/boolean_class.rb
|
105
|
+
- lib/boolean_class/boolean.rb
|
106
|
+
- lib/boolean_class/conversion.rb
|
107
|
+
- lib/boolean_class/core_ext/all.rb
|
108
|
+
- lib/boolean_class/version.rb
|
109
|
+
- spec/conversion_spec.rb
|
110
|
+
- spec/inheritance_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
homepage: https://github.com/elgalu/boolean_class
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.9.3
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.8.11
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.25
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Performs type conversion from anything to true:TrueClass / false:FalseClass
|
137
|
+
test_files:
|
138
|
+
- spec/conversion_spec.rb
|
139
|
+
- spec/inheritance_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
has_rdoc:
|