Class: Awis::Utils::XML
- Inherits:
-
Object
- Object
- Awis::Utils::XML
- Defined in:
- lib/awis/utils/xml.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #each_node(attributes_in_path = false) ⇒ Object
-
#initialize(data) ⇒ XML
constructor
A new instance of XML.
Constructor Details
#initialize(data) ⇒ XML
Returns a new instance of XML.
8 9 10 |
# File 'lib/awis/utils/xml.rb', line 8 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/awis/utils/xml.rb', line 6 def data @data end |
Instance Method Details
#each_node(attributes_in_path = false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/awis/utils/xml.rb', line 12 def each_node(attributes_in_path = false) reader = Nokogiri::XML::Reader(@data) nodes = [''] reader.each do |node| if node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT if attributes_in_path && !node.attributes.empty? attributes = [] node.attributes.sort.each do |name, value| attributes << "@#{name}=#{value}" end nodes << "#{node.name}/#{attributes.join('/')}" else nodes << node.name end path = nodes.join('/') yield node, path end nodes.pop if node.node_type == Nokogiri::XML::Reader::TYPE_END_ELEMENT || node.self_closing? # End tag end end |