url_compare 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/url_compare.rb +15 -4
- metadata +1 -1
data/lib/url_compare.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
1
|
class UrlCompare
|
2
|
-
def self.similar?(first_url, second_url)
|
3
|
-
|
2
|
+
def self.similar?(first_url, second_url, options = {})
|
3
|
+
if options[:strict]
|
4
|
+
first_url == second_url
|
5
|
+
else
|
6
|
+
strip_url(first_url, options) == strip_url(second_url, options)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.normalize(url, options = {})
|
11
|
+
strip_url(url, options)
|
4
12
|
end
|
5
13
|
|
6
14
|
private
|
7
15
|
|
8
|
-
def self.strip_url(url)
|
9
|
-
url
|
16
|
+
def self.strip_url(url, options)
|
17
|
+
result = url
|
18
|
+
|
19
|
+
result = result.split('?')[0] if options[:ignore_params]
|
20
|
+
result.split('#')[0].sub('//www.', '//').chomp('/')
|
10
21
|
end
|
11
22
|
end
|