Class: Jaspion::Miya::Document
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Jaspion::Miya::Document
- Defined in:
- lib/jaspion/miya/document.rb
Constant Summary collapse
- FLAT =
0
- TREE =
1
Instance Attribute Summary collapse
-
#objects ⇒ Object
Array with Miya::Object objects.
-
#structure ⇒ Object
Indicates if the elements should be a flat array or hierarchy.
Instance Method Summary collapse
-
#end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object
Nokogiri Document method.
-
#initialize(xml = nil, structure = TREE) ⇒ Document
constructor
Initializes a Document object and parses the xml argument if present.
-
#parse(xml) ⇒ Object
Replaces the current @objects variable.
-
#start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) ⇒ Object
Nokogiri Document method.
Constructor Details
#initialize(xml = nil, structure = TREE) ⇒ Document
Initializes a Document object and parses the xml argument if present
16 17 18 19 20 21 22 |
# File 'lib/jaspion/miya/document.rb', line 16 def initialize(xml = nil, structure = TREE) @objects = [] @structure = structure return if xml.nil? parse(xml) end |
Instance Attribute Details
#objects ⇒ Object
Array with Miya::Object objects
10 11 12 |
# File 'lib/jaspion/miya/document.rb', line 10 def objects @objects end |
#structure ⇒ Object
Indicates if the elements should be a flat array or hierarchy
13 14 15 |
# File 'lib/jaspion/miya/document.rb', line 13 def structure @structure end |
Instance Method Details
#end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object
Nokogiri Document method
37 38 39 40 41 42 43 44 |
# File 'lib/jaspion/miya/document.rb', line 37 def end_element_namespace(name, prefix = nil, uri = nil) return if name.nil? return if @structure == FLAT return if @objects.length <= 1 last = @objects.delete(@objects.last) @objects.last.push_child(last) end |
#parse(xml) ⇒ Object
Replaces the current @objects variable
25 26 27 28 29 30 |
# File 'lib/jaspion/miya/document.rb', line 25 def parse(xml) @objects = [] parser = Nokogiri::XML::SAX::Parser.new(self) parser.parse(xml) raise 'Document cannot have more than one root element' if @objects.length > 1 end |
#start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) ⇒ Object
Nokogiri Document method
33 34 |
# File 'lib/jaspion/miya/document.rb', line 33 def start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) end |