Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JaniJegoroff committed Sep 10, 2014
1 parent 8101965 commit 9a89041
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in to_boolean.gemspec
gemspec
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs << 'spec'
t.test_files = FileList['spec/spec_*.rb']
t.verbose = true
end

task :default => :test
6 changes: 6 additions & 0 deletions lib/to_boolean.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Object
def to_boolean
value = self.is_a?(String) ? self.downcase : self
[true, 'true', 1, '1'].include?(value)
end
end
7 changes: 7 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'minitest/spec'
require 'minitest/autorun'
require 'minitest/reporters'

require 'to_boolean'

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
17 changes: 17 additions & 0 deletions spec/spec_to_boolean.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative 'spec_helper'

class TestToBoolean < Minitest::Spec
describe TestToBoolean do
it 'should return true' do
[true, 'true', 'TRUE', 1, '1'].each do |value|
value.to_boolean.must_equal(true)
end
end

it 'should return false' do
[false, 'false', 'FALSE', 0, '0', nil, :symbol].each do |value|
value.to_boolean.must_equal(false)
end
end
end
end
21 changes: 21 additions & 0 deletions to_boolean.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Gem::Specification.new do |gem|
gem.name = 'to_boolean'
gem.version = '1.0.0'
gem.platform = Gem::Platform::RUBY
gem.authors = ['Jani Jegoroff']
gem.date = '2014-09-10'
gem.email = ['[email protected]']
gem.summary = 'Simple gem that provides to_boolean method.'
gem.description = 'Ruby core extension that converts string and integer values to boolean.'
gem.homepage = 'http://github.com/JaniJegoroff/to_boolean'
gem.license = 'MIT'

gem.files = %w[lib/to_boolean.rb]
gem.require_paths = ['lib']

gem.test_files = %w[spec/spec_helper.rb spec/spec_to_boolean.rb]

gem.add_development_dependency 'rake', '~> 0'
gem.add_development_dependency 'minitest', '~> 0'
gem.add_development_dependency 'minitest-reporters', '~> 0'
end

0 comments on commit 9a89041

Please sign in to comment.