Class: XML::Smart::Dom::NodeSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/xml/smart_domnodeset.rb

Instance Method Summary collapse

Constructor Details

#initialize(nodeset) ⇒ NodeSet

Returns a new instance of NodeSet.



8
9
10
# File 'lib/xml/smart_domnodeset.rb', line 8

def initialize(nodeset)
  @nodeset = nodeset
end

Instance Method Details

#===(cls) ⇒ Object



12
# File 'lib/xml/smart_domnodeset.rb', line 12

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

#[](*a) ⇒ Object



17
# File 'lib/xml/smart_domnodeset.rb', line 17

def [](*a);  Dom::smart_helper(@nodeset[*a]); end

#at(*a) ⇒ Object



16
# File 'lib/xml/smart_domnodeset.rb', line 16

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

#delete_all!Object



21
# File 'lib/xml/smart_domnodeset.rb', line 21

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

#delete_at(*a) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/xml/smart_domnodeset.rb', line 31

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

#delete_if(&block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/xml/smart_domnodeset.rb', line 45

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

#each(&block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/xml/smart_domnodeset.rb', line 23

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

#empty?Boolean

Returns:

  • (Boolean)


20
# File 'lib/xml/smart_domnodeset.rb', line 20

def empty?;       @nodeset.empty?; end

#firstObject



14
# File 'lib/xml/smart_domnodeset.rb', line 14

def first;        Dom::smart_helper(@nodeset.first); end

#lastObject



15
# File 'lib/xml/smart_domnodeset.rb', line 15

def last;         Dom::smart_helper(@nodeset.last); end

#lengthObject



19
# File 'lib/xml/smart_domnodeset.rb', line 19

def length;       @nodeset.length; end