poppacalypse_palindrome 0.1.1 → 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/poppacalypse_palindrome.rb +84 -53
- data/lib/poppacalypse_palindrome/version.rb +1 -1
- 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: badaccfc9cedab29e3e4ad843057ef365f8498e346be948c336d8b3b55060140
|
4
|
+
data.tar.gz: efaac2c037c783461a4d47f8b03468dbaa077638d21cf4a28bbd5625cd3fb7db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59f752adbff123af7097b31b21aace89e638226f55ed63b77bb16c80463b18930842a008cb889eecb1ccbcb00a9bbadecf9d1c93462843e269e14620bf84c964
|
7
|
+
data.tar.gz: 5541715856f757f4d7a2bd79bd45cb1e01607f0e711ff9c1b78133073203e39da74a8dae6339da5d8941d4e2f7d85c66c0b0f70028e5e524bcd4a50e46205e24
|
data/Gemfile.lock
CHANGED
@@ -1,59 +1,90 @@
|
|
1
1
|
require "poppacalypse_palindrome/version"
|
2
2
|
|
3
|
-
|
3
|
+
# =============== Ch 8.5 Refactor: Exercise ===================
|
4
|
+
# =============== Restore the module ===============
|
5
|
+
|
6
|
+
module PoppacalypsePalindrome
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
# ========== Testing & TDD =======================
|
11
|
-
# =============== Ch 8.4 Green ===================
|
12
|
-
|
13
|
-
# Returns only the letters in the string
|
14
|
-
# def letters
|
15
|
-
# the_letters = []
|
16
|
-
# for i in 0..self.length - 1 do
|
17
|
-
# if self[i].match(/[a-zA-z]/)
|
18
|
-
# the_letters << self[i]
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
# the_letters.join
|
22
|
-
# end
|
23
|
-
|
24
|
-
# =============== Ch 8.5 Refactor: Method 1 ===================
|
25
|
-
|
26
|
-
# def letters
|
27
|
-
# the_letters = []
|
28
|
-
# letter_regex = /[a-z]/i
|
29
|
-
# self.chars.each do |character|
|
30
|
-
# if character.match(letter_regex)
|
31
|
-
# the_letters << character
|
32
|
-
# end
|
33
|
-
# end
|
34
|
-
# the_letters.join
|
35
|
-
# end
|
36
|
-
|
37
|
-
# =============== Ch 8.5 Refactor: Method 2 ===================
|
38
|
-
|
39
|
-
# def letters
|
40
|
-
# # self.chars.select { |c| c.match(/[a-z]/i) }.join
|
41
|
-
# chars.select { |c| c.match(/[a-z]/i) }.join
|
42
|
-
# end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
# ============ Ch 8.5 Refactor: Method 3 ==================
|
47
|
-
# It's so compact that we can put it directly in processed_content, instead of defining a method of its own as the above 2 examples.
|
48
|
-
# We also won't be needing test_letters in the test file
|
49
|
-
|
50
|
-
# Returns content for palindrome testing
|
51
|
-
# def processed_content
|
52
|
-
# self.letters.downcase
|
53
|
-
# end
|
54
|
-
|
55
|
-
def processed_content
|
56
|
-
self.scan(/[a-z]/i).join.downcase
|
8
|
+
# Returns true for palindrome, false otherwise
|
9
|
+
def palindrome?
|
10
|
+
processed_content == processed_content.reverse
|
57
11
|
end
|
58
12
|
|
13
|
+
private
|
14
|
+
|
15
|
+
# Returns content for palindrome testing
|
16
|
+
def processed_content
|
17
|
+
# self.to_s.scan(/[a-z]/i).join.downcase
|
18
|
+
|
19
|
+
# include digits to accomodate integers
|
20
|
+
self.to_s.scan(/[a-z\d]/i).join.downcase
|
21
|
+
end
|
59
22
|
end
|
23
|
+
|
24
|
+
class String
|
25
|
+
include PoppacalypsePalindrome
|
26
|
+
end
|
27
|
+
|
28
|
+
class Integer
|
29
|
+
include PoppacalypsePalindrome
|
30
|
+
end
|
31
|
+
|
32
|
+
# -------------------------------------------
|
33
|
+
|
34
|
+
# class String
|
35
|
+
#
|
36
|
+
# # Returns true for a palindrome, false otherwise
|
37
|
+
# def palindrome?
|
38
|
+
# processed_content == processed_content.reverse
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# # ========== Testing & TDD =======================
|
42
|
+
# # =============== Ch 8.4 Green ===================
|
43
|
+
#
|
44
|
+
# # Returns only the letters in the string
|
45
|
+
# # def letters
|
46
|
+
# # the_letters = []
|
47
|
+
# # for i in 0..self.length - 1 do
|
48
|
+
# # if self[i].match(/[a-zA-z]/)
|
49
|
+
# # the_letters << self[i]
|
50
|
+
# # end
|
51
|
+
# # end
|
52
|
+
# # the_letters.join
|
53
|
+
# # end
|
54
|
+
#
|
55
|
+
# # =============== Ch 8.5 Refactor: Method 1 ===================
|
56
|
+
#
|
57
|
+
# # def letters
|
58
|
+
# # the_letters = []
|
59
|
+
# # letter_regex = /[a-z]/i
|
60
|
+
# # self.chars.each do |character|
|
61
|
+
# # if character.match(letter_regex)
|
62
|
+
# # the_letters << character
|
63
|
+
# # end
|
64
|
+
# # end
|
65
|
+
# # the_letters.join
|
66
|
+
# # end
|
67
|
+
#
|
68
|
+
# # =============== Ch 8.5 Refactor: Method 2 ===================
|
69
|
+
#
|
70
|
+
# # def letters
|
71
|
+
# # # self.chars.select { |c| c.match(/[a-z]/i) }.join
|
72
|
+
# # chars.select { |c| c.match(/[a-z]/i) }.join
|
73
|
+
# # end
|
74
|
+
#
|
75
|
+
# private
|
76
|
+
#
|
77
|
+
# # ============ Ch 8.5 Refactor: Method 3 ==================
|
78
|
+
# # It's so compact that we can put it directly in processed_content, instead of defining a method of its own as the above 2 examples.
|
79
|
+
# # We also won't be needing test_letters in the test file
|
80
|
+
#
|
81
|
+
# # Returns content for palindrome testing
|
82
|
+
# # def processed_content
|
83
|
+
# # self.letters.downcase
|
84
|
+
# # end
|
85
|
+
#
|
86
|
+
# def processed_content
|
87
|
+
# self.scan(/[a-z]/i).join.downcase
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# end
|