Module: Webrat::XML
- Defined in:
- lib/webrat/core/xml.rb
Overview
:nodoc:
Class Method Summary collapse
-
.define_dom_method(object, dom) ⇒ Object
:nodoc:.
- .detect_encoding(string) ⇒ Object
-
.document(stringlike) ⇒ Object
:nodoc:.
-
.html_document(stringlike) ⇒ Object
:nodoc:.
-
.xml_document(stringlike) ⇒ Object
:nodoc:.
Class Method Details
.define_dom_method(object, dom) ⇒ Object
:nodoc:
52 53 54 55 56 |
# File 'lib/webrat/core/xml.rb', line 52 def self.define_dom_method(object, dom) #:nodoc: object..send(:define_method, :dom) do dom end end |
.detect_encoding(string) ⇒ Object
20 21 22 |
# File 'lib/webrat/core/xml.rb', line 20 def self.detect_encoding(string) string.isutf8 ? "UTF-8" : nil if string.respond_to?(:isutf8) end |
.document(stringlike) ⇒ Object
:nodoc:
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/webrat/core/xml.rb', line 6 def self.document(stringlike) #:nodoc: return stringlike.dom if stringlike.respond_to?(:dom) if Nokogiri::HTML::Document === stringlike stringlike elsif Nokogiri::XML::NodeSet === stringlike stringlike elsif stringlike.respond_to?(:body) Nokogiri::HTML(stringlike.body.to_s, nil, detect_encoding(stringlike.body.to_s)) else Nokogiri::HTML(stringlike.to_s, nil, detect_encoding(stringlike.to_s)) end end |
.html_document(stringlike) ⇒ Object
:nodoc:
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/webrat/core/xml.rb', line 24 def self.html_document(stringlike) #:nodoc: return stringlike.dom if stringlike.respond_to?(:dom) if Nokogiri::HTML::Document === stringlike stringlike elsif Nokogiri::XML::NodeSet === stringlike stringlike elsif stringlike.respond_to?(:body) Nokogiri::HTML(stringlike.body.to_s, nil, detect_encoding(stringlike.body.to_s)) else Nokogiri::HTML(stringlike.to_s, nil, detect_encoding(stringlike.to_s)) end end |
.xml_document(stringlike) ⇒ Object
:nodoc:
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/webrat/core/xml.rb', line 38 def self.xml_document(stringlike) #:nodoc: return stringlike.dom if stringlike.respond_to?(:dom) if Nokogiri::HTML::Document === stringlike stringlike elsif Nokogiri::XML::NodeSet === stringlike stringlike elsif stringlike.respond_to?(:body) Nokogiri::XML(stringlike.body.to_s, nil, detect_encoding(stringlike.body.to_s)) else Nokogiri::XML(stringlike.to_s, nil, detect_encoding(stringlike.body.to_s)) end end |