From 50fb334ffff001a773b034ea96cebb091b958018 Mon Sep 17 00:00:00 2001 From: Ben Slaughter Date: Mon, 30 Sep 2013 18:06:50 +0100 Subject: [PATCH] Version 0.0.2 Added Symbol --- .gitignore | 1 + Gemfile.lock | 4 ++-- History.md | 15 +++++++++++++++ README.md | 34 ++++++++++++++++++++++++++++++++++ lib/to_bool.rb | 4 ++++ lib/to_bool/bool.rb | 6 +++--- lib/to_bool/version.rb | 2 +- spec/symbol_spec.rb | 29 +++++++++++++++++++++++++++++ 8 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 History.md create mode 100644 spec/symbol_spec.rb diff --git a/.gitignore b/.gitignore index 560d1a6..885e55a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ spec/reports test/tmp test/version_tmp tmp +Gemfile.lock # YARD artifacts .yardoc diff --git a/Gemfile.lock b/Gemfile.lock index 7ed755e..f57d58d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - to_bool (0.0.1) + to_b (0.0.2) GEM remote: http://rubygems.org/ @@ -41,5 +41,5 @@ DEPENDENCIES coveralls (~> 0.6.7) rake rspec (~> 2.13.0) - to_bool! + to_b! yard diff --git a/History.md b/History.md new file mode 100644 index 0000000..c18ea44 --- /dev/null +++ b/History.md @@ -0,0 +1,15 @@ +# History +## Released Versions +### Version 0.0.2 +#### Patch: Symbol +##### Added + * Symbol + +##### Changed + * All get converted to string first + +### Version 0.0.1 +#### Patch: Inital Code. Fixnum, String +##### Added + * Fixnum + * String \ No newline at end of file diff --git a/README.md b/README.md index 5f277c7..c60e24d 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,37 @@ to_bool [![Gem Version](https://badge.fury.io/rb/to_b.png)](http://badge.fury.io/rb/to_b) Extends classes to include the to_b method +Currently Extends: + * Fixnum + * String + * Symbol + +```ruby +gem install to_b +``` + +```ruby +require 'to_bool' +``` + +```ruby +1.to_b +=> true + +'yes'.to_b +=> true + +:t.to_b +=> true +``` + +```ruby +0.to_b +=> false + +'no'.to_b +=> false + +:f.to_b +=> false +``` diff --git a/lib/to_bool.rb b/lib/to_bool.rb index 40346dd..b2f1f26 100644 --- a/lib/to_bool.rb +++ b/lib/to_bool.rb @@ -7,4 +7,8 @@ class String class Fixnum include Bool +end + +class Symbol + include Bool end \ No newline at end of file diff --git a/lib/to_bool/bool.rb b/lib/to_bool/bool.rb index edec232..3da370e 100644 --- a/lib/to_bool/bool.rb +++ b/lib/to_bool/bool.rb @@ -1,9 +1,9 @@ module Bool def to_b - case self - when /true/i, /yes/i, /t/i, /1/i, 1 + case self.to_s + when /true/i, /yes/i, /t/i, /1/i true - when /false/i, /no/i, /f/i, /0/i, 0 + when /false/i, /no/i, /f/i, /0/i false end end diff --git a/lib/to_bool/version.rb b/lib/to_bool/version.rb index 1b58539..4ecbc9b 100644 --- a/lib/to_bool/version.rb +++ b/lib/to_bool/version.rb @@ -1,4 +1,4 @@ module Bool - VERSION = "0.0.1".freeze + VERSION = "0.0.2".freeze DATE = "2013-09-30".freeze end \ No newline at end of file diff --git a/spec/symbol_spec.rb b/spec/symbol_spec.rb new file mode 100644 index 0000000..acf7827 --- /dev/null +++ b/spec/symbol_spec.rb @@ -0,0 +1,29 @@ +require 'helper' + +describe Symbol do + describe "#to_b" do + it "returns true when true" do + expect(:true.to_b).to be true + end + + it "returns true when yes" do + expect(:yes.to_b).to be true + end + + it "returns true when t" do + expect(:t.to_b).to be true + end + + it "returns false when false" do + expect(:false.to_b).to be false + end + + it "returns false when no" do + expect(:no.to_b).to be false + end + + it "returns false when f" do + expect(:f.to_b).to be false + end + end +end \ No newline at end of file