librariesio-url-parser 1.0.8 → 1.0.9
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/librariesio-url-parser.rb +1 -1
- data/lib/url_parser.rb +31 -5
- 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: aed18904c0a030a5bdab10a3717974e2fe62ef63ec5525cb9aa5944213da540b
|
|
4
|
+
data.tar.gz: 69c24ecc3ea131c7725a9ab97a433131a53972e2b4e66b5d5cf9854e6ab63a1b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 529bd4550e2ec85f30ae870908ffd10931845da891d06ed138fbb0c9abe026e901b35a896b18c2a2b2b40cc1cdfdcd53527e38db1158ab4782e8349be06e092f
|
|
7
|
+
data.tar.gz: f8627e676157b0cdad2acfc2e5441f1a532bb39a68ef9164a1b6fed285b21fb719d8ec197dbc48dff67616648e8c83d750065713292a370d39bf24b19124cd85
|
data/Gemfile.lock
CHANGED
data/lib/url_parser.rb
CHANGED
|
@@ -11,13 +11,16 @@ class URLParser
|
|
|
11
11
|
@url = url.to_s.dup
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
# Clean the URL and format the path segments after the domain
|
|
15
|
+
#
|
|
16
|
+
# @return String Path segments after the domain joined by a "/"
|
|
14
17
|
def parse
|
|
15
18
|
return nil unless parseable?
|
|
16
19
|
|
|
17
20
|
if url = extractable_early?
|
|
18
21
|
url
|
|
19
22
|
else
|
|
20
|
-
clean_url
|
|
23
|
+
clean_url!
|
|
21
24
|
format_url
|
|
22
25
|
end
|
|
23
26
|
end
|
|
@@ -39,6 +42,10 @@ class URLParser
|
|
|
39
42
|
end
|
|
40
43
|
end
|
|
41
44
|
|
|
45
|
+
# Clean and parse the URL string returning all path segments following
|
|
46
|
+
# the domain.
|
|
47
|
+
#
|
|
48
|
+
# @return String Domain with URL path segments appended
|
|
42
49
|
def parse_to_full_url
|
|
43
50
|
path = parse
|
|
44
51
|
return nil if path.nil? || path.empty?
|
|
@@ -46,13 +53,17 @@ class URLParser
|
|
|
46
53
|
[full_domain, path].join('/')
|
|
47
54
|
end
|
|
48
55
|
|
|
56
|
+
# Clean and parse the URL string returning the first path following the domain.
|
|
57
|
+
#
|
|
58
|
+
# @return [String, nil] Domain with the lone user path segment appended. If the path resolved
|
|
59
|
+
# to more than one segment nil is returned since it is considered an invalid URL for a user.
|
|
49
60
|
def parse_to_full_user_url
|
|
50
61
|
return nil unless parseable?
|
|
51
62
|
|
|
52
|
-
|
|
53
|
-
return nil unless
|
|
63
|
+
clean_url!
|
|
64
|
+
return nil unless url.length == 1
|
|
54
65
|
|
|
55
|
-
[full_domain,
|
|
66
|
+
[full_domain, url].join('/')
|
|
56
67
|
end
|
|
57
68
|
|
|
58
69
|
def self.case_sensitive?
|
|
@@ -80,7 +91,12 @@ class URLParser
|
|
|
80
91
|
|
|
81
92
|
attr_accessor :url
|
|
82
93
|
|
|
83
|
-
|
|
94
|
+
# Clean up the string URL to find the non domain pieces of the URL and pass back
|
|
95
|
+
# to the specific parser class.
|
|
96
|
+
##
|
|
97
|
+
# @return [Array<String>, nil] Array of URL path segments following the domain or nil if the
|
|
98
|
+
# URL string does not contain the valid domain name.
|
|
99
|
+
def clean_url!
|
|
84
100
|
remove_whitespace
|
|
85
101
|
remove_quotes
|
|
86
102
|
remove_brackets
|
|
@@ -100,8 +116,18 @@ class URLParser
|
|
|
100
116
|
remove_git_scheme
|
|
101
117
|
remove_extra_segments
|
|
102
118
|
remove_git_extension
|
|
119
|
+
|
|
120
|
+
# url should have been transformed to an array during the various method calls
|
|
121
|
+
# The method is transforming the initialized url in place so any callers should
|
|
122
|
+
# reference url directly instead of expecting a return here.
|
|
123
|
+
url
|
|
103
124
|
end
|
|
104
125
|
|
|
126
|
+
# Join URL path segments for owner and repository name together with a "/" character.
|
|
127
|
+
#
|
|
128
|
+
#
|
|
129
|
+
# @return [String, nil] URL path segments joined by "/" or nil if there are not separate owner and
|
|
130
|
+
# repository name segments.
|
|
105
131
|
def format_url
|
|
106
132
|
return nil if url.nil?
|
|
107
133
|
return nil unless url.length == 2
|
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.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Pace
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-01-
|
|
11
|
+
date: 2024-01-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|