Class: Moxml::Adapter::OgaSAXBridge
- Inherits:
-
Object
- Object
- Moxml::Adapter::OgaSAXBridge
- 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
-
#after_element(namespace, name) ⇒ Object
Oga: after_element(namespace, name).
-
#initialize(handler) ⇒ OgaSAXBridge
constructor
A new instance of OgaSAXBridge.
- #on_cdata(text) ⇒ Object
- #on_comment(text) ⇒ Object
-
#on_element(namespace, name, attributes) ⇒ Object
Oga: on_element(namespace, name, attributes) namespace may be nil attributes is an array of [name, value] pairs.
- #on_processing_instruction(name, text) ⇒ Object
- #on_text(text) ⇒ Object
Constructor Details
#initialize(handler) ⇒ OgaSAXBridge
Returns a new instance of OgaSAXBridge.
388 389 390 |
# File 'lib/moxml/adapter/oga.rb', line 388 def initialize(handler) @handler = handler end |
Instance Method Details
#after_element(namespace, name) ⇒ Object
Oga: after_element(namespace, name)
423 424 425 426 |
# File 'lib/moxml/adapter/oga.rb', line 423 def after_element(namespace, name) element_name = namespace ? "#{namespace}:#{name}" : name @handler.on_end_element(element_name) end |
#on_cdata(text) ⇒ Object
432 433 434 |
# File 'lib/moxml/adapter/oga.rb', line 432 def on_cdata(text) @handler.on_cdata(text) end |
#on_comment(text) ⇒ Object
436 437 438 |
# File 'lib/moxml/adapter/oga.rb', line 436 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
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/moxml/adapter/oga.rb', line 395 def on_element(namespace, name, attributes) # Build full qualified name if namespace present element_name = namespace ? "#{namespace}:#{name}" : name # Convert Oga attributes to hash attr_hash = {} ns_hash = {} # Oga delivers attributes as array of [name, value] pairs attributes.each do |attr_name, attr_value| if attr_name.to_s.start_with?("xmlns") prefix = if attr_name.to_s == "xmlns" nil else attr_name.to_s.sub( "xmlns:", "" ) end ns_hash[prefix] = attr_value else attr_hash[attr_name.to_s] = attr_value end end @handler.on_start_element(element_name, attr_hash, ns_hash) end |
#on_processing_instruction(name, text) ⇒ Object
440 441 442 |
# File 'lib/moxml/adapter/oga.rb', line 440 def on_processing_instruction(name, text) @handler.on_processing_instruction(name, text || "") end |
#on_text(text) ⇒ Object
428 429 430 |
# File 'lib/moxml/adapter/oga.rb', line 428 def on_text(text) @handler.on_characters(text) end |