class CamtParser::Xml

Constants

PARSER_MAPPING
SUPPORTED_PARSERS

Public Class Methods

parse(doc) click to toggle source
# File lib/camt_parser/xml.rb, line 25
def self.parse(doc)
  raise CamtParser::Errors::NotXMLError, doc.class unless doc.is_a? Nokogiri::XML::Document

  namespace = doc.namespaces['xmlns']
  doc.remove_namespaces!

  parser_class = @namespace_parsers[namespace]
  if parser_class == nil
    raise CamtParser::Errors::UnsupportedNamespaceError, namespace
  end

  return parser_class.new(doc.xpath('Document'))
end
register(namespace, parser) click to toggle source
# File lib/camt_parser/xml.rb, line 13
def self.register(namespace, parser)
  if !SUPPORTED_PARSERS.include?(parser)
    raise CamtParser::Errors::UnsupportedParserClass, parser.to_s
  end

  if @namespace_parsers.key?(namespace) # Prevent overwriting existing registrations
    raise CamtParser::Errors::NamespaceAlreadyRegistered, namespace
  end

  @namespace_parsers[namespace] = PARSER_MAPPING[parser]
end