Class: Serialbench::Serializers::Xml::LeptrisSerializer
Defined Under Namespace
Classes: StreamingHandler
Instance Method Summary
collapse
#features, format, #generate_xml, #parse_dom, #parse_sax, #supports_generation?, #supports_namespaces?, #supports_validation?, #supports_xpath?
#get_version, #initialize, #require_library, #stream_parse, #supports?
Instance Method Details
#available? ⇒ Boolean
The gem's require succeeds even when the libtaurus shared library is
missing -- the FFI load happens lazily at first use. Probe with a
real parse so "available" means "actually usable".
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/serialbench/serializers/xml/leptris_serializer.rb', line 74
def available?
return @available if defined?(@available)
@available = begin
require 'leptris'
require 'leptris/xml'
Leptris::XML.parse('<probe/>')
true
rescue StandardError, LoadError
false
end
end
|
#capabilities ⇒ Object
43
44
45
|
# File 'lib/serialbench/serializers/xml/leptris_serializer.rb', line 43
def capabilities
super | Set.new(%i[xpath namespaces sax stax])
end
|
#generate(data) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/serialbench/serializers/xml/leptris_serializer.rb', line 19
def generate(data)
require 'leptris'
require 'leptris/xml'
if data.is_a?(Leptris::XML::Document) || data.is_a?(Leptris::XML::Node)
data.to_xml(indent: 2)
else
build_document_from_data(data).to_xml(indent: 2)
end
end
|
#library_require_name ⇒ Object
67
68
69
|
# File 'lib/serialbench/serializers/xml/leptris_serializer.rb', line 67
def library_require_name
'leptris'
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/serialbench/serializers/xml/leptris_serializer.rb', line 9
def name
'leptris'
end
|
#parse(xml_string) ⇒ Object
13
14
15
16
17
|
# File 'lib/serialbench/serializers/xml/leptris_serializer.rb', line 13
def parse(xml_string)
require 'leptris'
require 'leptris/xml'
Leptris::XML.parse(xml_string)
end
|
#parse_streaming(xml_string, &block) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/serialbench/serializers/xml/leptris_serializer.rb', line 29
def parse_streaming(xml_string, &block)
require 'leptris'
require 'leptris/xml'
handler = StreamingHandler.new(&block)
parser = Leptris::XML::SAX::Parser.new(handler)
parser.parse_memory(xml_string)
handler.elements_processed
end
|
#supports_streaming? ⇒ Boolean
39
40
41
|
# File 'lib/serialbench/serializers/xml/leptris_serializer.rb', line 39
def supports_streaming?
true
end
|
#version ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/serialbench/serializers/xml/leptris_serializer.rb', line 59
def version
return 'unknown' unless available?
require 'leptris'
require 'leptris/xml'
Leptris::VERSION
end
|
#xpath_query(document, expression) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/serialbench/serializers/xml/leptris_serializer.rb', line 47
def xpath_query(document, expression)
require 'leptris'
require 'leptris/xml'
result = document.xpath(expression)
result.size
end
|