Module: Webrat::XML

Defined in:
lib/webrat/core/xml.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.define_dom_method(object, dom) ⇒ Object

:nodoc:


24
25
26
27
28
# File 'lib/webrat/core/xml.rb', line 24

def self.define_dom_method(object, dom) #:nodoc:
  object.meta_class.send(:define_method, :dom) do
    dom
  end
end

.document(stringlike) ⇒ Object

:nodoc:


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/webrat/core/xml.rb', line 6

def self.document(stringlike) #:nodoc:
  return stringlike.dom if stringlike.respond_to?(:dom)

  case stringlike
  when Nokogiri::HTML::Document, Nokogiri::XML::NodeSet
    stringlike
  else
    stringlike = stringlike.body if stringlike.respond_to?(:body)
    stringlike = stringlike.to_s

    if stringlike =~ /\<\?xml/
      Nokogiri::XML(stringlike)
    else
      Nokogiri::HTML(stringlike)
    end
  end
end