Sha256: 93e089b84ad5c66a21988796e5b9befd5c2bd1a9f32504779f235c6a3c5faac9

Contents?: true

Size: 1.5 KB

Versions: 20

Compression:

Stored size: 1.5 KB

Contents

module XML
  module Smart
    class Dom

      class AttributeSet
        include Enumerable

        def initialize(element)
          @element = element
          @set = @element.attributes
        end

        def ===(cls); self.is_a? cls; end

        def names
          @set.keys 
        end

        def has_attr?(a); @set.has_key?(a) end
        alias :include? :has_attr?
        alias :attr? :has_attr?
        alias :member? :has_attr?

        def [](name,attr=false)
          return nil unless has_attr?(name)
          if attr == false 
            @element.attribute(name).value
          else  
            Attribute.new(@element.attribute(name))
          end 
        end
        def []=(name,value);
          @element[name] = value
        end

        def length;      @set.length; end
        def empty?;      @set.empty?; end
        def delete_all!; @set.each { |k,a| a.remove }; end

        def each(&block)
          return self if block.nil?
          @set.each do |k,node|
            block.call Dom::smart_helper(node)
          end
          self
        end

        def delete_at!(name)
          tmp = @set[name]
          if tmp.is_a?(Nokogiri::XML::Attr)
            tmp.remove
            true
          else
            false
          end
        end

        def delete_if!(&block)
          return self if block.nil?
          @set.each do |k,node|
            node.remove if block.call(Dom::smart_helper(node))
          end
          self
        end
      end  
    
    end
  end  
end  

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
xml-smart-0.5.3 lib/xml/smart_domattributeset.rb
xml-smart-0.5.2 lib/xml/smart_domattributeset.rb
xml-smart-0.5.1 lib/xml/smart_domattributeset.rb
xml-smart-0.5.0 lib/xml/smart_domattributeset.rb
xml-smart-0.4.4 lib/xml/smart_domattributeset.rb
xml-smart-0.4.3 lib/xml/smart_domattributeset.rb
xml-smart-0.4.2 lib/xml/smart_domattributeset.rb
xml-smart-0.4.1 lib/xml/smart_domattributeset.rb
xml-smart-0.4.0 lib/xml/smart_domattributeset.rb
xml-smart-0.3.22 lib/xml/smart_domattributeset.rb
xml-smart-0.3.21 lib/xml/smart_domattributeset.rb
xml-smart-0.3.20 lib/xml/smart_domattributeset.rb
xml-smart-0.3.19 lib/xml/smart_domattributeset.rb
xml-smart-0.3.18 lib/xml/smart_domattributeset.rb
xml-smart-0.3.17 lib/xml/smart_domattributeset.rb
xml-smart-0.3.16 lib/xml/smart_domattributeset.rb
xml-smart-0.3.15 lib/xml/smart_domattributeset.rb
xml-smart-0.3.14 lib/xml/smart_domattributeset.rb
xml-smart-0.3.12 lib/xml/smart_domattributeset.rb
xml-smart-0.3.11 lib/xml/smart_domattributeset.rb