github_urls 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/github_urls/parser.rb +112 -0
- data/lib/github_urls/version.rb +1 -1
- data/lib/github_urls.rb +2 -27
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c390218d35e75397d87eae2c93c3e3923fb6f5f
|
4
|
+
data.tar.gz: 053a741a0be43c4c7f6cf3e58d908e5e098e61a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f049411671636b4eb972b8f9b82b30325b9cb6c7ee966e0712b98663d4f878e4f8c1f28617d07805cbeb688539b19d897bcb3bb07e97623fa9ee50058ee5d84
|
7
|
+
data.tar.gz: 5f905b289654b31d426fbca2e2e02ee930640d150240adb2d5415b08c98512a06e09be855ad443a2b0d738d0c50bad30618a3867b6bc87b51a111c1d83044ca3
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module GithubUrls
|
2
|
+
class Parser
|
3
|
+
def self.parse(url)
|
4
|
+
new(url).parse
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_accessor :url
|
8
|
+
|
9
|
+
def initialize(url)
|
10
|
+
@url = url
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
return nil unless parseable?
|
15
|
+
|
16
|
+
if url = extractable_early?
|
17
|
+
url
|
18
|
+
else
|
19
|
+
clean_url
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def clean_url
|
24
|
+
remove_whitespace
|
25
|
+
remove_brackets
|
26
|
+
remove_anchors
|
27
|
+
remove_querystring
|
28
|
+
remove_auth_user
|
29
|
+
remove_equals_sign
|
30
|
+
remove_scheme
|
31
|
+
remove_subdomain
|
32
|
+
remove_github_domain
|
33
|
+
remove_git_extension
|
34
|
+
remove_git_scheme
|
35
|
+
remove_extra_segments
|
36
|
+
format_url
|
37
|
+
end
|
38
|
+
|
39
|
+
def extractable_early?
|
40
|
+
return false if github_website_url?
|
41
|
+
|
42
|
+
match = url.match(/([\w\.@\:\-_~]+)\.github\.(io|com|org)\/([\w\.@\:\-\_\~]+)/i)
|
43
|
+
if match && match.length == 4
|
44
|
+
return "#{match[1]}/#{match[3]}"
|
45
|
+
end
|
46
|
+
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def parseable?
|
51
|
+
!url.nil? && url.include?('github')
|
52
|
+
end
|
53
|
+
|
54
|
+
def remove_extra_segments
|
55
|
+
self.url = url.split('/').reject(&:blank?)[0..1]
|
56
|
+
end
|
57
|
+
|
58
|
+
def remove_brackets
|
59
|
+
url.gsub!(/>|<|\(|\)|\[|\]/, '')
|
60
|
+
end
|
61
|
+
|
62
|
+
def remove_querystring
|
63
|
+
url.gsub!(/(\?\S*)$/i, '')
|
64
|
+
end
|
65
|
+
|
66
|
+
def remove_anchors
|
67
|
+
url.gsub!(/(#\S*)$/i, '')
|
68
|
+
end
|
69
|
+
|
70
|
+
def remove_git_scheme
|
71
|
+
url.gsub!(/git\/\//i, '')
|
72
|
+
end
|
73
|
+
|
74
|
+
def remove_git_extension
|
75
|
+
url.gsub!(/(\.git|\/)$/i, '')
|
76
|
+
end
|
77
|
+
|
78
|
+
def remove_equals_sign
|
79
|
+
self.url = url.split('=')[-1]
|
80
|
+
end
|
81
|
+
|
82
|
+
def remove_auth_user
|
83
|
+
self.url = url.split('@')[-1]
|
84
|
+
end
|
85
|
+
|
86
|
+
def remove_whitespace
|
87
|
+
url.gsub!(/\s/, '')
|
88
|
+
end
|
89
|
+
|
90
|
+
def remove_scheme
|
91
|
+
url.gsub!(/(((git|ssh|hg|svn|scm|http|https)+?:)+?)/i, '')
|
92
|
+
end
|
93
|
+
|
94
|
+
def remove_subdomain
|
95
|
+
url.gsub!(/(www|ssh|raw|git|wiki)+?\./i, '')
|
96
|
+
end
|
97
|
+
|
98
|
+
def remove_github_domain
|
99
|
+
url.gsub!(/(github.io|github.com|github.org|raw.githubusercontent.com)+?(:|\/)?/i, '')
|
100
|
+
end
|
101
|
+
|
102
|
+
def github_website_url?
|
103
|
+
url.match(/www.github.(io|com|org)/i)
|
104
|
+
end
|
105
|
+
|
106
|
+
def format_url
|
107
|
+
return nil unless url.length == 2
|
108
|
+
url.join('/')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
data/lib/github_urls/version.rb
CHANGED
data/lib/github_urls.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "github_urls/version"
|
2
|
+
require "github_urls/parser"
|
2
3
|
|
3
4
|
class Object
|
4
5
|
def blank?
|
@@ -8,32 +9,6 @@ end
|
|
8
9
|
|
9
10
|
module GithubUrls
|
10
11
|
def self.parse(url_string)
|
11
|
-
|
12
|
-
return nil unless url_string.include?('github')
|
13
|
-
if extract_github_io_name(url_string)
|
14
|
-
return extract_github_io_name(url_string)
|
15
|
-
end
|
16
|
-
url_string = url_string.gsub(/\s/, '')
|
17
|
-
url_string = url_string.split('@')[-1]
|
18
|
-
url_string = url_string.split('=')[-1]
|
19
|
-
url_string = url_string.gsub(/(((git|ssh|hg|svn|scm|http|https)+?:)+?)/i, '')
|
20
|
-
url_string = url_string.gsub(/(www|ssh|raw|git|wiki)+?\./i, '')
|
21
|
-
url_string = url_string.gsub(/(github.io|github.com|github.org|raw.githubusercontent.com)+?(:|\/)?/i, '')
|
22
|
-
url_string = url_string.gsub(/(\.git|\/)$/i, '')
|
23
|
-
url_string = url_string.gsub(/git\/\//i, '')
|
24
|
-
url_string = url_string.gsub(/(#\S*)$/i, '')
|
25
|
-
url_string = url_string.gsub(/(\?\S*)$/i, '')
|
26
|
-
url_string = url_string.gsub(/>|<|(|)|[|]/, '')
|
27
|
-
url_string = url_string.split('/').reject(&:blank?)[0..1]
|
28
|
-
return nil unless url_string.length == 2
|
29
|
-
url_string.join('/')
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.extract_github_io_name(url)
|
33
|
-
return nil if url.nil?
|
34
|
-
return nil if url.match(/www.github.(io|com|org)/i)
|
35
|
-
match = url.match(/([\w\.@\:\-_~]+)\.github\.(io|com|org)\/([\w\.@\:\-\_\~]+)/i)
|
36
|
-
return nil unless match && match.length == 4
|
37
|
-
"#{match[1]}/#{match[3]}"
|
12
|
+
Parser.new(url_string).parse
|
38
13
|
end
|
39
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_urls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Nesbitt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- bin/setup
|
72
72
|
- github_urls.gemspec
|
73
73
|
- lib/github_urls.rb
|
74
|
+
- lib/github_urls/parser.rb
|
74
75
|
- lib/github_urls/version.rb
|
75
76
|
homepage: https://github.com/librariesio/github_urls
|
76
77
|
licenses:
|