slugalizer 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slugalizer.rb +8 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18c58c042f68b52c179f3e6d5657b95c6112e4fb
|
4
|
+
data.tar.gz: 0fce5b8b003e4ccee693ad0ad33977f8f617c1c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83b40823766c4165b75c00aba8712b395c10674255a728f63fd383688aa5ce576828f3c926864fde0e6ac194b2aafa5e042a74c060f007396f492262dfc6ccda
|
7
|
+
data.tar.gz: fd8f3bb3a080956b26f562065100adf2c5dd252af5cc4b4d8285813cd801d0a1bc028dc2733d29b5c0a3ca94f0811afc1d580f7650cc7f026c214ca37d8952d5
|
data/lib/slugalizer.rb
CHANGED
@@ -2,25 +2,23 @@ module Slugalizer
|
|
2
2
|
extend self
|
3
3
|
|
4
4
|
def to_slug(string = '')
|
5
|
-
#strip the string
|
5
|
+
# strip the string
|
6
6
|
ret = string.strip
|
7
7
|
|
8
|
-
#blow away apostrophes
|
9
|
-
ret.gsub! /['
|
8
|
+
# blow away apostrophes and dots
|
9
|
+
ret.gsub! /['`\.]/,""
|
10
10
|
|
11
|
-
#replace all non alphanumeric
|
12
|
-
ret.gsub! /\s*[^A-Za-z0-9
|
13
|
-
ret.gsub! /_/, '-'
|
11
|
+
# replace all non alphanumeric with dashes
|
12
|
+
ret.gsub! /\s*[^A-Za-z0-9]\s*/, '-'
|
14
13
|
|
15
|
-
#convert double dashes to single
|
14
|
+
# convert double dashes to single
|
16
15
|
ret.gsub! /-+/,"-"
|
17
16
|
|
18
|
-
#strip off leading/trailing dashes
|
17
|
+
# strip off leading/trailing dashes
|
19
18
|
ret.gsub! /\A[-\.]+|[-\.]+\z/,""
|
20
19
|
|
21
|
-
#transfor to downcase
|
20
|
+
# transfor to downcase
|
22
21
|
ret.downcase!
|
23
|
-
|
24
22
|
ret
|
25
23
|
end
|
26
24
|
end
|