Class: MySQLXML::MyXListener
- Inherits:
-
Object
- Object
- MySQLXML::MyXListener
- Defined in:
- lib/mysql-xml.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
-
#initialize(block) ⇒ MyXListener
constructor
A new instance of MyXListener.
-
#method_missing(*opts) ⇒ Object
Silence method missing exceptions since we only need to handle some events.
- #tag_end(name) ⇒ Object
- #tag_start(name, attrs) ⇒ Object
- #text(text) ⇒ Object
Constructor Details
#initialize(block) ⇒ MyXListener
Returns a new instance of MyXListener.
26 27 28 29 30 31 32 |
# File 'lib/mysql-xml.rb', line 26 def initialize(block) #Track where we are in the tree. @context = [] @cur_record = nil @cur_field_name = nil @block = block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*opts) ⇒ Object
Silence method missing exceptions since we only need to handle some events
61 |
# File 'lib/mysql-xml.rb', line 61 def method_missing(*opts); end |
Instance Attribute Details
#records ⇒ Object (readonly)
Returns the value of attribute records.
24 25 26 |
# File 'lib/mysql-xml.rb', line 24 def records @records end |
Instance Method Details
#tag_end(name) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/mysql-xml.rb', line 49 def tag_end(name) @context.pop if name == 'field' @cur_field_name = nil elsif name == 'row' @block.call(@cur_record) @cur_record = nil end end |
#tag_start(name, attrs) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/mysql-xml.rb', line 34 def tag_start(name, attrs) @context << name if name == 'row' @cur_record = {} elsif name == 'field' @cur_field_name = attrs['name'] end end |
#text(text) ⇒ Object
43 44 45 46 47 |
# File 'lib/mysql-xml.rb', line 43 def text(text) if @context[-1] == 'field' @cur_record[@cur_field_name] = text end end |