json-ld 3.2.4 → 3.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/json/ld/api.rb +807 -771
- data/lib/json/ld/compact.rb +304 -304
- data/lib/json/ld/conneg.rb +179 -161
- data/lib/json/ld/context.rb +2080 -1913
- data/lib/json/ld/expand.rb +745 -666
- data/lib/json/ld/extensions.rb +14 -13
- data/lib/json/ld/flatten.rb +257 -247
- data/lib/json/ld/format.rb +202 -194
- data/lib/json/ld/frame.rb +525 -502
- data/lib/json/ld/from_rdf.rb +223 -204
- data/lib/json/ld/html/nokogiri.rb +123 -121
- data/lib/json/ld/html/rexml.rb +151 -147
- data/lib/json/ld/reader.rb +107 -100
- data/lib/json/ld/resource.rb +224 -205
- data/lib/json/ld/streaming_reader.rb +574 -507
- data/lib/json/ld/streaming_writer.rb +93 -92
- data/lib/json/ld/to_rdf.rb +171 -169
- data/lib/json/ld/utils.rb +270 -264
- data/lib/json/ld/version.rb +24 -14
- data/lib/json/ld/writer.rb +334 -311
- data/lib/json/ld.rb +103 -96
- metadata +55 -198
- data/spec/api_spec.rb +0 -132
- data/spec/compact_spec.rb +0 -3482
- data/spec/conneg_spec.rb +0 -373
- data/spec/context_spec.rb +0 -2056
- data/spec/expand_spec.rb +0 -4496
- data/spec/flatten_spec.rb +0 -1203
- data/spec/format_spec.rb +0 -115
- data/spec/frame_spec.rb +0 -2541
- data/spec/from_rdf_spec.rb +0 -1072
- data/spec/matchers.rb +0 -20
- data/spec/rdfstar_spec.rb +0 -25
- data/spec/reader_spec.rb +0 -883
- data/spec/resource_spec.rb +0 -76
- data/spec/spec_helper.rb +0 -281
- data/spec/streaming_reader_spec.rb +0 -237
- data/spec/streaming_writer_spec.rb +0 -145
- data/spec/suite_compact_spec.rb +0 -22
- data/spec/suite_expand_spec.rb +0 -36
- data/spec/suite_flatten_spec.rb +0 -34
- data/spec/suite_frame_spec.rb +0 -29
- data/spec/suite_from_rdf_spec.rb +0 -22
- data/spec/suite_helper.rb +0 -411
- data/spec/suite_html_spec.rb +0 -22
- data/spec/suite_http_spec.rb +0 -35
- data/spec/suite_remote_doc_spec.rb +0 -22
- data/spec/suite_to_rdf_spec.rb +0 -30
- data/spec/support/extensions.rb +0 -44
- data/spec/test-files/test-1-compacted.jsonld +0 -10
- data/spec/test-files/test-1-context.jsonld +0 -7
- data/spec/test-files/test-1-expanded.jsonld +0 -5
- data/spec/test-files/test-1-input.jsonld +0 -10
- data/spec/test-files/test-1-rdf.ttl +0 -8
- data/spec/test-files/test-2-compacted.jsonld +0 -20
- data/spec/test-files/test-2-context.jsonld +0 -7
- data/spec/test-files/test-2-expanded.jsonld +0 -16
- data/spec/test-files/test-2-input.jsonld +0 -20
- data/spec/test-files/test-2-rdf.ttl +0 -14
- data/spec/test-files/test-3-compacted.jsonld +0 -11
- data/spec/test-files/test-3-context.jsonld +0 -8
- data/spec/test-files/test-3-expanded.jsonld +0 -10
- data/spec/test-files/test-3-input.jsonld +0 -11
- data/spec/test-files/test-3-rdf.ttl +0 -8
- data/spec/test-files/test-4-compacted.jsonld +0 -10
- data/spec/test-files/test-4-context.jsonld +0 -7
- data/spec/test-files/test-4-expanded.jsonld +0 -6
- data/spec/test-files/test-4-input.jsonld +0 -10
- data/spec/test-files/test-4-rdf.ttl +0 -5
- data/spec/test-files/test-5-compacted.jsonld +0 -13
- data/spec/test-files/test-5-context.jsonld +0 -7
- data/spec/test-files/test-5-expanded.jsonld +0 -9
- data/spec/test-files/test-5-input.jsonld +0 -13
- data/spec/test-files/test-5-rdf.ttl +0 -7
- data/spec/test-files/test-6-compacted.jsonld +0 -10
- data/spec/test-files/test-6-context.jsonld +0 -7
- data/spec/test-files/test-6-expanded.jsonld +0 -10
- data/spec/test-files/test-6-input.jsonld +0 -10
- data/spec/test-files/test-6-rdf.ttl +0 -6
- data/spec/test-files/test-7-compacted.jsonld +0 -23
- data/spec/test-files/test-7-context.jsonld +0 -4
- data/spec/test-files/test-7-expanded.jsonld +0 -20
- data/spec/test-files/test-7-input.jsonld +0 -23
- data/spec/test-files/test-7-rdf.ttl +0 -14
- data/spec/test-files/test-8-compacted.jsonld +0 -34
- data/spec/test-files/test-8-context.jsonld +0 -11
- data/spec/test-files/test-8-expanded.jsonld +0 -24
- data/spec/test-files/test-8-frame.jsonld +0 -18
- data/spec/test-files/test-8-framed.jsonld +0 -25
- data/spec/test-files/test-8-input.jsonld +0 -30
- data/spec/test-files/test-8-rdf.ttl +0 -15
- data/spec/test-files/test-9-compacted.jsonld +0 -20
- data/spec/test-files/test-9-context.jsonld +0 -13
- data/spec/test-files/test-9-expanded.jsonld +0 -14
- data/spec/test-files/test-9-input.jsonld +0 -12
- data/spec/to_rdf_spec.rb +0 -1684
- data/spec/writer_spec.rb +0 -427
@@ -1,151 +1,153 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# @see http://nokogiri.org/
|
7
|
-
module Nokogiri
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSON
|
4
|
+
module LD
|
5
|
+
class API
|
8
6
|
##
|
9
|
-
#
|
7
|
+
# Nokogiri implementation of an HTML parser.
|
10
8
|
#
|
11
|
-
# @
|
12
|
-
|
13
|
-
:nokogiri
|
14
|
-
end
|
15
|
-
|
16
|
-
# Proxy class to implement uniform element accessors
|
17
|
-
class NodeProxy
|
18
|
-
attr_reader :node
|
19
|
-
attr_reader :parent
|
20
|
-
|
21
|
-
def initialize(node, parent = nil)
|
22
|
-
@node = node
|
23
|
-
@parent = parent
|
24
|
-
end
|
25
|
-
|
9
|
+
# @see http://nokogiri.org/
|
10
|
+
module Nokogiri
|
26
11
|
##
|
27
|
-
#
|
12
|
+
# Returns the name of the underlying XML library.
|
28
13
|
#
|
29
|
-
# @return [
|
30
|
-
def
|
31
|
-
|
14
|
+
# @return [Symbol]
|
15
|
+
def self.library
|
16
|
+
:nokogiri
|
32
17
|
end
|
33
18
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
19
|
+
# Proxy class to implement uniform element accessors
|
20
|
+
class NodeProxy
|
21
|
+
attr_reader :node, :parent
|
22
|
+
|
23
|
+
def initialize(node, parent = nil)
|
24
|
+
@node = node
|
25
|
+
@parent = parent
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Return xml:base on element, if defined
|
30
|
+
#
|
31
|
+
# @return [String]
|
32
|
+
def base
|
33
|
+
@node.attribute_with_ns("base", RDF::XML.to_s) || @node.attribute('xml:base')
|
34
|
+
end
|
35
|
+
|
36
|
+
def display_path
|
37
|
+
@display_path ||= begin
|
38
|
+
path = []
|
39
|
+
path << parent.display_path if parent
|
40
|
+
path << @node.name
|
41
|
+
case @node
|
42
|
+
when ::Nokogiri::XML::Element then path.join("/")
|
43
|
+
when ::Nokogiri::XML::Attr then path.join("@")
|
44
|
+
else path.join("?")
|
45
|
+
end
|
43
46
|
end
|
44
47
|
end
|
45
|
-
end
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
##
|
50
|
+
# Return true of all child elements are text
|
51
|
+
#
|
52
|
+
# @return [Array<:text, :element, :attribute>]
|
53
|
+
def text_content?
|
54
|
+
@node.children.all?(&:text?)
|
55
|
+
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
##
|
58
|
+
# Children of this node
|
59
|
+
#
|
60
|
+
# @return [NodeSetProxy]
|
61
|
+
def children
|
62
|
+
NodeSetProxy.new(@node.children, self)
|
63
|
+
end
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
# Ancestors of this element, in order
|
66
|
+
def ancestors
|
67
|
+
@ancestors ||= parent ? parent.ancestors + [parent] : []
|
68
|
+
end
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
70
|
+
##
|
71
|
+
# Inner text of an element. Decode Entities
|
72
|
+
#
|
73
|
+
# @return [String]
|
74
|
+
# def inner_text
|
75
|
+
# coder = HTMLEntities.new
|
76
|
+
# coder.decode(@node.inner_text)
|
77
|
+
# end
|
78
|
+
|
79
|
+
def attribute_nodes
|
80
|
+
@attribute_nodes ||= NodeSetProxy.new(@node.attribute_nodes, self)
|
81
|
+
end
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
def xpath(*args)
|
84
|
+
@node.xpath(*args).map do |n|
|
85
|
+
# Get node ancestors
|
86
|
+
parent = n.ancestors.reverse.inject(nil) do |p, node|
|
87
|
+
NodeProxy.new(node, p)
|
88
|
+
end
|
89
|
+
NodeProxy.new(n, parent)
|
86
90
|
end
|
87
|
-
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Proxy for everything else to @node
|
95
|
+
def method_missing(method, *args)
|
96
|
+
@node.send(method, *args)
|
88
97
|
end
|
89
98
|
end
|
90
99
|
|
91
100
|
##
|
92
|
-
#
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
101
|
+
# NodeSet proxy
|
102
|
+
class NodeSetProxy
|
103
|
+
attr_reader :node_set, :parent
|
97
104
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
attr_reader :parent
|
103
|
-
|
104
|
-
def initialize(node_set, parent)
|
105
|
-
@node_set = node_set
|
106
|
-
@parent = parent
|
107
|
-
end
|
105
|
+
def initialize(node_set, parent)
|
106
|
+
@node_set = node_set
|
107
|
+
@parent = parent
|
108
|
+
end
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
110
|
+
##
|
111
|
+
# Return a proxy for each child
|
112
|
+
#
|
113
|
+
# @yield child
|
114
|
+
# @yieldparam [NodeProxy]
|
115
|
+
def each
|
116
|
+
@node_set.each do |c|
|
117
|
+
yield NodeProxy.new(c, parent)
|
118
|
+
end
|
117
119
|
end
|
118
|
-
end
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
##
|
122
|
+
# Proxy for everything else to @node_set
|
123
|
+
def method_missing(method, *args)
|
124
|
+
@node_set.send(method, *args)
|
125
|
+
end
|
124
126
|
end
|
125
|
-
end
|
126
127
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
128
|
+
##
|
129
|
+
# Initializes the underlying XML library.
|
130
|
+
#
|
131
|
+
# @param [Hash{Symbol => Object}] options
|
132
|
+
# @return [NodeProxy] of root element
|
133
|
+
def initialize_html_nokogiri(input, _options = {})
|
134
|
+
require 'nokogiri' unless defined?(::Nokogiri)
|
135
|
+
doc = case input
|
136
|
+
when ::Nokogiri::HTML::Document, ::Nokogiri::XML::Document
|
137
|
+
input
|
138
|
+
else
|
139
|
+
begin
|
140
|
+
input = input.read if input.respond_to?(:read)
|
141
|
+
::Nokogiri::HTML5(input.force_encoding('utf-8'), max_parse_errors: 1000)
|
142
|
+
rescue LoadError, NoMethodError
|
143
|
+
::Nokogiri::HTML.parse(input, base_uri.to_s, 'utf-8')
|
144
|
+
end
|
143
145
|
end
|
144
|
-
end
|
145
146
|
|
146
|
-
|
147
|
+
NodeProxy.new(doc.root) if doc&.root
|
148
|
+
end
|
149
|
+
alias initialize_html initialize_html_nokogiri
|
147
150
|
end
|
148
|
-
alias_method :initialize_html, :initialize_html_nokogiri
|
149
151
|
end
|
150
152
|
end
|
151
153
|
end
|
data/lib/json/ld/html/rexml.rb
CHANGED
@@ -1,187 +1,191 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'htmlentities'
|
2
4
|
|
3
|
-
module JSON
|
4
|
-
|
5
|
-
|
6
|
-
# REXML implementation of an XML parser.
|
7
|
-
#
|
8
|
-
# @see http://www.germane-software.com/software/rexml/
|
9
|
-
module REXML
|
5
|
+
module JSON
|
6
|
+
module LD
|
7
|
+
class API
|
10
8
|
##
|
11
|
-
#
|
9
|
+
# REXML implementation of an XML parser.
|
12
10
|
#
|
13
|
-
# @
|
14
|
-
|
15
|
-
:rexml
|
16
|
-
end
|
17
|
-
|
18
|
-
# Proxy class to implement uniform element accessors
|
19
|
-
class NodeProxy
|
20
|
-
attr_reader :node
|
21
|
-
attr_reader :parent
|
22
|
-
|
23
|
-
def initialize(node, parent = nil)
|
24
|
-
@node = node
|
25
|
-
@parent = parent
|
26
|
-
end
|
27
|
-
|
11
|
+
# @see http://www.germane-software.com/software/rexml/
|
12
|
+
module REXML
|
28
13
|
##
|
29
|
-
#
|
14
|
+
# Returns the name of the underlying XML library.
|
30
15
|
#
|
31
|
-
# @return [
|
32
|
-
def
|
33
|
-
|
16
|
+
# @return [Symbol]
|
17
|
+
def self.library
|
18
|
+
:rexml
|
34
19
|
end
|
35
20
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
21
|
+
# Proxy class to implement uniform element accessors
|
22
|
+
class NodeProxy
|
23
|
+
attr_reader :node, :parent
|
24
|
+
|
25
|
+
def initialize(node, parent = nil)
|
26
|
+
@node = node
|
27
|
+
@parent = parent
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Return xml:base on element, if defined
|
32
|
+
#
|
33
|
+
# @return [String]
|
34
|
+
def base
|
35
|
+
@node.attribute("base", RDF::XML.to_s) || @node.attribute('xml:base')
|
36
|
+
end
|
37
|
+
|
38
|
+
def display_path
|
39
|
+
@display_path ||= begin
|
40
|
+
path = []
|
41
|
+
path << parent.display_path if parent
|
42
|
+
path << @node.name
|
43
|
+
case @node
|
44
|
+
when ::REXML::Element then path.join("/")
|
45
|
+
when ::REXML::Attribute then path.join("@")
|
46
|
+
else path.join("?")
|
47
|
+
end
|
45
48
|
end
|
46
49
|
end
|
47
|
-
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
##
|
52
|
+
# Return true of all child elements are text
|
53
|
+
#
|
54
|
+
# @return [Array<:text, :element, :attribute>]
|
55
|
+
def text_content?
|
56
|
+
@node.children.all?(::REXML::Text)
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
##
|
60
|
+
# Children of this node
|
61
|
+
#
|
62
|
+
# @return [NodeSetProxy]
|
63
|
+
def children
|
64
|
+
NodeSetProxy.new(@node.children, self)
|
65
|
+
end
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
# Ancestors of this element, in order
|
68
|
+
def ancestors
|
69
|
+
@ancestors ||= parent ? parent.ancestors + [parent] : []
|
70
|
+
end
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
72
|
+
##
|
73
|
+
# Inner text of an element
|
74
|
+
#
|
75
|
+
# @see http://apidock.com/ruby/REXML/Element/get_text#743-Get-all-inner-texts
|
76
|
+
# @return [String]
|
77
|
+
def inner_text
|
78
|
+
coder = HTMLEntities.new
|
79
|
+
::REXML::XPath.match(@node, './/text()').map do |e|
|
80
|
+
coder.decode(e)
|
81
|
+
end.join
|
82
|
+
end
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
##
|
85
|
+
# Inner text of an element
|
86
|
+
#
|
87
|
+
# @see http://apidock.com/ruby/REXML/Element/get_text#743-Get-all-inner-texts
|
88
|
+
# @return [String]
|
89
|
+
def inner_html
|
90
|
+
@node.children.map(&:to_s).join
|
91
|
+
end
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
-
|
93
|
+
def attribute_nodes
|
94
|
+
attrs = @node.attributes.dup.keep_if do |name, _attr|
|
95
|
+
!name.start_with?('xmlns')
|
96
|
+
end
|
97
|
+
@attribute_nodes ||= (attrs.empty? ? attrs : NodeSetProxy.new(attrs, self))
|
94
98
|
end
|
95
|
-
@attribute_nodes ||= (attrs.empty? ? attrs : NodeSetProxy.new(attrs, self))
|
96
|
-
end
|
97
99
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
100
|
+
##
|
101
|
+
# Node type accessors
|
102
|
+
#
|
103
|
+
# @return [Boolean]
|
104
|
+
def text?
|
105
|
+
@node.is_a?(::REXML::Text)
|
106
|
+
end
|
105
107
|
|
106
|
-
|
107
|
-
|
108
|
-
|
108
|
+
def element?
|
109
|
+
@node.is_a?(::REXML::Element)
|
110
|
+
end
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
|
112
|
+
def blank?
|
113
|
+
@node.is_a?(::REXML::Text) && @node.empty?
|
114
|
+
end
|
113
115
|
|
114
|
-
|
116
|
+
def to_s
|
117
|
+
@node.to_s
|
118
|
+
end
|
115
119
|
|
116
|
-
|
117
|
-
|
118
|
-
|
120
|
+
def xpath(*args)
|
121
|
+
::REXML::XPath.match(@node, *args).map do |n|
|
122
|
+
NodeProxy.new(n, parent)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def at_xpath(*args)
|
127
|
+
xpath(*args).first
|
119
128
|
end
|
120
|
-
end
|
121
129
|
|
122
|
-
|
123
|
-
|
130
|
+
##
|
131
|
+
# Proxy for everything else to @node
|
132
|
+
def method_missing(method, *args)
|
133
|
+
@node.send(method, *args)
|
134
|
+
end
|
124
135
|
end
|
125
136
|
|
126
137
|
##
|
127
|
-
#
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
end
|
138
|
+
# NodeSet proxy
|
139
|
+
class NodeSetProxy
|
140
|
+
attr_reader :node_set, :parent
|
132
141
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
attr_reader :parent
|
138
|
-
|
139
|
-
def initialize(node_set, parent)
|
140
|
-
@node_set = node_set
|
141
|
-
@parent = parent
|
142
|
-
end
|
142
|
+
def initialize(node_set, parent)
|
143
|
+
@node_set = node_set
|
144
|
+
@parent = parent
|
145
|
+
end
|
143
146
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
147
|
+
##
|
148
|
+
# Return a proxy for each child
|
149
|
+
#
|
150
|
+
# @yield child
|
151
|
+
# @yieldparam [NodeProxy]
|
152
|
+
def each
|
153
|
+
@node_set.each do |c|
|
154
|
+
yield NodeProxy.new(c, parent)
|
155
|
+
end
|
152
156
|
end
|
153
|
-
end
|
154
157
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
+
##
|
159
|
+
def to_html
|
160
|
+
node_set.map(&:to_s).join
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# Proxy for everything else to @node_set
|
165
|
+
def method_missing(method, *args)
|
166
|
+
@node_set.send(method, *args)
|
167
|
+
end
|
158
168
|
end
|
159
169
|
|
160
170
|
##
|
161
|
-
#
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
171
|
+
# Initializes the underlying XML library.
|
172
|
+
#
|
173
|
+
# @param [Hash{Symbol => Object}] options
|
174
|
+
# @return [NodeProxy] of document root
|
175
|
+
def initialize_html_rexml(input, _options = {})
|
176
|
+
require 'rexml/document' unless defined?(::REXML)
|
177
|
+
doc = case input
|
178
|
+
when ::REXML::Document
|
179
|
+
input
|
180
|
+
else
|
181
|
+
# Only parse as XML, no HTML mode
|
182
|
+
::REXML::Document.new(input.respond_to?(:read) ? input.read : input.to_s)
|
183
|
+
end
|
166
184
|
|
167
|
-
|
168
|
-
# Initializes the underlying XML library.
|
169
|
-
#
|
170
|
-
# @param [Hash{Symbol => Object}] options
|
171
|
-
# @return [NodeProxy] of document root
|
172
|
-
def initialize_html_rexml(input, options = {})
|
173
|
-
require 'rexml/document' unless defined?(::REXML)
|
174
|
-
doc = case input
|
175
|
-
when ::REXML::Document
|
176
|
-
input
|
177
|
-
else
|
178
|
-
# Only parse as XML, no HTML mode
|
179
|
-
::REXML::Document.new(input.respond_to?(:read) ? input.read : input.to_s)
|
185
|
+
NodeProxy.new(doc.root) if doc&.root
|
180
186
|
end
|
181
|
-
|
182
|
-
NodeProxy.new(doc.root) if doc && doc.root
|
187
|
+
alias initialize_html initialize_html_rexml
|
183
188
|
end
|
184
|
-
alias_method :initialize_html, :initialize_html_rexml
|
185
189
|
end
|
186
190
|
end
|
187
191
|
end
|