chap8_ex_gem_palindrome 0.1.0 → 0.2.1
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 +2 -2
- data/Gemfile.lock +1 -1
- data/chap8_ex_gem_palindrome.gemspec +2 -6
- data/lib/chap8_ex_gem_palindrome/version.rb +1 -1
- data/lib/chap8_ex_gem_palindrome.rb +87 -58
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1786ac8e9766be3749b2dba55abe2c5cfc670dca24968dd18c33993e8ee50456
|
4
|
+
data.tar.gz: a4c44a30a8da0b5a94e63c4b6cf9410c6b45a90db9dc5d4858d069634503a6e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6de3ebc6949a1c2d83b751a99ffca5c646520df106e0ae8a76534aa245ace9e5751010b8b792a0a45a1ff713eb5b089aa3c438e75b1afa6ca1f1f8cf619eefce
|
7
|
+
data.tar.gz: 2bf8f847a73717162fda823ff2f12bc165d21eb182ae347d4006a7264e8a6eff8553863f8a116595b1c9ce6f3753a38c809561181c2b45d817e5155725346ea2
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
6
|
|
7
7
|
# Specify your gem's dependencies in chap8_ex_gem_palindrome.gemspec
|
8
8
|
gemspec
|
@@ -13,4 +13,4 @@ gem "minitest", "~> 5.0"
|
|
13
13
|
|
14
14
|
gem "rubocop", "~> 1.21"
|
15
15
|
|
16
|
-
gem
|
16
|
+
gem "minitest-reporters", "1.2.0"
|
data/Gemfile.lock
CHANGED
@@ -8,13 +8,11 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Xeniouska"]
|
9
9
|
spec.email = ["115425494+Xeniouska@users.noreply.github.com"]
|
10
10
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = "Palindrome detector"
|
12
|
+
spec.description = "Learn Enough Ruby palindrome detector"
|
13
13
|
spec.homepage = "https://github.com/mhartl/mhartl_palindrome"
|
14
14
|
spec.required_ruby_version = ">= 2.6.0"
|
15
15
|
|
16
|
-
|
17
|
-
|
18
16
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the
|
19
17
|
# 'allowed_push_host'
|
20
18
|
# to allow pushing to a single host or delete this section to allow pushing to
|
@@ -32,8 +30,6 @@ Gem::Specification.new do |spec|
|
|
32
30
|
# spec.metadata["source_code_uri"] = spec.homepage
|
33
31
|
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
34
32
|
|
35
|
-
|
36
|
-
|
37
33
|
# Specify which files should be added to the gem when it is released.
|
38
34
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
39
35
|
spec.files = Dir.chdir(__dir__) do
|
@@ -1,70 +1,99 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# Version 0.2.1
|
4
4
|
|
5
|
-
|
5
|
+
require_relative "chap8_ex_gem_palindrome/version"
|
6
6
|
|
7
|
+
# Test for palindroms
|
8
|
+
module Chap8ExGemPalindrome
|
7
9
|
# Returns true for a palindrome, false otherwise.
|
8
10
|
def palindrome?
|
9
|
-
|
11
|
+
if processed_content.empty?
|
12
|
+
false
|
13
|
+
else
|
14
|
+
processed_content == processed_content.reverse
|
15
|
+
end
|
10
16
|
end
|
11
17
|
|
12
|
-
# Returns the letters of the string (made by myself).
|
13
|
-
# def letters
|
14
|
-
# self.scan(/[a-z*A-Z*]/).join
|
15
|
-
# end
|
16
|
-
|
17
|
-
# Longer version A (from Tutorial).
|
18
|
-
# def letters
|
19
|
-
# the_letters = []
|
20
|
-
# for i in 0..(self.length - 1) do
|
21
|
-
# if self[i].match(/[a-zA-Z]/)
|
22
|
-
# the_letters << self[i]
|
23
|
-
# end
|
24
|
-
# end
|
25
|
-
# the_letters.join
|
26
|
-
# end
|
27
|
-
|
28
|
-
# Longer version B (made by myself).
|
29
|
-
# def letters
|
30
|
-
# the_letters = []
|
31
|
-
# regex_letters = /[a-z]/i # i for case incensitive
|
32
|
-
# self.each_char do |letter|
|
33
|
-
# if letter.match(regex_letters)
|
34
|
-
# the_letters << letter
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
# the_letters.join
|
38
|
-
# end
|
39
|
-
|
40
|
-
# Shorter version (following tutorial, from myself)
|
41
|
-
# def letters
|
42
|
-
# the_letters = self.chars.select { |char| char.match?(/[a-z]/i) }
|
43
|
-
# the_letters.join
|
44
|
-
# end
|
45
|
-
|
46
|
-
# Shorter version (from tutorial)
|
47
|
-
# def letters
|
48
|
-
# chars.select { |char| char.match?(/[a-z]/i) }.join
|
49
|
-
# end
|
50
|
-
|
51
|
-
# Finally Hartl end ups with the same code as I.
|
52
|
-
# def letters
|
53
|
-
# self.scan(/[a-z*A-Z*]/).join
|
54
|
-
# end
|
55
|
-
# And he goes further by pasting this in the processed_content and
|
56
|
-
# deleting the letters method !
|
57
|
-
|
58
18
|
private
|
59
19
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
20
|
+
# Returns content for palindrome testing.
|
21
|
+
def processed_content
|
22
|
+
scan(/[a-z0-9]/i).join.downcase
|
23
|
+
end
|
24
|
+
end
|
65
25
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
26
|
+
class String
|
27
|
+
include Chap8ExGemPalindrome
|
28
|
+
end
|
29
|
+
|
30
|
+
class Integer
|
31
|
+
include Chap8ExGemPalindrome
|
70
32
|
end
|
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
|
+
# # Returns the letters of the string (made by myself).
|
42
|
+
# # def letters
|
43
|
+
# # self.scan(/[a-z*A-Z*]/).join
|
44
|
+
# # end
|
45
|
+
|
46
|
+
# # Longer version A (from Tutorial).
|
47
|
+
# # def letters
|
48
|
+
# # the_letters = []
|
49
|
+
# # for i in 0..(self.length - 1) do
|
50
|
+
# # if self[i].match(/[a-zA-Z]/)
|
51
|
+
# # the_letters << self[i]
|
52
|
+
# # end
|
53
|
+
# # end
|
54
|
+
# # the_letters.join
|
55
|
+
# # end
|
56
|
+
|
57
|
+
# # Longer version B (made by myself).
|
58
|
+
# # def letters
|
59
|
+
# # the_letters = []
|
60
|
+
# # regex_letters = /[a-z]/i # i for case incensitive
|
61
|
+
# # self.each_char do |letter|
|
62
|
+
# # if letter.match(regex_letters)
|
63
|
+
# # the_letters << letter
|
64
|
+
# # end
|
65
|
+
# # end
|
66
|
+
# # the_letters.join
|
67
|
+
# # end
|
68
|
+
|
69
|
+
# # Shorter version (following tutorial, from myself)
|
70
|
+
# # def letters
|
71
|
+
# # the_letters = self.chars.select { |char| char.match?(/[a-z]/i) }
|
72
|
+
# # the_letters.join
|
73
|
+
# # end
|
74
|
+
|
75
|
+
# # Shorter version (from tutorial)
|
76
|
+
# # def letters
|
77
|
+
# # chars.select { |char| char.match?(/[a-z]/i) }.join
|
78
|
+
# # end
|
79
|
+
|
80
|
+
# # Finally Hartl end ups with the same code as I.
|
81
|
+
# # def letters
|
82
|
+
# # self.scan(/[a-z*A-Z*]/).join
|
83
|
+
# # end
|
84
|
+
# # And he goes further by pasting this in the processed_content and
|
85
|
+
# # deleting the letters method !
|
86
|
+
|
87
|
+
# private
|
88
|
+
|
89
|
+
# # Returns content for palindrome testing.
|
90
|
+
# # FIRST version:
|
91
|
+
# # def processed_content
|
92
|
+
# # self.letters.downcase
|
93
|
+
# # end
|
94
|
+
|
95
|
+
# # SECOND version, after joining to it the letters method:
|
96
|
+
# def processed_content
|
97
|
+
# self.scan(/[a-z*A-Z*]/).join.downcase
|
98
|
+
# end
|
99
|
+
# end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chap8_ex_gem_palindrome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xeniouska
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Learn Enough Ruby palindrome detector
|
14
14
|
email:
|