librariesio-url-parser 1.0.3 → 1.0.6
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/android_googlesource_url_parser.rb +2 -0
- data/lib/apache_git_wip_url_parser.rb +2 -0
- data/lib/apache_gitbox_url_parser.rb +2 -0
- data/lib/apache_svn_url_parser.rb +2 -0
- data/lib/eclipse_git_url_parser.rb +2 -0
- data/lib/librariesio-url-parser.rb +1 -1
- data/lib/sourceforge_url_parser.rb +1 -0
- data/lib/url_parser.rb +31 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0552e054ac1b05ff114f7d95cf7281508ee65500356810168c5d4c56587524d6
|
4
|
+
data.tar.gz: 1a1dc645db555eb8935de55c6cf11ecebe3448bcb0325a49b9e850114006c92e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c479b95802f3d673fa23fbdd8fcc67fd36ed51c2fdf9f640147ebaa276466f9a8112111ba8a796ceb918e9df1b97d97dabcbfa2abe7e6df63e2a8911a53b5837
|
7
|
+
data.tar.gz: b9daf84d0a9347979489f1289d6608ea4f44125a607b37cba2d5065db56be2e4b551349f1cd585ee9f520f192d516dd264b8a91faa0c7da03fb92fd601689c7e
|
data/Gemfile.lock
CHANGED
data/lib/url_parser.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class URLParser
|
4
|
+
CASE_SENSITIVE = false
|
5
|
+
|
4
6
|
def self.parse(url)
|
5
7
|
new(url).parse
|
6
8
|
end
|
@@ -31,7 +33,7 @@ class URLParser
|
|
31
33
|
def self.try_all(url)
|
32
34
|
# run through all the subclasses and try their parse method
|
33
35
|
# exit the reduce at the first non nil value and return that
|
34
|
-
|
36
|
+
all_parsers.reduce(nil) do |_, n|
|
35
37
|
r = n.parse_to_full_url(url)
|
36
38
|
break r if r
|
37
39
|
end
|
@@ -53,6 +55,27 @@ class URLParser
|
|
53
55
|
[full_domain, path].join('/')
|
54
56
|
end
|
55
57
|
|
58
|
+
def self.case_sensitive?
|
59
|
+
self::CASE_SENSITIVE
|
60
|
+
end
|
61
|
+
|
62
|
+
# This computation is memoized because it is expensive. This prevents use cases which require using
|
63
|
+
# .try_all in a tight loop. However, if this class is required directly (without requiring any subparsers),
|
64
|
+
# this method will memoize an empty array. It is recommended to simply require librariesio-url-parser.rb directly.
|
65
|
+
# This is the default behavior when installing this gem.
|
66
|
+
def self.all_parsers
|
67
|
+
@all_parsers ||=
|
68
|
+
begin
|
69
|
+
all_parsers = []
|
70
|
+
ObjectSpace.each_object(singleton_class) do |k|
|
71
|
+
next if k.singleton_class?
|
72
|
+
|
73
|
+
all_parsers.unshift k unless k == self
|
74
|
+
end
|
75
|
+
all_parsers
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
56
79
|
private
|
57
80
|
|
58
81
|
attr_accessor :url
|
@@ -65,7 +88,12 @@ class URLParser
|
|
65
88
|
remove_auth_user
|
66
89
|
remove_equals_sign
|
67
90
|
remove_scheme
|
68
|
-
|
91
|
+
|
92
|
+
unless includes_domain?
|
93
|
+
self.url = nil
|
94
|
+
return nil
|
95
|
+
end
|
96
|
+
|
69
97
|
remove_subdomain
|
70
98
|
remove_domain
|
71
99
|
remove_git_extension
|
@@ -74,6 +102,7 @@ class URLParser
|
|
74
102
|
end
|
75
103
|
|
76
104
|
def format_url
|
105
|
+
return nil if url.nil?
|
77
106
|
return nil unless url.length == 2
|
78
107
|
|
79
108
|
url.join('/')
|
@@ -161,14 +190,4 @@ class URLParser
|
|
161
190
|
def remove_whitespace
|
162
191
|
url.gsub!(/\s/, '')
|
163
192
|
end
|
164
|
-
|
165
|
-
private_class_method def self.descendants
|
166
|
-
descendants = []
|
167
|
-
ObjectSpace.each_object(singleton_class) do |k|
|
168
|
-
next if k.singleton_class?
|
169
|
-
|
170
|
-
descendants.unshift k unless k == self
|
171
|
-
end
|
172
|
-
descendants
|
173
|
-
end
|
174
193
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: librariesio-url-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Pace
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|