-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurlsorter.rb
48 lines (37 loc) · 1.36 KB
/
urlsorter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def urlsorter url
#Protocal http
seperaterProtocal = 0
while url[seperaterProtocal].chr != ':' && seperaterProtocal < url.length
seperaterProtocal = seperaterProtocal + 1
end
protocal = url[0..seperaterProtocal - 1]
#subdomain
seperaterAddress = seperaterProtocal
while url[seperaterAddress].chr != '.' && seperaterAddress < url.length
seperaterAddress = seperaterAddress + 1
end
#if seperaterProtocal >
subdomain = url[seperaterProtocal+3..seperaterAddress-1]
seperaterDomain = seperaterAddress
while url[seperaterDomain].chr != '/' && seperaterDomain < url.length
seperaterDomain = seperaterDomain + 1
end
domain = url[seperaterProtocal+7..seperaterDomain-5]
seperatorTLD = seperaterDomain
while url[seperatorTLD].chr != '/' && seperatorTLD < url.length
seperatorTLD = seperatorTLD + 1
end
tld = url[seperaterDomain-3..seperatorTLD-1]
seperatorPath = seperatorTLD - 1
while seperatorPath < url.length #url[seperatorPath].chr != '' &&
seperatorPath = seperatorPath + 1
end
path = url[seperatorTLD+1..seperatorPath-2]
puts
puts "Protocal: #{protocal}" #http
puts "Subdomain: #{subdomain}" #www
puts "Domain: #{domain}" #google
puts "TLD: #{tld}" #.com
puts "Path: #{path}" #gmaps
end
urlsorter('http://blog.google.com/ruby-on-rails')