Class: Rexle::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/rexslt.rb

Instance Method Summary collapse

Instance Method Details

#attribute_scan(node) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/rexslt.rb', line 11

def attribute_scan(node)
  result = ''
  attr = %w(id class).detect {|x| node.attributes.has_key? x}
  if attr then
    value = node.attribute[attr]
    result = "[@%s='%s']" % [attr, value]
  end
  result
end

#doc_scan(node, option = nil) ⇒ Object



21
22
23
24
25
26
# File 'lib/rexslt.rb', line 21

def doc_scan(node, option=nil)
  name = node.name
  attribute = option == :no_cond ? '' : attribute_scan(node)
  result = doc_scan(node.parent,option) unless node.root === node.doc_root
  [result, name.to_s + attribute]
end

#to_xpath(option = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rexslt.rb', line 10

def to_xpath(option=nil)
  def attribute_scan(node)
    result = ''
    attr = %w(id class).detect {|x| node.attributes.has_key? x}
    if attr then
      value = node.attribute[attr]
      result = "[@%s='%s']" % [attr, value]
    end
    result
  end

  def doc_scan(node, option=nil)
    name = node.name
    attribute = option == :no_cond ? '' : attribute_scan(node)
    result = doc_scan(node.parent,option) unless node.root === node.doc_root
    [result, name.to_s + attribute]
  end

  doc_scan(self, option).flatten.compact.join('/')
end