sdalnodar_palindrome 0.1.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 +7 -0
- data/.gitignore +8 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +30 -0
- data/README.md +45 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/sdalnodar_palindrome.rb +42 -0
- data/lib/sdalnodar_palindrome/version.rb +5 -0
- data/sdalnodar_palindrome.gemspec +36 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d78a3f71d29687342df81958fbb194088af2ade8296bbebb0372da04cbbf28d2
|
4
|
+
data.tar.gz: 1b20ffec4ffbde1c74d604a7a8ead01b58091baac553e3af87f8ece4a26bde33
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b4a38c17f845ff2571e72bec3cbda93f747f921501f501787f6b8a0c8f9ac251febe79a57540b169fa03320383087d57893337bcf477e3dd2acc232c2049818
|
7
|
+
data.tar.gz: c788d739da5ba1291ce9c5edba7799e3df016fe379c0510722feb47244f65f114bda0fc687a7fde63d3167ae6d05d05913df22853da9fdca2ad0862292721e44
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sdalnodar_palindrome (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ansi (1.5.0)
|
10
|
+
builder (3.2.4)
|
11
|
+
minitest (5.14.4)
|
12
|
+
minitest-reporters (1.4.3)
|
13
|
+
ansi
|
14
|
+
builder
|
15
|
+
minitest (>= 5.0)
|
16
|
+
ruby-progressbar
|
17
|
+
rake (13.0.3)
|
18
|
+
ruby-progressbar (1.11.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
x86_64-linux
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
minitest (~> 5.0)
|
25
|
+
minitest-reporters
|
26
|
+
rake (~> 13.0)
|
27
|
+
sdalnodar_palindrome!
|
28
|
+
|
29
|
+
BUNDLED WITH
|
30
|
+
2.2.15
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Palindrome detector
|
2
|
+
|
3
|
+
`sdalnodar_palindrome` is a sample Ruby gem created in [*Learn Enough Ruby to Be Dangerous*](https://www.learnenough.com/ruby-tutorial) by Michael Hartl.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To install `sdalnodar_palindrome`, add this line to your application's `Gemfile`:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'sdalnodar_palindrome'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then install as follows:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it directly using `gem`:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install mhartl_palindrome
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
`sdalnodar_palindrome` adds a `palindrome?` method to the `String` class, and can be used as follows:
|
28
|
+
|
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
|
+
```
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "sdalnodar_palindrome"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "sdalnodar_palindrome/version"
|
4
|
+
|
5
|
+
class String
|
6
|
+
|
7
|
+
# Returns true for a palindrome, fals otherwise.
|
8
|
+
def palindrome?
|
9
|
+
processed_content == processed_content.reverse
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns true if a string is blank, false otherwise.
|
13
|
+
def blank?
|
14
|
+
empty? || match?(/^\s/)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Strips non-word characters from a string
|
18
|
+
def letters
|
19
|
+
## old school for loop
|
20
|
+
# the_letters = []
|
21
|
+
# for i in 0..self.length - 1 do
|
22
|
+
# if self[i].match(/[a-zA-Z0-9]/)
|
23
|
+
# the_letters << self[i]
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# the_letters.join
|
27
|
+
## select single line
|
28
|
+
# self.chars.select { |c| c.match(/[a-z]/i) }.join
|
29
|
+
## using gsub method
|
30
|
+
self.gsub(/\W+/, '')
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# Returns processed content
|
36
|
+
def processed_content
|
37
|
+
# # using the above letters method
|
38
|
+
# self.letters.downcase
|
39
|
+
# pattern matching on one line
|
40
|
+
self.scan(/[a-z]/i).join.downcase
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/sdalnodar_palindrome/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sdalnodar_palindrome"
|
7
|
+
spec.version = Sdalnodarpalindrome::VERSION
|
8
|
+
spec.authors = ["Sean Dalnodar"]
|
9
|
+
spec.email = ["sdalnodar@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Palindrome detector."
|
12
|
+
spec.description = "Learn Enough Ruby palindrome detector."
|
13
|
+
spec.homepage = "https://github.com/sdalnodar/palindrome_detector"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, checkout our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sdalnodar_palindrome
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Dalnodar
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Learn Enough Ruby palindrome detector.
|
14
|
+
email:
|
15
|
+
- sdalnodar@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- bin/console
|
26
|
+
- bin/setup
|
27
|
+
- lib/sdalnodar_palindrome.rb
|
28
|
+
- lib/sdalnodar_palindrome/version.rb
|
29
|
+
- sdalnodar_palindrome.gemspec
|
30
|
+
homepage: https://github.com/sdalnodar/palindrome_detector
|
31
|
+
licenses: []
|
32
|
+
metadata:
|
33
|
+
allowed_push_host: https://rubygems.org
|
34
|
+
homepage_uri: https://github.com/sdalnodar/palindrome_detector
|
35
|
+
source_code_uri: https://github.com/sdalnodar/palindrome_detector
|
36
|
+
changelog_uri: https://github.com/sdalnodar/palindrome_detector
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.4.0
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.0.3
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: Palindrome detector.
|
56
|
+
test_files: []
|