From: Jeff Pritchard Date: 2006-11-09T01:03:37+09:00 Subject: Re: can you rubyfy this? ChrisH wrote: > I'm no expert, but this is how I would do it: > > #!/usr/bin/ruby > require "rexml/document" > require "id3lib" > include REXML > include ID3Lib > > File.new("collection.nml", 'r'){|inF| > doc = Document.new(inF) > > doc.root.each_element("//ENTRY"){|node| > #use File.join to ensure path is good and cross-platform > file = File.join(node.elements["LOCATION"].attributes["DIR"], > node.elements["LOCATION"].attributes["FILE"]) > if File.exists?(file) > #use 'unless' instead of 'if !' > node.add_attribute "ARTIST" unless node.attributes["ARTIST"] > #why assign Tag to a variable if only uses one? > node.attributes["ARTIST"] = Tag.new(file).artist > end > } > > File.new("test.xml", "w+"){|out| > #use block to ensure file is closed, > doc.write out > } > } > > > Cheers > Chris I'm no expert either, but I'm going to have to ask for a "Man Law" from the group on this one. No use of the uglier of the two types of brace alignment that came out of the 'C' world. I know it's just a matter of taste, and I mean no disrespect to Chris or his opinion, but I for one just can't stomach this style of brace alignment. Seeing it in a Ruby script is, for me, like fingernails on a blackboard. Use of do/end obviates the need for the usual tug of war on this age-old issue. jp -- Posted via http://www.ruby-forum.com/.