-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_modifier.rb
47 lines (37 loc) · 1014 Bytes
/
url_modifier.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
require 'uri'
class UrlModifier
SHORTCUTS = {'socrates' => 'http://socrates.devbootcamp.com/',
'hn' => 'https://news.ycombinator.com/',
'github' => 'https://github.com/',
'tumblr' => 'http://www.tumblr.com/dashboard',
'awesome' => 'http://brogrammersguide.tumblr.com/'}
MODIFIER = {'1' => 'challenges#week-1-ruby',
'2' => 'challenges#week-2-oo-design',
'3' => 'challenges#week-3-databases'}
def shortcut(input_url)
split_args = decoder(input_url).chomp.split(' ')
if SHORTCUTS[split_args[0]]
url = base_url(split_args[0])
modifier = split_args[1].nil? ? '' : add_modifier(split_args[1])
url + modifier
else
google_it(input_url)
end
end
def decoder(input_url)
URI.decode(input_url)
end
def base_url(arg)
SHORTCUTS[arg] ? SHORTCUTS[arg] : google_it(arg)
end
def add_modifier(arg)
if MODIFIER[arg]
MODIFIER[arg]
else
''
end
end
def google_it(url)
URI.escape("https://www.google.com/search?q=#{url}")
end
end