mhartl_palindrome 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +26 -20
- data/lib/mhartl_palindrome/version.rb +1 -1
- data/lib/mhartl_palindrome.rb +12 -6
- 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: 81cdc690fc626f2a67ab34e1f5bd51d3cb7bc4da44da5c7b7d3337ee0bf2cfca
|
4
|
+
data.tar.gz: 9a97d7bc16ab6faea5703de2c113d8980305e79146d479b71cb79dcb32140f7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eafea7c4fb6102d3407d2dc5d8ec3ab0cc15b157827205fc3538a666824bc0139c6f7981b5461e9250a580367eb2c937975d90e1cc00ece91ceb0d256b368454
|
7
|
+
data.tar.gz: e951fd4e19a1a160e7f5c740c90aa3b974bc349cf790af9f4cff2bf5d0255b4f85c9142b419335bb658b3726524e2e7a7c77e22965985a6241ab627c4581084c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,38 +1,44 @@
|
|
1
|
-
#
|
1
|
+
# Palindrome detector
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
`mhartl_palindrome` is a sample Ruby gem created in [*Learn Enough Ruby to Be Dangerous*](https://www.learnenough.com/ruby-tutorial) by Michael Hartl.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
To install `mhartl_palindrome`, add this line to your application's `Gemfile`:
|
10
8
|
|
11
|
-
```
|
9
|
+
```
|
12
10
|
gem 'mhartl_palindrome'
|
13
11
|
```
|
14
12
|
|
15
|
-
|
13
|
+
Then install as follows:
|
16
14
|
|
17
|
-
|
15
|
+
```
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
18
|
|
19
|
-
Or install it
|
19
|
+
Or install it directly using `gem`:
|
20
20
|
|
21
|
-
|
21
|
+
```
|
22
|
+
$ gem install mhartl_palindrome
|
23
|
+
```
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
`mhartl_palindrome` adds a `palindrome?` method to the `String` class, and can be used as follows:
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
```
|
30
|
+
$ irb
|
31
|
+
>> require 'mhartl_palindrome'
|
32
|
+
>> "honey badger".palindrome?
|
33
|
+
=> false
|
34
|
+
>> "deified".palindrome?
|
35
|
+
=> true
|
36
|
+
>> "Able was I, ere I saw Elba.".palindrome?
|
37
|
+
=> true
|
38
|
+
>> phrase = "Madam, I'm Adam."
|
39
|
+
>> phrase.palindrome?
|
40
|
+
=> true
|
41
|
+
```
|
36
42
|
|
37
43
|
## License
|
38
44
|
|
data/lib/mhartl_palindrome.rb
CHANGED
@@ -2,13 +2,19 @@ require "mhartl_palindrome/version"
|
|
2
2
|
|
3
3
|
class String
|
4
4
|
|
5
|
-
# Processes content for palindrome testing.
|
6
|
-
def processed_content
|
7
|
-
self.scan(/[a-z]/i).join.downcase
|
8
|
-
end
|
9
|
-
|
10
5
|
# Returns true for a palindrome, false otherwise.
|
11
6
|
def palindrome?
|
12
|
-
|
7
|
+
if processed_content.empty?
|
8
|
+
false
|
9
|
+
else
|
10
|
+
processed_content == processed_content.reverse
|
11
|
+
end
|
13
12
|
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# Returns content for palindrome testing.
|
17
|
+
def processed_content
|
18
|
+
self.scan(/[a-z]/i).join.downcase
|
19
|
+
end
|
14
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mhartl_palindrome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Hartl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|