SAXMachine::ClassMethods

Public Instance Methods

ancestor(name, options = {}) click to toggle source
# File lib/sax-machine/sax_document.rb, line 55
def ancestor(name, options = {})
  real_name = (options[:as] ||= name).to_s
  sax_config.add_ancestor(name, options)
  create_attr(real_name)
end
attribute(name, options = {}) click to toggle source
# File lib/sax-machine/sax_document.rb, line 43
def attribute(name, options = {})
  real_name = (options[:as] ||= name).to_s
  sax_config.add_top_level_attribute(self.class.to_s, options.merge(:name => name))
  create_attr real_name
end
column(sym) click to toggle source
# File lib/sax-machine/sax_document.rb, line 65
def column(sym)
  columns.select { |c| c.column == sym }[0]
end
column_names() click to toggle source
# File lib/sax-machine/sax_document.rb, line 77
def column_names
  columns.map { |e| e.column }
end
columns() click to toggle source
# File lib/sax-machine/sax_document.rb, line 61
def columns
  sax_config.columns
end
create_attr(real_name) click to toggle source

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.

# File lib/sax-machine/sax_document.rb, line 112
def create_attr real_name
  attr_reader real_name unless method_defined?(real_name)
  attr_writer real_name unless method_defined?("#{real_name}=")
end
data_class(sym) click to toggle source
# File lib/sax-machine/sax_document.rb, line 69
def data_class(sym)
  column(sym).data_class
end
element(name, options = {}) click to toggle source
# File lib/sax-machine/sax_document.rb, line 37
def element(name, options = {})
  real_name = (options[:as] ||= name).to_s
  sax_config.add_top_level_element(name, options)
  create_attr real_name
end
elements(name, options = {}) click to toggle source
# File lib/sax-machine/sax_document.rb, line 81
def elements(name, options = {})
  options[:as] ||= name
  if options[:class]
    sax_config.add_collection_element(name, options)
  else
    class_eval           def add_#{options[:as]}(value)            #{options[:as]} << value          end
    sax_config.add_top_level_element(name, options.merge(:collection => true))
  end

  if !method_defined?(options[:as].to_s)
    class_eval           def #{options[:as]}            @#{options[:as]} ||= []          end
  end

  attr_writer options[:as] unless method_defined?("#{options[:as]}=")
end
inherited(subclass) click to toggle source
# File lib/sax-machine/sax_document.rb, line 29
def inherited(subclass)
  subclass.sax_config.send(:initialize_copy, self.sax_config)
end
parse(xml_text, on_error = nil, on_warning = nil) click to toggle source
# File lib/sax-machine/sax_document.rb, line 33
def parse(xml_text, on_error = nil, on_warning = nil)
  new.parse(xml_text, on_error, on_warning)
end
required?(sym) click to toggle source
# File lib/sax-machine/sax_document.rb, line 73
def required?(sym)
  column(sym).required?
end
sax_config() click to toggle source
# File lib/sax-machine/sax_document.rb, line 105
def sax_config
  @sax_config ||= SAXConfig.new
end
value(name, options = {}) click to toggle source
# File lib/sax-machine/sax_document.rb, line 49
def value(name, options = {})
  real_name = (options[:as] ||= name).to_s
  sax_config.add_top_level_element_value(self.class.to_s, options.merge(:name => name))
  create_attr real_name
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.