Module: OpenfireAdmin::ElementHelper

Defined in:
lib/openfire_admin/html_parser.rb

Overview

REXML Element extention. like nokogiri

Instance Method Summary collapse

Instance Method Details

#[](arg, name = nil) ⇒ String|nil

find element attribute

Parameters:

  • attribute (Symbol)

    name

Returns:

  • (String|nil)


31
32
33
34
35
36
37
# File 'lib/openfire_admin/html_parser.rb', line 31

def [](arg, name=nil)
  if arg.is_a?(Symbol)
    self.attributes[arg.to_s]
  else
    super
  end
end

#at(xpath) ⇒ REXML::Element extends ElementHelper

find first element by xpath

Parameters:

  • xpath (String)

Returns:



9
10
11
12
13
14
# File 'lib/openfire_admin/html_parser.rb', line 9

def at(xpath)
  xpath = ".#{xpath}" if !self.is_a?(REXML::Document) and xpath =~ /^\//
  elm = REXML::XPath.first(self,xpath)
  elm.extend(ElementHelper)
  elm
end

#search(xpath) ⇒ Array<REXML::Element extends ElementHelper>

find elements by xpath

Parameters:

  • xpath (String)

Returns:



19
20
21
22
23
24
25
26
# File 'lib/openfire_admin/html_parser.rb', line 19

def search(xpath)
  xpath = ".#{xpath}" if !self.is_a?(REXML::Document) and xpath =~ /^\//
  ret = REXML::XPath.match(self,xpath).map{|elm|
    elm.extend(ElementHelper)
    elm
    block_given? ? (yield elm) : elm
  }
end