class Saxerator::Adapters::Oga

Constants

NAMESPACE_MATCHER

Public Class Methods

new(reader) click to toggle source
# File lib/saxerator/adapters/oga.rb, line 16
def initialize(reader)
  @reader = reader
  @ignore_namespaces = reader.ignore_namespaces?
end
parse(source, reader) click to toggle source
# File lib/saxerator/adapters/oga.rb, line 9
def self.parse(source, reader)
  parser = ::Oga::XML::SaxParser.new(new(reader), source, strict: true)
  parser.parse
rescue LL::ParserError => message
  raise Saxerator::ParseException, message
end

Public Instance Methods

after_element(namespace, name) click to toggle source
# File lib/saxerator/adapters/oga.rb, line 30
def after_element(namespace, name)
  name = "#{namespace}:#{name}" if namespace && !@ignore_namespaces
  @reader.end_element(name)
end
on_element(namespace, name, attrs = {}) click to toggle source
# File lib/saxerator/adapters/oga.rb, line 24
def on_element(namespace, name, attrs = {})
  name = "#{namespace}:#{name}" if namespace && !@ignore_namespaces
  attrs = @ignore_namespaces ? strip_namespace(attrs) : attrs.to_a
  @reader.start_element(name, attrs)
end

Private Instance Methods

strip_namespace(attrs) click to toggle source
# File lib/saxerator/adapters/oga.rb, line 37
def strip_namespace(attrs)
  attrs.map { |k, v| [k.gsub(NAMESPACE_MATCHER, ''), v] }
end