Module: SAXMachine::ClassMethods
- Defined in:
- lib/sax-machine/sax_document.rb
Instance Method Summary collapse
- #element(name, options = {}) ⇒ Object
- #elements(name, options = {}) ⇒ Object
- #parse(xml_text) ⇒ Object
- #sax_config ⇒ Object
Instance Method Details
#element(name, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sax-machine/sax_document.rb', line 22 def element(name, = {}) [:as] ||= name sax_config.add_top_level_element(name, ) # we only want to insert the getter and setter if they haven't defined it from elsewhere. # this is how we allow custom parsing behavior. So you could define the setter # and have it parse the string into a date or whatever. attr_reader [:as] unless instance_methods.include?([:as].to_s) attr_writer [:as] unless instance_methods.include?("#{[:as]}=") end |
#elements(name, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sax-machine/sax_document.rb', line 33 def elements(name, = {}) [:as] ||= name if [:class] sax_config.add_collection_element(name, ) else class_eval <<-SRC def add_#{[:as]}(value) #{[:as]} << value end SRC sax_config.add_top_level_element(name, .merge(:collection => true)) end class_eval <<-SRC def #{[:as]} @#{[:as]} ||= [] end SRC attr_writer [:as] end |
#parse(xml_text) ⇒ Object
18 19 20 |
# File 'lib/sax-machine/sax_document.rb', line 18 def parse(xml_text) new.parse(xml_text) end |