Module: NokogiriExt

Included in:
Nokogiri::XML::Node
Defined in:
lib/nokogiri/nokogiri_ext.rb

Defined Under Namespace

Modules: Etest

Instance Method Summary collapse

Instance Method Details

#full_nameObject



2
3
4
5
# File 'lib/nokogiri/nokogiri_ext.rb', line 2

def full_name
  ns = namespace
  ns ? "#{ns}:#{name}" : name
end

#remove_blanksObject



25
26
27
28
29
# File 'lib/nokogiri/nokogiri_ext.rb', line 25

def remove_blanks
  transform do |n|
    n.name != "text" || !n.text.blank?
  end
end

#transform(&block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nokogiri/nokogiri_ext.rb', line 7

def transform(&block)
  case r = yield(self)
  when false
    self.remove
  when String
    Nokogiri::HTML.fragment(r).children.each do |n|
      add_previous_sibling n
    end

    self.remove
  when Nokogiri::XML::Node
    add_previous_sibling r
    self.remove
  else
    children.each do |child| child.transform(&block) end
  end
end