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

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

Instance Method Summary collapse

Instance Method Details

#/(path) ⇒ Object



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

def /(path); search(path) end

#convert_to_xpath(rule) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 20

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



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

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

#get_elements_by_tag_name(tag) ⇒ Object



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

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

#raw_attributesObject



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

def raw_attributes; self end

#search(path) ⇒ Object



5
6
7
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 5

def search path
  super(*convert_to_xpath(path))
end

#targetObject



37
38
39
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 37

def target
  name
end

#to_original_htmlObject



41
42
43
# File 'lib/nokogiri/decorators/hpricot/node.rb', line 41

def to_original_html
  to_html
end