Module: Saxophone
- Defined in:
- lib/saxophone.rb,
lib/saxophone/version.rb,
lib/saxophone/sax_config.rb,
lib/saxophone/sax_document.rb,
lib/saxophone/sax_configure.rb,
lib/saxophone/config/sax_element.rb,
lib/saxophone/config/sax_ancestor.rb,
lib/saxophone/config/sax_attribute.rb,
lib/saxophone/config/sax_collection.rb,
lib/saxophone/handlers/sax_ox_handler.rb,
lib/saxophone/config/sax_element_value.rb,
lib/saxophone/handlers/sax_oga_handler.rb,
lib/saxophone/handlers/sax_abstract_handler.rb,
lib/saxophone/handlers/sax_nokogiri_handler.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods, LightWeightSaxMachine, SAXAbstractHandler
Classes: SAXConfig, SAXNokogiriHandler, SAXOgaHandler, SAXOxHandler
Constant Summary
collapse
- VERSION =
"1.1.0"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/saxophone/sax_configure.rb', line 2
def self.configure(clazz)
extended_clazz = Class.new(clazz)
extended_clazz.send(:include, Saxophone)
def extended_clazz.create_attr real_name
superclass.send(:attr_reader, real_name) unless superclass.method_defined?(real_name)
superclass.send(:attr_writer, real_name) unless superclass.method_defined?("#{real_name}=")
end
yield(extended_clazz)
clazz.extend LightWeightSaxMachine
clazz.sax_config = extended_clazz.sax_config
(class << clazz;self;end).send(:define_method, :parse) do |xml_input|
extended_clazz.parse(xml_input)
end
end
|
.handler ⇒ Object
7
8
9
|
# File 'lib/saxophone.rb', line 7
def self.handler
@@handler ||= nil
end
|
.handler=(handler) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/saxophone.rb', line 11
def self.handler=(handler)
if handler
require "saxophone/handlers/sax_#{handler}_handler"
@@handler = handler
end
end
|
.included(base) ⇒ Object
2
3
4
5
|
# File 'lib/saxophone/sax_document.rb', line 2
def self.included(base)
base.send(:include, InstanceMethods)
base.extend(ClassMethods)
end
|
.on_error ⇒ Object
18
19
20
|
# File 'lib/saxophone.rb', line 18
def self.on_error
@@on_error ||= ->(_) {}
end
|
.on_error=(on_error_proc) ⇒ Object
22
23
24
|
# File 'lib/saxophone.rb', line 22
def self.on_error=(on_error_proc)
@@on_error = on_error_proc
end
|
.on_warning ⇒ Object
26
27
28
|
# File 'lib/saxophone.rb', line 26
def self.on_warning
@@on_warning ||= ->(_) {}
end
|
.on_warning=(on_warning_proc) ⇒ Object
30
31
32
|
# File 'lib/saxophone.rb', line 30
def self.on_warning=(on_warning_proc)
@@on_warning = on_warning_proc
end
|
Instance Method Details
#parse(xml_input, on_error = Saxophone.on_error, on_warning = Saxophone.on_warning) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/saxophone/sax_document.rb', line 7
def parse(xml_input, on_error = Saxophone.on_error, on_warning = Saxophone.on_warning)
handler_klass = Saxophone.const_get("SAX#{Saxophone.handler.capitalize}Handler")
handler = handler_klass.new(self, on_error, on_warning)
handler.sax_parse(xml_input)
self
end
|