Module: SAXMachine::ClassMethods
- Defined in:
- lib/sax-machine/sax_document.rb
Instance Method Summary collapse
- #column(sym) ⇒ Object
- #column_names ⇒ Object
- #columns ⇒ Object
- #data_class(sym) ⇒ Object
- #element(name, options = {}) ⇒ Object
- #elements(name, options = {}) ⇒ Object
- #inherited(klass) ⇒ Object
- #parse(xml_text) ⇒ Object
- #required?(sym) ⇒ Boolean
- #sax_config ⇒ Object
- #sax_config=(config) ⇒ Object
Instance Method Details
#column(sym) ⇒ Object
37 38 39 |
# File 'lib/sax-machine/sax_document.rb', line 37 def column(sym) columns.select{|c| c.column == sym}[0] end |
#column_names ⇒ Object
49 50 51 |
# File 'lib/sax-machine/sax_document.rb', line 49 def column_names columns.map{|e| e.column} end |
#columns ⇒ Object
33 34 35 |
# File 'lib/sax-machine/sax_document.rb', line 33 def columns sax_config.columns end |
#data_class(sym) ⇒ Object
41 42 43 |
# File 'lib/sax-machine/sax_document.rb', line 41 def data_class(sym) column(sym).data_class end |
#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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sax-machine/sax_document.rb', line 53 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 if !instance_methods.include?([:as].to_s) class_eval <<-SRC def #{[:as]} @#{[:as]} ||= [] end SRC end attr_writer [:as] unless instance_methods.include?("#{[:as]}=") end |
#inherited(klass) ⇒ Object
85 86 87 88 |
# File 'lib/sax-machine/sax_document.rb', line 85 def inherited(klass) klass.sax_config = sax_config.clone super 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 |
#required?(sym) ⇒ Boolean
45 46 47 |
# File 'lib/sax-machine/sax_document.rb', line 45 def required?(sym) column(sym).required? end |
#sax_config ⇒ Object
77 78 79 |
# File 'lib/sax-machine/sax_document.rb', line 77 def sax_config @sax_config ||= SAXConfig.new end |
#sax_config=(config) ⇒ Object
81 82 83 |
# File 'lib/sax-machine/sax_document.rb', line 81 def sax_config=(config) @sax_config = config end |