From: Ben Morse on 16 Jul 2010 01:23 hello, I am trying to make a simple ruby script that can look at a set of xml files, and make a set of folders based on the content of the XML files. As it stands I can import the data with REXML, but when I run the script I get a set of errors(I posted below the code) talking about TypeError. Take a look below and let me know what you think.. ________________________CODE_________________________ #!/usr/bin/ruby require 'rexml/document' include REXML jnumber_file = File.new("XML_EXPORT/export_j_number.xml") jname_file = File.new("XML_EXPORT/export_j_name.xml") cnumber_file = File.new("XML_EXPORT/export_cnumber.xml") cname_file = File.new("XML_EXPORT/export_c_name.xml") jnumber_file = Document.new(jnumber_file) jname_file = Document.new(jname_file) cnumber_file = Document.new(cnumber_file) cname_file = Document.new(cname_file) puts jnumber_file puts jname_file puts cnumbe_file puts cname_file class Job attr_accessor :client_num, :client_name, :job_num, :job_name; def generate_files() # print "Client Num is " + @client_num.to_s + "\n" client_dir = @client_num.to_s + "_" + @client_name job_dir = @job_num.to_s + "_" + @job_name if(! File.exist?(client_dir)) Dir.mkdir(client_dir); end Dir.mkdir(client_dir+"/"+job_dir); Dir.mkdir(client_dir+"/"+job_dir+"/parent"); Dir.mkdir(client_dir+"/"+job_dir+"/parent/old"); Dir.mkdir(client_dir+"/"+job_dir+"/parent/current"); Dir.mkdir(client_dir+"/"+job_dir+"/children"); Dir.mkdir(client_dir+"/"+job_dir+"/children/old"); Dir.mkdir(client_dir+"/"+job_dir+"/children/current"); end end j = Job.new j.client_name = cname j.client_num = cnumberfile j.job_name = cname j.job_num = jname_file j.generate_files() ____________________________END CODE_________________________ ____________________________ERROE____________________________ director_v3.rb:28:in `+': can't convert REXML::Document into String (TypeError) from director_v4.rb:28:in `generate_files' from director_v4.rb:50 ____________________________END ERROR________________________ Anything yall can see to help would be awsome! Thanks -- Posted via http://www.ruby-forum.com/.
From: Mark T on 16 Jul 2010 02:08 If you can afford the time to install Nokogiri, this might be a good direction to take. It has better mindshare at the moment. Anyways, could you re-run with the formatting below? (One typo found). MarkT #================================= require 'rexml/document' include REXML class Job attr_accessor :client_num, :client_name, :job_num, :job_name def generate_files() client_dir = @client_num.to_s + "_" + @client_name job_dir = @job_num.to_s + "_" + @job_name unless File.exist?(client_dir) then Dir.mkdir(client_dir) end Dir.mkdir(client_dir+"/"+job_dir) Dir.mkdir(client_dir+"/"+job_dir+"/parent") Dir.mkdir(client_dir+"/"+job_dir+"/parent/old") Dir.mkdir(client_dir+"/"+job_dir+"/parent/current") Dir.mkdir(client_dir+"/"+job_dir+"/children") Dir.mkdir(client_dir+"/"+job_dir+"/children/old") Dir.mkdir(client_dir+"/"+job_dir+"/children/current") end end def declareFiles jnumber_file = File.new("XML_EXPORT/export_j_number.xml") jname_file = File.new("XML_EXPORT/export_j_name.xml") cnumber_file = File.new("XML_EXPORT/export_cnumber.xml") cname_file = File.new("XML_EXPORT/export_c_name.xml") jnumber_file = Document.new(jnumber_file) jname_file = Document.new(jname_file) cnumber_file = Document.new(cnumber_file) cname_file = Document.new(cname_file) end j = Job.new j.client_name = cname j.client_num = cnumberfile j.job_name = cname j.job_num = jname_file j.declareFiles puts jnumber_file, jname_file, cnumber_file, cname_file j.generate_files() #=================================
From: Ben Morse on 16 Jul 2010 03:22 Thank you for you help! Sadly this didn't end up working I got errors (posted below) ____________________ERROR____________________________ undefined local variable or method `cnumber_file' for main:Object (NameError) ____________________END ERROR________________________ again sorry for the newness and thanks!!!! fro your help > > #================================= > require 'rexml/document' > include REXML > class Job > attr_accessor :client_num, :client_name, :job_num, :job_name > > def generate_files() > client_dir = @client_num.to_s + "_" + @client_name > job_dir = @job_num.to_s + "_" + @job_name > unless File.exist?(client_dir) then Dir.mkdir(client_dir) end > Dir.mkdir(client_dir+"/"+job_dir) > Dir.mkdir(client_dir+"/"+job_dir+"/parent") > Dir.mkdir(client_dir+"/"+job_dir+"/parent/old") > Dir.mkdir(client_dir+"/"+job_dir+"/parent/current") > Dir.mkdir(client_dir+"/"+job_dir+"/children") > Dir.mkdir(client_dir+"/"+job_dir+"/children/old") > Dir.mkdir(client_dir+"/"+job_dir+"/children/current") end end > > def declareFiles > jnumber_file = File.new("XML_EXPORT/export_j_number.xml") > jname_file = File.new("XML_EXPORT/export_j_name.xml") > cnumber_file = File.new("XML_EXPORT/export_cnumber.xml") > cname_file = File.new("XML_EXPORT/export_c_name.xml") > jnumber_file = Document.new(jnumber_file) > jname_file = Document.new(jname_file) > cnumber_file = Document.new(cnumber_file) > cname_file = Document.new(cname_file) end > > j = Job.new > j.client_name = cname > j.client_num = cnumberfile > j.job_name = cname > j.job_num = jname_file > j.declareFiles > puts jnumber_file, jname_file, cnumber_file, cname_file > j.generate_files() > #================================= -- Posted via http://www.ruby-forum.com/.
From: brabuhr on 16 Jul 2010 09:48 On Fri, Jul 16, 2010 at 1:23 AM, Ben Morse <cornflaik(a)gmail.com> wrote: > hello, > > I am trying to make a simple ruby script that can look at a set of xml > files, and make a set of folders based on the content of the XML files. > As it stands I can import the data with REXML, but when I run the script > I get a set of errors(I posted below the code) talking about TypeError. > > Take a look below and let me know what you think.. $ ruby /tmp/code_below /tmp/code_below:6:in `initialize': No such file or directory - XML_EXPORT/export_j_number.xml (Errno::ENOENT) from /tmp/code_below:6:in `new' from /tmp/code_below:6 Beyond that, is the posted code the same code that produced your sample output? 44 j.client_name = cname 46 j.job_name = cname But, cname is never set to anything before this point (or after). 9 cname_file = File.new("XML_EXPORT/export_c_name.xml") 14 cname_file = Document.new(cname_file) 19 puts cname_file But, cname_file is never used after this point. 18 puts cnumbe_file There is no cnumbe_file. 26 client_dir = @client_num.to_s + "_" + @client_name @client_num comes from: 45 j.client_num = cnumberfile 13 cnumber_file = Document.new(cnumber_file) @client_name comes from: 44 j.client_name = cname Should that have been?: 44 j.client_name = cname_file 14 cname_file = Document.new(cname_file) So, in line 26 we have something like: 26 client_dir = <REXML::Document>.to_s + "_" + <REXML::Document> 26 client_dir = <String> + "_" + <REXML::Document> 26 client_dir = <String> + <REXML::Document> TypeError: can't convert REXML::Document into String
|
Pages: 1 Prev: farming automation Next: Sinatra + mumboe-soap4r + ruby1.9.1 problem |