Module: XML
- Defined in:
- lib/sixarm_ruby_xml_load.rb
Class Method Summary collapse
-
.load_attributes(dirpath, xpath) ⇒ Object
Sugar to load attributes from a file.
-
.load_attributes_array(dirpath, xpath) ⇒ Object
Sugar to load attributes array from a file.
-
.load_attributes_hash(dirpath, xpath) ⇒ Object
Sugar to load attributes hash from a file.
-
.load_dir(*dirpaths) ⇒ Object
Specify one or more directory patterns and pass each XML file in the matching directories to a block.
-
.load_elements(dirpath, xpath) ⇒ Object
Sugar to load elements from a file.
Class Method Details
.load_attributes(dirpath, xpath) ⇒ Object
Sugar to load attributes from a file.
57 58 59 60 61 |
# File 'lib/sixarm_ruby_xml_load.rb', line 57 def XML.load_attributes(dirpath,xpath) XML.load_elements(dirpath,xpath){|elem| yield elem.attributes } end |
.load_attributes_array(dirpath, xpath) ⇒ Object
Sugar to load attributes array from a file.
69 70 71 72 73 |
# File 'lib/sixarm_ruby_xml_load.rb', line 69 def XML.load_attributes_array(dirpath,xpath) XML.load_elements(dirpath,xpath){|elem| yield elem.attributes.to_a } end |
.load_attributes_hash(dirpath, xpath) ⇒ Object
Sugar to load attributes hash from a file.
81 82 83 84 85 |
# File 'lib/sixarm_ruby_xml_load.rb', line 81 def XML.load_attributes_hash(dirpath,xpath) XML.load_elements(dirpath,xpath){|elem| yield elem.attributes.to_a_hash } end |
.load_dir(*dirpaths) ⇒ Object
Specify one or more directory patterns and pass each XML file in the matching directories to a block.
See [Dir#glob](www.ruby-doc.org/core/classes/Dir.html#M002347) for pattern details.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sixarm_ruby_xml_load.rb', line 25 def XML.load_dir(*dirpaths) dirpaths=[*dirpaths.flatten] dirpaths.each do |dirpath| Dir[dirpath].sort.each do |filename| File.open(filename) do |file| doc = REXML::Document.new file yield doc end #file end #dir end #each end |