Class: Ape::AtomURI

Inherits:
Object
  • Object
show all
Defined in:
lib/ape/atomURI.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_uri) ⇒ AtomURI

Returns a new instance of AtomURI.



8
9
10
11
12
13
14
# File 'lib/ape/atomURI.rb', line 8

def initialize base_uri
  if base_uri.kind_of? URI
    @base = base_uri
  else
    @base = URI.parse base_uri
  end
end

Class Method Details

.check(uri_string) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ape/atomURI.rb', line 47

def AtomURI.check(uri_string)
  if uri_string.kind_of? URI
    uri = uri_string
  else
    begin
      uri = URI.parse(uri_string)
    rescue URI::InvalidURIError
      return "Invalid URI: #{$!}"
    end
  end

  unless uri.scheme =~ /^https?$/ 
    return "URI scheme must be 'http' or 'https', not '#{uri.scheme}'"
  else
    return uri
  end
end

.on_the_wire(uri) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/ape/atomURI.rb', line 65

def AtomURI.on_the_wire uri
  if uri.query
    "#{uri.path}?#{uri.query}"
  else
    uri.path
  end
end

Instance Method Details

#absolutize(uri_s, context) ⇒ Object

Given a URI pulled out of the middle of an XML doc (‘context’ provides

containing element) absolutize it if it's relative, with proper regard
for xml:base


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ape/atomURI.rb', line 20

def absolutize uri_s, context
  begin
    uri = URI.parse uri_s
    return uri_s if uri.absolute?

    path_base = @base
    path_to(context).each do |node|
      if (xb = node.attributes['xml:base'])
        xb = URI.parse xb
        if xb.absolute? then path_base = xb else path_base.merge! xb end
      end
    end

    return path_base.merge(uri).to_s
  rescue URI::InvalidURIError
    return nil
  end
end

#path_to(node) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/ape/atomURI.rb', line 39

def path_to node
  if node.class == REXML::Element
    path_to(node.parent) << node
  else
    [ ]
  end
end