Class: Semi::Variables::Url
- Inherits:
-
Base
- Object
- Base
- Semi::Variables::Url
show all
- Defined in:
- lib/semi/variables/url.rb
Constant Summary
collapse
- @@url_re =
Regexp.new('^(?<proto>https?|ftp):\/{2}(?!\/)(?<host>[a-z\.0-9\-_]+)?(?::(?<port>\d{1,5}))?\/?(?<path>.*?)\/?(?<file>[^\/\?]+)?(?:\?(?<params>.*?))?$', Regexp::IGNORECASE)
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#!=, #!~, #&, #<=>, #==, #===, #=~, #^, #eql?, #equal?, #method_missing, #set, #to_s, #value, #|
Constructor Details
#initialize(val) ⇒ Url
Returns a new instance of Url.
8
9
10
11
12
13
14
|
# File 'lib/semi/variables/url.rb', line 8
def initialize(val)
if @@url_re.match(val)
@value = val
else
raise Semi::VariableError, '#{val} does not look like a URL'
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Semi::Variables::Base
Class Method Details
.validate(val) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/semi/variables/url.rb', line 20
def self.validate(val)
if ['String', 'Semi::Variables::Url'].include? val.class.to_s
if @@url_re.match(val.to_s)
return true
end
end
false
end
|
Instance Method Details
#file ⇒ Object
58
59
60
61
62
63
|
# File 'lib/semi/variables/url.rb', line 58
def file
match = @@url_re.match(@value)
if match
match['file']
end
end
|
#host ⇒ Object
37
38
39
40
41
42
|
# File 'lib/semi/variables/url.rb', line 37
def host
match = @@url_re.match(@value)
if match
match['host']
end
end
|
#params ⇒ Object
65
66
67
68
69
70
|
# File 'lib/semi/variables/url.rb', line 65
def params
match = @@url_re.match(@value)
if match
match['params']
end
end
|
#path ⇒ Object
51
52
53
54
55
56
|
# File 'lib/semi/variables/url.rb', line 51
def path
match = @@url_re.match(@value)
if match
match['path']
end
end
|
#port ⇒ Object
44
45
46
47
48
49
|
# File 'lib/semi/variables/url.rb', line 44
def port
match = @@url_re.match(@value)
if match
match['port']
end
end
|
#proto ⇒ Object
30
31
32
33
34
35
|
# File 'lib/semi/variables/url.rb', line 30
def proto
match = @@url_re.match(@value)
if match
match['proto']
end
end
|
#validate ⇒ Object
16
17
18
|
# File 'lib/semi/variables/url.rb', line 16
def validate
self.validate(@value)
end
|