typoglycemize 1.0.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/lib/typoglycemize.rb +34 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b36e199731d2cba302437701790a1c7e8cacceadf2bccbf3259dadf60c63d14e
|
4
|
+
data.tar.gz: 2c0c071c6109ea95fee4432ebb4707f039f44d0e0e47d85bfcc1e1a852ba3582
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ba0cb888d4cbfa45b6dce9b669900833a99e910516ad23ba95643ddfe1de9811167904f84aef3a8e6d32ac0e101d92a287375bccfabb64c0ce436652e6cadae
|
7
|
+
data.tar.gz: 38a22765ce326429a7b05d41f7397bab4cf744d835f96dd107736d1ae324a98e67221437fb4d67914f86dfe2e3300bcd5113bedf2173d001e686c3967893c3dd
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
def typoglycemize(string)
|
4
|
+
jumbled_string = []
|
5
|
+
words = string.split(/(\W+)/) # catch whitespace and punctuation
|
6
|
+
words.each do |word|
|
7
|
+
jumbled_string << jumble(word)
|
8
|
+
end
|
9
|
+
jumbled_string.join
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def jumble(word)
|
15
|
+
return word if (word.length < 4) || (word !~ /\D/)
|
16
|
+
|
17
|
+
chars = word.chars
|
18
|
+
# For each word, save the position of the first and last letter
|
19
|
+
first_letter = chars.shift
|
20
|
+
last_letter = chars.pop
|
21
|
+
|
22
|
+
# Scramble the remaining letters
|
23
|
+
shuffled_chars = chars.shuffle
|
24
|
+
# Ensure the shuffle is unique
|
25
|
+
shuffled_chars = chars.shuffle while shuffled_chars == chars &&
|
26
|
+
chars.length == chars.uniq.length
|
27
|
+
|
28
|
+
# Add the first and last letter back
|
29
|
+
shuffled_chars.insert(0, first_letter)
|
30
|
+
shuffled_chars.insert(-1, last_letter)
|
31
|
+
|
32
|
+
# Return all jumbled words in one string
|
33
|
+
shuffled_chars.join
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: typoglycemize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Corey Ellis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem that adds the typoglycemize method
|
14
|
+
email: coreypozzatiellis@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/typoglycemize.rb
|
20
|
+
homepage: https://rubygems.org/gems/typoglycemize
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.3.7
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: A method that will Typoglycemize a string of words, returning a jumbled yet
|
43
|
+
readable string
|
44
|
+
test_files: []
|