Class: Serialbench::Serializers::Xml::NokogiriSerializer
Defined Under Namespace
Classes: StreamingHandler
Instance Method Summary
collapse
#available?, #features, format, #generate_xml, #parse_dom, #parse_sax, #supports_generation?, #supports_namespaces?, #supports_validation?, #supports_xpath?
#get_version, #initialize, #require_library, #stream_parse
Instance Method Details
#generate(data) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 18
def generate(data)
require 'nokogiri'
if data.respond_to?(:to_xml)
data.to_xml(indent: 2)
else
builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
build_xml_from_data(xml, data)
end
builder.to_xml
end
end
|
#library_require_name ⇒ Object
52
53
54
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 52
def library_require_name
'nokogiri'
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 9
def name
'nokogiri'
end
|
#parse(xml_string) ⇒ Object
13
14
15
16
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 13
def parse(xml_string)
require 'nokogiri'
Nokogiri::XML(xml_string)
end
|
#parse_streaming(xml_string, &block) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 32
def parse_streaming(xml_string, &block)
require 'nokogiri'
handler = StreamingHandler.new(&block)
parser = Nokogiri::XML::SAX::Parser.new(handler)
parser.parse(xml_string)
handler.elements_processed
end
|
#supports_streaming? ⇒ Boolean
41
42
43
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 41
def supports_streaming?
true
end
|
#version ⇒ Object
45
46
47
48
49
50
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 45
def version
return 'unknown' unless available?
require 'nokogiri'
Nokogiri::VERSION
end
|