Class: Nokogiri::HTML5::Document

Inherits:
Nokogiri::HTML::Document
  • Object
show all
Defined in:
lib/nokogumbo/html5/document.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(string_or_io, url = nil, encoding = nil, **options) {|options| ... } ⇒ Object

Yields:

  • (options)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/nokogumbo/html5/document.rb', line 4

def self.parse(string_or_io, url = nil, encoding = nil, **options, &block)
  yield options if block_given?
	string_or_io = '' unless string_or_io

  if string_or_io.respond_to?(:encoding) && string_or_io.encoding.name != 'ASCII-8BIT'
    encoding ||= string_or_io.encoding.name
  end

  if string_or_io.respond_to?(:read) && string_or_io.respond_to?(:path)
    url ||= string_or_io.path
  end
  unless string_or_io.respond_to?(:read) || string_or_io.respond_to?(:to_str)
    raise ArgumentError.new("not a string or IO object")
  end
  do_parse(string_or_io, url, encoding, options)
end

.read_io(io, url = nil, encoding = nil, **options) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
# File 'lib/nokogumbo/html5/document.rb', line 21

def self.read_io(io, url = nil, encoding = nil, **options)
  raise ArgumentError.new("io object doesn't respond to :read") unless io.respond_to?(:read)
  do_parse(io, url, encoding, options)
end

.read_memory(string, url = nil, encoding = nil, **options) ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
# File 'lib/nokogumbo/html5/document.rb', line 26

def self.read_memory(string, url = nil, encoding = nil, **options)
  raise ArgumentError.new("string object doesn't respond to :to_str") unless string.respond_to?(:to_str)
  do_parse(string, url, encoding, options)
end

Instance Method Details

#fragment(tags = nil) ⇒ Object



31
32
33
# File 'lib/nokogumbo/html5/document.rb', line 31

def fragment(tags = nil)
  DocumentFragment.new(self, tags, self.root)
end

#to_xml(options = {}, &block) ⇒ Object



35
36
37
38
39
# File 'lib/nokogumbo/html5/document.rb', line 35

def to_xml(options = {}, &block)
  # Bypass XML::Document#to_xml which doesn't add
  # XML::Node::SaveOptions::AS_XML like XML::Node#to_xml does.
  XML::Node.instance_method(:to_xml).bind(self).call(options, &block)
end