Class: Serialbench::Serializers::Html::LeptrisSerializer
Instance Method Summary
collapse
#features, format, #from_hash, #generate
#generate, #get_version, #initialize, #require_library, #stream_parse, #supports?
Instance Method Details
#available? ⇒ Boolean
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/serialbench/serializers/html/leptris_serializer.rb', line 31
def available?
return @available if defined?(@available)
@available = begin
require 'leptris'
require 'leptris/xml'
Leptris::XML.parse_html('<p>probe</p>')
true
rescue StandardError, LoadError => e
warn "#{name} unavailable: #{e.class}: #{e.message}"
false
end
end
|
#capabilities ⇒ Object
13
14
15
|
# File 'lib/serialbench/serializers/html/leptris_serializer.rb', line 13
def capabilities
super | Set.new(%i[xpath html5])
end
|
#library_require_name ⇒ Object
52
53
54
|
# File 'lib/serialbench/serializers/html/leptris_serializer.rb', line 52
def library_require_name
'leptris'
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/serialbench/serializers/html/leptris_serializer.rb', line 9
def name
'leptris'
end
|
#parse(html_string) ⇒ Object
17
18
19
20
21
|
# File 'lib/serialbench/serializers/html/leptris_serializer.rb', line 17
def parse(html_string)
require 'leptris'
require 'leptris/xml'
Leptris::XML.parse_html(html_string)
end
|
#serialize_document(document) ⇒ Object
27
28
29
|
# File 'lib/serialbench/serializers/html/leptris_serializer.rb', line 27
def serialize_document(document)
document.to_xml
end
|
#version ⇒ Object
45
46
47
48
49
50
|
# File 'lib/serialbench/serializers/html/leptris_serializer.rb', line 45
def version
return 'unknown' unless available?
require 'leptris'
Leptris::VERSION
end
|
#xpath_query(document, expression) ⇒ Object
23
24
25
|
# File 'lib/serialbench/serializers/html/leptris_serializer.rb', line 23
def xpath_query(document, expression)
document.xpath(expression).size
end
|