to_slug 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/to_slug/version.rb +1 -1
- data/lib/to_slug.rb +5 -2
- data/spec/to_slug_spec.rb +5 -1
- metadata +3 -3
data/lib/to_slug/version.rb
CHANGED
data/lib/to_slug.rb
CHANGED
@@ -86,8 +86,8 @@ class String # This reopns the string class
|
|
86
86
|
string = string.gsub(regex, replacement)
|
87
87
|
end
|
88
88
|
|
89
|
-
# Convert underscores to dashs
|
90
|
-
string = string.gsub(/[_]/,"-")
|
89
|
+
# Convert underscores and periods to dashs
|
90
|
+
string = string.gsub(/[_|.]/,"-")
|
91
91
|
|
92
92
|
# Remove any characters that aren't alphanumeric (or a dash)
|
93
93
|
string = string.gsub(/[^a-zA-Z0-9 \-]/,"")
|
@@ -101,6 +101,9 @@ class String # This reopns the string class
|
|
101
101
|
# Replace single spaces with a URL friendly dash (-)
|
102
102
|
string = string.gsub(/ /,"-")
|
103
103
|
|
104
|
+
# Do a greedy replace on multiple dashes
|
105
|
+
string = string.gsub(/-+/,"-")
|
106
|
+
|
104
107
|
# CASE. EVERYTHING. DOWN. (and return since it's the last line)
|
105
108
|
string = string.downcase
|
106
109
|
|
data/spec/to_slug_spec.rb
CHANGED
@@ -24,6 +24,10 @@ describe String, "to_slug" do
|
|
24
24
|
"This is an example to_slug".to_slug.should == "this-is-an-example-to-slug"
|
25
25
|
end
|
26
26
|
|
27
|
+
it "converts periods to dashes" do
|
28
|
+
"This.is.an.example.string".to_slug.should == "this-is-an-example-string"
|
29
|
+
end
|
30
|
+
|
27
31
|
it "removes leading/trailing whitespace" do
|
28
32
|
" this is a string ".to_slug.should == "this-is-a-string"
|
29
33
|
end
|
@@ -45,7 +49,7 @@ describe String, "to_slug" do
|
|
45
49
|
end
|
46
50
|
|
47
51
|
it "preserves dashes" do
|
48
|
-
"I like Mrs - on my salad".to_slug.should == "i-like-mrs
|
52
|
+
"I like Mrs - on my salad".to_slug.should == "i-like-mrs-on-my-salad"
|
49
53
|
end
|
50
54
|
|
51
55
|
it "downcases all characters" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 6
|
9
|
+
version: 1.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Eric Boehs
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-11 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|