Class: Moxml::Adapter::OgaSAXBridge

Inherits:
Object
  • Object
show all
Includes:
SAX::NamespaceSplitter
Defined in:
lib/moxml/adapter/oga.rb

Overview

Bridge between Oga SAX and Moxml SAX

Translates Oga SAX events to Moxml::SAX::Handler events. Oga has different event naming and namespace as first param.

Instance Method Summary collapse

Methods included from SAX::NamespaceSplitter

#split_attributes_and_namespaces

Constructor Details

#initialize(handler) ⇒ OgaSAXBridge

Returns a new instance of OgaSAXBridge.



542
543
544
# File 'lib/moxml/adapter/oga.rb', line 542

def initialize(handler)
  @handler = handler
end

Instance Method Details

#after_element(namespace, name) ⇒ Object

Oga: after_element(namespace, name)



556
557
558
559
# File 'lib/moxml/adapter/oga.rb', line 556

def after_element(namespace, name)
  element_name = namespace ? "#{namespace}:#{name}" : name
  @handler.on_end_element(element_name)
end

#on_cdata(text) ⇒ Object



565
566
567
# File 'lib/moxml/adapter/oga.rb', line 565

def on_cdata(text)
  @handler.on_cdata(text)
end

#on_comment(text) ⇒ Object



569
570
571
# File 'lib/moxml/adapter/oga.rb', line 569

def on_comment(text)
  @handler.on_comment(text)
end

#on_element(namespace, name, attributes) ⇒ Object

Oga: on_element(namespace, name, attributes) namespace may be nil attributes is an array of [name, value] pairs



549
550
551
552
553
# File 'lib/moxml/adapter/oga.rb', line 549

def on_element(namespace, name, attributes)
  element_name = namespace ? "#{namespace}:#{name}" : name
  attr_hash, ns_hash = split_attributes_and_namespaces(attributes)
  @handler.on_start_element(element_name, attr_hash, ns_hash)
end

#on_processing_instruction(name, text) ⇒ Object



573
574
575
# File 'lib/moxml/adapter/oga.rb', line 573

def on_processing_instruction(name, text)
  @handler.on_processing_instruction(name, text || "")
end

#on_text(text) ⇒ Object



561
562
563
# File 'lib/moxml/adapter/oga.rb', line 561

def on_text(text)
  @handler.on_characters(text)
end