Module: SAXMachine
- Defined in:
- lib/lazy-sax-machine/sax_config.rb,
lib/lazy-sax-machine/sax_handler.rb,
lib/lazy-sax-machine/sax_document.rb,
lib/lazy-sax-machine/sax_element_config.rb,
lib/lazy-sax-machine/sax_attribute_config.rb,
lib/lazy-sax-machine/sax_collection_config.rb,
lib/lazy-sax-machine/sax_element_value_config.rb
Defined Under Namespace
Modules: ClassMethods Classes: SAXConfig, SAXHandler
Class Method Summary collapse
Instance Method Summary collapse
- #parse(thing, options = {}) ⇒ Object
-
#to_h ⇒ Object
Convert this node to a hash.
-
#to_json ⇒ Object
Convert this node to JSON.
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/lazy-sax-machine/sax_document.rb', line 4 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#parse(thing, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lazy-sax-machine/sax_document.rb', line 8 def parse(thing, = {}) if [:lazy] require 'fiber' @parser = Fiber.new do Nokogiri::XML::SAX::Parser.new( SAXHandler.new(self) ).parse(thing) end else Nokogiri::XML::SAX::Parser.new( SAXHandler.new(self) ).parse(thing) end self end |
#to_h ⇒ Object
Convert this node to a hash
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lazy-sax-machine/sax_document.rb', line 23 def to_h h = {} instance_variables.each do |iv| val = instance_variable_get(iv) val = val.map(&:to_h) if val.is_a? Array key = iv[1..-1] h[key] = val end h end |
#to_json ⇒ Object
Convert this node to JSON
40 41 42 43 |
# File 'lib/lazy-sax-machine/sax_document.rb', line 40 def to_json require 'json' JSON.dump(to_h) end |