to_bool 1.0.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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in to_bool.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # ToBool
2
+
3
+ Natural coercion into boolean (true / false). Useful for API interaction.
4
+
5
+
6
+ ## Installation
7
+
8
+ `gem "to_bool"`
9
+
10
+
11
+ ## Usage
12
+
13
+ Call `to_bool` on any object. It will *usually* return false, except:
14
+
15
+ * String: `"true"`, `"1"`, and `"yes"` are true
16
+ * Integer: `1` is true
17
+
18
+ See the spec, it pretty much maps it out.
19
+
20
+ ## Contributing
21
+
22
+ Yes.
23
+
24
+
25
+ ## License
26
+
27
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ RSpec::Core::RakeTask.new(:spec)
3
+ task :default => "spec"
data/lib/to_bool.rb ADDED
@@ -0,0 +1,24 @@
1
+ class String
2
+ def to_bool
3
+ %w{ 1 true yes }.include? self.downcase
4
+ end
5
+ end
6
+
7
+ class Integer
8
+ def to_bool
9
+ self == 1
10
+ end
11
+ end
12
+
13
+
14
+ class TrueClass
15
+ def to_bool
16
+ self
17
+ end
18
+ end
19
+
20
+ class Object
21
+ def to_bool
22
+ false
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'bundler/setup'
2
+ Bundler.require
3
+
4
+ describe "String" do
5
+ it "is true if yes" do
6
+ "yes".to_bool.should eq true
7
+ end
8
+
9
+ it "is true if '1'" do
10
+ "1".to_bool.should eq true
11
+ end
12
+
13
+ it "is true if 'true'" do
14
+ "true".to_bool.should eq true
15
+ end
16
+
17
+ it "is false otherwise" do
18
+ "no".to_bool.should eq false
19
+ "false".to_bool.should eq false
20
+ "0".to_bool.should eq false
21
+ end
22
+ end
23
+
24
+ describe "Integer" do
25
+ it "is true if 1" do
26
+ 1.to_bool.should eq true
27
+ end
28
+
29
+ it "is false otherwise" do
30
+ 0.to_bool.should eq false
31
+ end
32
+ end
33
+
34
+ describe "TrueClass" do
35
+ it "is true" do
36
+ true.to_bool.should eq true
37
+ end
38
+ end
39
+
40
+ describe "Object" do
41
+ it "is false by default" do
42
+ Object.new.to_bool.should eq false
43
+ end
44
+ end
data/to_bool.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "to_bool"
7
+ gem.version = "1.0.0"
8
+ gem.authors = ["Bryan Ricker"]
9
+ gem.email = ["bricker88@gmail.com"]
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
+ gem.summary = %q{Convert any object naturally into a boolean}
12
+ gem.homepage = "http://github.com/bricker88/to_bool"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_development_dependency "rspec", [">= 0"]
20
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to_bool
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bryan Ricker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '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: '0'
30
+ description: Super-simple gem that extends some Ruby classes with a "to_bool" method,
31
+ which converts any object naturally into a boolean.
32
+ email:
33
+ - bricker88@gmail.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - README.md
41
+ - Rakefile
42
+ - lib/to_bool.rb
43
+ - spec/to_bool_spec.rb
44
+ - to_bool.gemspec
45
+ homepage: http://github.com/bricker88/to_bool
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Convert any object naturally into a boolean
69
+ test_files:
70
+ - spec/to_bool_spec.rb