Sha256: 703f43e67fa9537af8359ad1c0f5daba888f692d928a4ebba34269f4c4106600

Contents?: true

Size: 1.5 KB

Versions: 20

Compression:

Stored size: 1.5 KB

Contents

module XML
  module Smart
    class Dom

      class NodeSet
        include Enumerable

        def initialize(nodeset)
          @nodeset = nodeset
        end

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

        def first;        Dom::smart_helper(@nodeset.first); end
        def last;         Dom::smart_helper(@nodeset.last); end
        def at(*a);  Dom::smart_helper(@nodeset[*a]); end
        def [](*a);  Dom::smart_helper(@nodeset[*a]); end

        def length;       @nodeset.length; end
        def empty?;       @nodeset.empty?; end
        def delete_all!;  @nodeset.remove; @nodeset.to_a.each { |n| @nodeset.delete(n) }; true  end

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

        def delete_at(*a)
          tmp = @nodeset[*a]
          case tmp
            when Nokogiri::XML::NodeSet
              tmp.each { |node| @nodeset.delete(node.remove) }
              true
            when Nokogiri::XML::Node
              @nodeset.delete(tmp.remove)
              true
            else
              false
          end
        end

        def delete_if(&block) 
          return self if block.nil?
          tmp = []
          @nodeset.each do |node| 
            if block.call(Dom::smart_helper(node))
              tmp << node.remove
            end  
          end    
          tmp.each { |t| @nodeset.delete(t) }
          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_domnodeset.rb
xml-smart-0.5.2 lib/xml/smart_domnodeset.rb
xml-smart-0.5.1 lib/xml/smart_domnodeset.rb
xml-smart-0.5.0 lib/xml/smart_domnodeset.rb
xml-smart-0.4.4 lib/xml/smart_domnodeset.rb
xml-smart-0.4.3 lib/xml/smart_domnodeset.rb
xml-smart-0.4.2 lib/xml/smart_domnodeset.rb
xml-smart-0.4.1 lib/xml/smart_domnodeset.rb
xml-smart-0.4.0 lib/xml/smart_domnodeset.rb
xml-smart-0.3.22 lib/xml/smart_domnodeset.rb
xml-smart-0.3.21 lib/xml/smart_domnodeset.rb
xml-smart-0.3.20 lib/xml/smart_domnodeset.rb
xml-smart-0.3.19 lib/xml/smart_domnodeset.rb
xml-smart-0.3.18 lib/xml/smart_domnodeset.rb
xml-smart-0.3.17 lib/xml/smart_domnodeset.rb
xml-smart-0.3.16 lib/xml/smart_domnodeset.rb
xml-smart-0.3.15 lib/xml/smart_domnodeset.rb
xml-smart-0.3.14 lib/xml/smart_domnodeset.rb
xml-smart-0.3.12 lib/xml/smart_domnodeset.rb
xml-smart-0.3.11 lib/xml/smart_domnodeset.rb