tboetto_palindrome 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/tboetto_palindrome/version.rb +1 -1
- data/lib/tboetto_palindrome.rb +17 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a80f59e203604adec04b8e352a6b8418e7bcd0df28cadc98489cb82f993d661
|
4
|
+
data.tar.gz: 14f927cb1f217b4b7c86eb6508e91e22994211fae124363513fa7f4d4b2ce4d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5690468e10fc842e596b9ecdab477408b22bc2b827797d408f1ec00bbbb25ef739d5c6fa86464b1316a49ae260c377575631580c89fad38626d6f47382fe5166
|
7
|
+
data.tar.gz: 66a1a5185c7badb04420891a4b0aaa9ef10d42c47e32c880f2e471e793fa2a72675bd30d22f394142c04d680166a47f4f6999e4692544afda4043c26a23d0014
|
data/Gemfile.lock
CHANGED
data/lib/tboetto_palindrome.rb
CHANGED
@@ -1,16 +1,30 @@
|
|
1
1
|
require "tboetto_palindrome/version"
|
2
2
|
|
3
3
|
# Modify the String class to check for palindromes
|
4
|
-
|
4
|
+
module TboettoPalindrome
|
5
5
|
# Returns true for palindrome, otherwise false.
|
6
6
|
def palindrome?
|
7
|
-
|
7
|
+
if processed_content.empty?
|
8
|
+
false
|
9
|
+
else
|
10
|
+
processed_content == processed_content.reverse
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
private
|
11
15
|
|
12
16
|
# Processes string/integer to be compared
|
13
17
|
def processed_content
|
14
|
-
self.scan(/[a-
|
18
|
+
self.to_s.scan(/[a-z0-9]/i).join.downcase
|
15
19
|
end
|
16
20
|
end
|
21
|
+
|
22
|
+
# Allow for all strings to test for Palindrome's natively
|
23
|
+
class String
|
24
|
+
include TboettoPalindrome
|
25
|
+
end
|
26
|
+
|
27
|
+
# Allow for integers to test for Palindrome's natively
|
28
|
+
class Integer
|
29
|
+
include TboettoPalindrome
|
30
|
+
end
|