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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
# encoding: UTF-8
module LibXML
module XML
class Namespace
include Comparable
include Enumerable
# call-seq:
# namespace1 <=> namespace2
#
# Compares two namespace objects. Namespace objects are
# considered equal if their prefixes and hrefs are the same.
def <=>(other)
if self.prefix.nil? and other.prefix.nil?
self.href <=> other.href
elsif self.prefix.nil?
-1
elsif other.prefix.nil?
1
else
self.prefix <=> other.prefix
end
end
# call-seq:
# namespace.each {|ns| .. }
#
# libxml stores namespaces in memory as a linked list.
# Use the each method to iterate over the list. Note
# the first namespace in the loop is the current namespace.
#
# Usage:
# namespace.each do |ns|
# ..
# end
def each
ns = self
while ns
yield ns
ns = ns.next
end
end
# call-seq:
# namespace.to_s -> "string"
#
# Returns the string represenation of a namespace.
#
# Usage:
# namespace.to_s
def to_s
if self.prefix
"#{self.prefix}:#{self.href}"
else
self.href
end
end
end
end
end
|