In Files

Parent

EimXML::Element

Constants

NEST

Attributes

attributes[R]
contents[R]
name[R]

Public Class Methods

new(name, attributes={}) click to toggle source
# File lib/eim_xml.rb, line 65
def initialize(name, attributes={})
        @name = name.to_sym
        @attributes = Hash.new
        @contents = Array.new

        attributes.each do |k, v|
                @attributes[k.to_sym] = v
        end

        yield(self) if block_given?
end

Public Instance Methods

<<(v) click to toggle source
Alias for: add
==(xml) click to toggle source
# File lib/eim_xml.rb, line 127
def ==(xml)
        return false unless xml.is_a?(Element)
        @name==xml.name && @attributes==xml.attributes && @contents==xml.contents
end
=~(obj, attr=nil) click to toggle source
Alias for: match
[](key) click to toggle source
# File lib/eim_xml.rb, line 137
def [](key)
        if key.is_a?(Fixnum)
                @contents[key]
        else
                @attributes[key.to_sym]
        end
end
[]=(key, value) click to toggle source
Alias for: add_attribute
add(v) click to toggle source
# File lib/eim_xml.rb, line 82
def add(v)
        case v
        when nil
        when Array
                v.each{|i| self.add(i)}
        else
                @contents << v
        end
        self
end
Also aliased as: <<
add_attribute(key, value) click to toggle source
# File lib/eim_xml.rb, line 132
def add_attribute(key, value)
        @attributes[key.to_sym] = value
end
Also aliased as: []=
del_attribute(key) click to toggle source
# File lib/eim_xml.rb, line 145
def del_attribute(key)
        @attributes.delete(key.to_sym)
end
find(obj, dst=Element.new(:found)) click to toggle source
# File lib/eim_xml.rb, line 195
def find(obj, dst=Element.new(:found))
        return find(Element.new(obj, dst)) if dst.is_a?(Hash)

        dst << self if match(obj)
        @contents.each do |i|
                case
                when i.is_a?(Element)
                        i.find(obj, dst)
                when obj.is_a?(Module) && i.is_a?(obj)
                        dst << i
                end
        end
        dst
end
has?(obj, attr=nil) click to toggle source
# File lib/eim_xml.rb, line 181
def has?(obj, attr=nil)
        return has?(Element.new(obj, attr)) if attr

        @contents.any? do |i|
                if i.is_a?(Element)
                        i.match(obj) || i.has?(obj)
                else
                        obj.is_a?(Module) && i.is_a?(obj)
                end
        end
end
Also aliased as: has_element?, include?
has_element?(obj, attr=nil) click to toggle source
Alias for: has?
include?(obj, attr=nil) click to toggle source
Alias for: has?
inspect(out = "") click to toggle source
Alias for: to_s
match(obj, attr=nil) click to toggle source
# File lib/eim_xml.rb, line 153
def match(obj, attr=nil)
        return match(Element.new(obj, attr)) if attr
        return obj=~@name.to_s if obj.is_a?(Regexp)
        return @name==obj if obj.is_a?(Symbol)
        return is_a?(obj) if obj.is_a?(Module)

        raise ArgumentError unless obj.is_a?(Element)

        return false unless @name==obj.name

        obj.attributes.all? do |k, v|
                (v.nil? && !@attributes.include?(k)) ||
                        (@attributes.include?(k) && (v.is_a?(Regexp) ? v =~ @attributes[k] : PCString[v] == PCString[@attributes[k]]))
        end and obj.contents.all? do |i|
                case i
                when Element
                        has_element?(i)
                when String
                        pcstring_contents.include?(PCString.new(i))
                when PCString
                        pcstring_contents.include?(i)
                when Regexp
                        @contents.any?{|c| c.is_a?(String) and i=~c}
                end                                 
        end
end
Also aliased as: =~
name_and_attributes(out="") click to toggle source
# File lib/eim_xml.rb, line 94
def name_and_attributes(out="")
        out << "#{@name}"
        @attributes.each do |k, v|
                next unless v
                out << " #{k}='#{PCString===v ? v : PCString.encode(v.to_s)}'"
        end
end
pcstring_contents() click to toggle source
# File lib/eim_xml.rb, line 149
def pcstring_contents
        @contents.select{|c| c.is_a?(String)||c.is_a?(PCString)}.map{|c| c.is_a?(String) ? PCString.new(c) : c}
end
to_s(out = "") click to toggle source
Also aliased as: inspect
Alias for: write_to
write_to(out = "") click to toggle source
# File lib/eim_xml.rb, line 102
def write_to(out = "")
        out << "<"
        name_and_attributes(out)

        if @contents.empty?
                out << " />"
        else
                out << ">"
                @contents.each do |c|
                        case c
                        when Element
                                c.write_to(out)
                        when PCString
                                out << c.to_s
                        else
                                out << PCString.encode(c.to_s)
                        end
                end
                out << "</#{@name}>"
        end
        out
end
Also aliased as: to_s

Protected Instance Methods

name=(new_name) click to toggle source
# File lib/eim_xml.rb, line 77
def name=(new_name)
        @name = new_name.to_sym
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.