Class: Serialbench::Serializers::Xml::BaseXmlSerializer

Inherits:
BaseSerializer
  • Object
show all
Defined in:
lib/serialbench/serializers/xml/base_xml_serializer.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseSerializer

#generate, #get_version, #initialize, #parse, #require_library, #stream_parse, #supports?

Constructor Details

This class inherits a constructor from Serialbench::Serializers::BaseSerializer

Class Method Details

.formatObject



9
10
11
# File 'lib/serialbench/serializers/xml/base_xml_serializer.rb', line 9

def self.format
  :xml
end

Instance Method Details

#available?Boolean

Check if the XML library is available

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
# File 'lib/serialbench/serializers/xml/base_xml_serializer.rb', line 42

def available?
  return @available if defined?(@available)

  @available = begin
    require library_require_name
    true
  rescue LoadError
    false
  end
end

#capabilitiesObject



26
27
28
# File 'lib/serialbench/serializers/xml/base_xml_serializer.rb', line 26

def capabilities
  super | Set.new(%i[namespaces])
end

#featuresObject

XML-specific features derive from the capability set



31
32
33
34
35
36
37
38
39
# File 'lib/serialbench/serializers/xml/base_xml_serializer.rb', line 31

def features
  {
    xpath: supports?(:xpath),
    namespaces: supports?(:namespaces),
    validation: supports?(:validation),
    streaming: supports?(:sax) || supports?(:streaming),
    stax: supports?(:stax)
  }
end

#generate_xml(document, options = {}) ⇒ Object



22
23
24
# File 'lib/serialbench/serializers/xml/base_xml_serializer.rb', line 22

def generate_xml(document, options = {})
  generate(document, options)
end

#parse_dom(xml_string) ⇒ Object

XML-specific methods



14
15
16
# File 'lib/serialbench/serializers/xml/base_xml_serializer.rb', line 14

def parse_dom(xml_string)
  parse(xml_string)
end

#parse_sax(xml_string, &block) ⇒ Object



18
19
20
# File 'lib/serialbench/serializers/xml/base_xml_serializer.rb', line 18

def parse_sax(xml_string, &block)
  stream_parse(xml_string, &block)
end