palindrome 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +19 -0
- data/README.md +25 -0
- data/Rakefile +6 -0
- data/lib/palindrome.rb +4 -0
- data/lib/palindrome/core_ext.rb +1 -0
- data/lib/palindrome/core_ext/string.rb +1 -0
- data/lib/palindrome/core_ext/string/palindrome.rb +7 -0
- data/lib/palindrome/version.rb +3 -0
- data/palindrome.gemspec +24 -0
- data/spec/palindrome_spec.rb +57 -0
- metadata +58 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 by Chris Nichols
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Palindrome #
|
2
|
+
|
3
|
+
A **palindrome** is a word, phrase, number, or other sequence of units that can
|
4
|
+
be read the same way in either direction, with general allowances for
|
5
|
+
adjustments to punctuation and word dividers. - [Wikipedia](http://en.wikipedia.org/wiki/Palindrome)
|
6
|
+
|
7
|
+
The Palindrome gem extends the String class with the `palindrome?` method.
|
8
|
+
## Installing ##
|
9
|
+
|
10
|
+
$ gem install palindrome
|
11
|
+
|
12
|
+
## Usage ##
|
13
|
+
irb example:
|
14
|
+
|
15
|
+
> require 'palindrome'
|
16
|
+
=> true
|
17
|
+
> "Go hang a salami, I'm a lasagna hog.".palindrome?
|
18
|
+
=> true
|
19
|
+
> "No palindrome here".palindrome?
|
20
|
+
=> false
|
21
|
+
|
22
|
+
## License ##
|
23
|
+
|
24
|
+
Palindrome gem is released under the MIT license.
|
25
|
+
|
data/Rakefile
ADDED
data/lib/palindrome.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'palindrome/core_ext/string'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'palindrome/core_ext/string/palindrome'
|
data/palindrome.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "palindrome/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "palindrome"
|
7
|
+
s.version = Palindrome::VERSION
|
8
|
+
s.authors = ["Chris Nichols"]
|
9
|
+
s.email = ["chris@clnichols.com"]
|
10
|
+
s.homepage = "https://github.com/cnichols/palindrome"
|
11
|
+
s.summary = %q{A gem to identify palindromes}
|
12
|
+
s.description = %q{Adds 'palindrome?' method to String class}
|
13
|
+
|
14
|
+
s.rubyforge_project = "palindrome"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path("../../lib/palindrome", __FILE__)
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
# Test strings brought to you by Weird Al Yankovic's "Bob"
|
5
|
+
# http://www.youtube.com/watch?v=Nej4xJe4Tdg
|
6
|
+
|
7
|
+
describe "String with pamindrome support" do
|
8
|
+
it "should be a String class" do
|
9
|
+
string = String.new
|
10
|
+
string.must_be_kind_of String
|
11
|
+
end
|
12
|
+
it "should respond to palindrome?" do
|
13
|
+
string = String.new
|
14
|
+
string.must_respond_to('palindrome?')
|
15
|
+
end
|
16
|
+
it "should handle blank Strings" do
|
17
|
+
''.palindrome?.must_equal false
|
18
|
+
end
|
19
|
+
it "should handle new Strings" do
|
20
|
+
test_string = String.new
|
21
|
+
test_string.palindrome?.must_equal false
|
22
|
+
end
|
23
|
+
it "shound not identify a non-palindrome as a palindrome" do
|
24
|
+
"This is not a palindrome".palindrome?.must_equal false
|
25
|
+
"Nore is this".palindrome?.must_equal false
|
26
|
+
end
|
27
|
+
it "should validate a single word palindrome" do
|
28
|
+
"hannah".palindrome?.must_equal true
|
29
|
+
end
|
30
|
+
it "should ignore case" do
|
31
|
+
"HaNnah".palindrome?.must_equal true
|
32
|
+
end
|
33
|
+
it "should ignore spaces" do
|
34
|
+
"I man am regal a german am I".palindrome?.must_equal true
|
35
|
+
end
|
36
|
+
it "should ignore dashes" do
|
37
|
+
"if I had a hi-fi".palindrome?.must_equal true
|
38
|
+
end
|
39
|
+
it "should ignore apostrophes" do
|
40
|
+
"madam I'm adam".palindrome?.must_equal true
|
41
|
+
end
|
42
|
+
it "should ignore non-letters" do
|
43
|
+
"Do nine men interpret? 'Nine men' I nod.".palindrome?.must_equal true
|
44
|
+
end
|
45
|
+
it "should ignore double quotes" do
|
46
|
+
'No "X" in Nixon'.palindrome?.must_equal true
|
47
|
+
end
|
48
|
+
it "should ignore bangs and periods" do
|
49
|
+
"God! A red nugget! A fat egg under a dog.".palindrome?.must_equal true
|
50
|
+
end
|
51
|
+
it "should test a palindrome with the words salami and lasagna" do
|
52
|
+
"Go hang a salami, I'm a lasagna hog.".palindrome?.must_equal true
|
53
|
+
end
|
54
|
+
it "should allow numbers" do
|
55
|
+
"123454321".palindrome?.must_equal true
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: palindrome
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Nichols
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-13 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Adds 'palindrome?' method to String class
|
15
|
+
email:
|
16
|
+
- chris@clnichols.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/palindrome.rb
|
27
|
+
- lib/palindrome/core_ext.rb
|
28
|
+
- lib/palindrome/core_ext/string.rb
|
29
|
+
- lib/palindrome/core_ext/string/palindrome.rb
|
30
|
+
- lib/palindrome/version.rb
|
31
|
+
- palindrome.gemspec
|
32
|
+
- spec/palindrome_spec.rb
|
33
|
+
homepage: https://github.com/cnichols/palindrome
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project: palindrome
|
53
|
+
rubygems_version: 1.8.10
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: A gem to identify palindromes
|
57
|
+
test_files:
|
58
|
+
- spec/palindrome_spec.rb
|