Module: Nokogiri::Decorators::Hpricot::Node

Defined in:
lib/nokogiri/decorators/hpricot/node.rb

Instance Method Summary collapse

Instance Method Details

#/(path) ⇒ Object



14
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 14

def /(path); search(path) end

#convert_to_xpath(rule) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 31

def convert_to_xpath(rule)
  rule = rule.to_s
  case rule
  when %r{^//}
    [".#{rule}"]
  when %r{^/}
    [rule]
  when %r{^.//}
    [rule]
  else
    ctx = CSS::Parser.parse(rule)
    visitor = CSS::XPathVisitor.new
    visitor.extend(Hpricot::XPathVisitor)
    ctx.map { |ast| './/' + visitor.accept(ast.preprocess!) }
  end
end

#get_element_by_id(element_id) ⇒ Object



23
24
25
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 23

def get_element_by_id element_id
  search("//*[@id='#{element_id}']").first
end

#get_elements_by_tag_name(tag) ⇒ Object



27
28
29
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 27

def get_elements_by_tag_name tag
  search("//#{tag}")
end

#raw_attributesObject



21
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 21

def raw_attributes; self end

#search(*paths) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 5

def search *paths
  ns = paths.last.is_a?(Hash) ? paths.pop : {}
  converted = paths.map { |path|
    convert_to_xpath(path)
  }.flatten.uniq

  namespaces = document.xml? ? document.namespaces.merge(ns) : ns
  super(*converted + [namespaces])
end

#targetObject



48
49
50
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 48

def target
  name
end

#to_original_htmlObject



52
53
54
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 52

def to_original_html
  to_html
end

#xpath(*args) ⇒ Object



16
17
18
19
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 16

def xpath *args
  return super if args.length > 0
  path
end