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.



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

def initialize(handler)
  @handler = handler
end

Instance Method Details

#after_element(namespace, name) ⇒ Object

Oga: after_element(namespace, name)



575
576
577
578
# File 'lib/moxml/adapter/oga.rb', line 575

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

#on_cdata(text) ⇒ Object



584
585
586
# File 'lib/moxml/adapter/oga.rb', line 584

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

#on_comment(text) ⇒ Object



588
589
590
# File 'lib/moxml/adapter/oga.rb', line 588

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



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

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



592
593
594
# File 'lib/moxml/adapter/oga.rb', line 592

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

#on_text(text) ⇒ Object



580
581
582
# File 'lib/moxml/adapter/oga.rb', line 580

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