Class: XML::Parser::SAXDriver::URL

Inherits:
Object
  • Object
show all
Defined in:
lib/xml/saxdriver.rb

Overview

very simple URL parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, url2 = nil) ⇒ URL

Returns a new instance of 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::expand_path(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.
      if url2 =~ /^\//
        @urlpath = url2
      else
        path = url.urlpath
        path =~ /^([^\#]+)\#?(.*)$/
        path = $1
        path =~ /^([^\?]+)\??(.*)$/
        path = $1
        path =~ /^(.+)\/(.*)/
        path = $1
        @urlpath = File.expand_path(path + '/' + url2)
      end
    end
  end
end

Instance Attribute Details

#loginObject (readonly)

Returns the value of attribute login.



27
28
29
# File 'lib/xml/saxdriver.rb', line 27

def 
  @login
end

#schemeObject (readonly)

Returns the value of attribute scheme.



26
27
28
# File 'lib/xml/saxdriver.rb', line 26

def scheme
  @scheme
end

#urlpathObject (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_sObject



63
64
65
# File 'lib/xml/saxdriver.rb', line 63

def to_s
  @scheme + "://" + @login + @urlpath
end