Class: Moxml::SAX::BlockHandler
- Defined in:
- lib/moxml/sax/block_handler.rb
Overview
Block-based SAX handler with DSL
Provides a convenient block-based API for simple SAX parsing cases without requiring a full class definition.
Instance Method Summary collapse
-
#cdata {|text| ... } ⇒ void
Define handler for CDATA section event.
-
#characters {|text| ... } ⇒ void
Define handler for character data event.
-
#comment {|text| ... } ⇒ void
Define handler for comment event.
-
#end_document { ... } ⇒ void
Define handler for document end event.
-
#end_element {|name| ... } ⇒ void
Define handler for element end event.
-
#error {|error| ... } ⇒ void
Define handler for error event.
-
#initialize(&block) { ... } ⇒ BlockHandler
constructor
Create a new block handler.
- #on_cdata(text) ⇒ Object
- #on_characters(text) ⇒ Object
- #on_comment(text) ⇒ Object
- #on_end_document ⇒ Object
- #on_end_element(name) ⇒ Object
- #on_error(error) ⇒ Object
- #on_processing_instruction(target, data) ⇒ Object
- #on_start_document ⇒ Object
- #on_start_element(name, attributes = {}, namespaces = {}) ⇒ Object
- #on_warning(message) ⇒ Object
-
#processing_instruction {|target, data| ... } ⇒ void
Define handler for processing instruction event.
-
#start_document { ... } ⇒ void
Define handler for document start event.
-
#start_element {|name, attributes, namespaces| ... } ⇒ void
Define handler for element start event.
-
#warning {|message| ... } ⇒ void
Define handler for warning event.
Constructor Details
#initialize(&block) { ... } ⇒ BlockHandler
Create a new block handler
32 33 34 35 36 |
# File 'lib/moxml/sax/block_handler.rb', line 32 def initialize(&block) super() @handlers = {} instance_eval(&block) if block end |
Instance Method Details
#cdata {|text| ... } ⇒ void
This method returns an undefined value.
Define handler for CDATA section event
94 95 96 |
# File 'lib/moxml/sax/block_handler.rb', line 94 def cdata(&block) @handlers[:cdata] = block end |
#characters {|text| ... } ⇒ void
This method returns an undefined value.
Define handler for character data event
84 85 86 |
# File 'lib/moxml/sax/block_handler.rb', line 84 def characters(&block) @handlers[:characters] = block end |
#comment {|text| ... } ⇒ void
This method returns an undefined value.
Define handler for comment event
104 105 106 |
# File 'lib/moxml/sax/block_handler.rb', line 104 def comment(&block) @handlers[:comment] = block end |
#end_document { ... } ⇒ void
This method returns an undefined value.
Define handler for document end event
52 53 54 |
# File 'lib/moxml/sax/block_handler.rb', line 52 def end_document(&block) @handlers[:end_document] = block end |
#end_element {|name| ... } ⇒ void
This method returns an undefined value.
Define handler for element end event
74 75 76 |
# File 'lib/moxml/sax/block_handler.rb', line 74 def end_element(&block) @handlers[:end_element] = block end |
#error {|error| ... } ⇒ void
This method returns an undefined value.
Define handler for error event
125 126 127 |
# File 'lib/moxml/sax/block_handler.rb', line 125 def error(&block) @handlers[:error] = block end |
#on_cdata(text) ⇒ Object
165 166 167 |
# File 'lib/moxml/sax/block_handler.rb', line 165 def on_cdata(text) @handlers[:cdata]&.call(text) end |
#on_characters(text) ⇒ Object
160 161 162 |
# File 'lib/moxml/sax/block_handler.rb', line 160 def on_characters(text) @handlers[:characters]&.call(text) end |
#on_comment(text) ⇒ Object
170 171 172 |
# File 'lib/moxml/sax/block_handler.rb', line 170 def on_comment(text) @handlers[:comment]&.call(text) end |
#on_end_document ⇒ Object
145 146 147 |
# File 'lib/moxml/sax/block_handler.rb', line 145 def on_end_document @handlers[:end_document]&.call end |
#on_end_element(name) ⇒ Object
155 156 157 |
# File 'lib/moxml/sax/block_handler.rb', line 155 def on_end_element(name) @handlers[:end_element]&.call(name) end |
#on_error(error) ⇒ Object
180 181 182 183 184 185 186 |
# File 'lib/moxml/sax/block_handler.rb', line 180 def on_error(error) if @handlers[:error] @handlers[:error].call(error) else super end end |
#on_processing_instruction(target, data) ⇒ Object
175 176 177 |
# File 'lib/moxml/sax/block_handler.rb', line 175 def on_processing_instruction(target, data) @handlers[:processing_instruction]&.call(target, data) end |
#on_start_document ⇒ Object
140 141 142 |
# File 'lib/moxml/sax/block_handler.rb', line 140 def on_start_document @handlers[:start_document]&.call end |
#on_start_element(name, attributes = {}, namespaces = {}) ⇒ Object
150 151 152 |
# File 'lib/moxml/sax/block_handler.rb', line 150 def on_start_element(name, attributes = {}, namespaces = {}) @handlers[:start_element]&.call(name, attributes, namespaces) end |
#on_warning(message) ⇒ Object
189 190 191 |
# File 'lib/moxml/sax/block_handler.rb', line 189 def on_warning() @handlers[:warning]&.call() end |
#processing_instruction {|target, data| ... } ⇒ void
This method returns an undefined value.
Define handler for processing instruction event
115 116 117 |
# File 'lib/moxml/sax/block_handler.rb', line 115 def processing_instruction(&block) @handlers[:processing_instruction] = block end |
#start_document { ... } ⇒ void
This method returns an undefined value.
Define handler for document start event
43 44 45 |
# File 'lib/moxml/sax/block_handler.rb', line 43 def start_document(&block) @handlers[:start_document] = block end |
#start_element {|name, attributes, namespaces| ... } ⇒ void
This method returns an undefined value.
Define handler for element start event
64 65 66 |
# File 'lib/moxml/sax/block_handler.rb', line 64 def start_element(&block) @handlers[:start_element] = block end |
#warning {|message| ... } ⇒ void
This method returns an undefined value.
Define handler for warning event
135 136 137 |
# File 'lib/moxml/sax/block_handler.rb', line 135 def warning(&block) @handlers[:warning] = block end |