Class: XML::Parser::SAXDriver::URL
- Inherits:
-
Object
- Object
- XML::Parser::SAXDriver::URL
- Defined in:
- lib/xml/saxdriver.rb
Overview
very simple URL parser
Instance Attribute Summary collapse
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#urlpath ⇒ Object
readonly
Returns the value of attribute urlpath.
Instance Method Summary collapse
-
#initialize(url, url2 = nil) ⇒ URL
constructor
A new instance of URL.
- #to_s ⇒ Object
Constructor Details
#initialize(url, url2 = nil) ⇒ URL
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/xml/saxdriver.rb', line 30 def initialize(url, url2 = nil) @scheme = '' @login = '' @urlpath = '' if url.kind_of?(String) && url2.nil? if url =~ /^([a-z0-9\+\-\.]+):\/\/([^\/]+)(\/.*)$/ @scheme, @login, @urlpath = $1, $2, $3 else url = File::(url) @scheme, @login, @urlpath = "file", "localhost", url end elsif url.kind_of?(URL) && url2.kind_of?(String) if url2 =~ /^([a-z0-9\+\-\.]+):\/\/([^\/]+)(\/.*)$/ @scheme, @login, @urlpath = $1, $2, $3 else @scheme = url.scheme @login = url.login if url2 =~ /^\// @urlpath = url2 else path = url.urlpath path =~ /^([^\#]+)\#?(.*)$/ path = $1 path =~ /^([^\?]+)\??(.*)$/ path = $1 path =~ /^(.+)\/(.*)/ path = $1 @urlpath = File.(path + '/' + url2) end end end end |
Instance Attribute Details
#login ⇒ Object (readonly)
Returns the value of attribute login.
27 28 29 |
# File 'lib/xml/saxdriver.rb', line 27 def login @login end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
26 27 28 |
# File 'lib/xml/saxdriver.rb', line 26 def scheme @scheme end |
#urlpath ⇒ Object (readonly)
Returns the value of attribute urlpath.
28 29 30 |
# File 'lib/xml/saxdriver.rb', line 28 def urlpath @urlpath end |
Instance Method Details
#to_s ⇒ Object
63 64 65 |
# File 'lib/xml/saxdriver.rb', line 63 def to_s @scheme + "://" + @login + @urlpath end |