home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 4427 / aisp_memo-20090510.7z / hed_dat3_src / src / make_code_map.rb < prev    next >
Encoding:
Ruby Source  |  2009-04-18  |  608 b   |  27 lines

  1. #!/usr/bin/env ruby
  2.  
  3. def make_code_map(infile, className)
  4.   key = []
  5.   value = []
  6.   ifp = open(infile)
  7.   ifp.read.each do |line|
  8.     if line =~ /^(\d+),(.*)/
  9.       key << $1
  10.       value << $2
  11.     end
  12.   end
  13.   ifp.close
  14.  
  15.   ofp = open("#{className}.java", "w")
  16.   ofp.printf "public class #{className} {\n"
  17.   ofp.printf "\tpublic static final String[][] array = {\n"
  18.   key.length.times do |i|
  19.     ofp.printf "\t\t{\"#{key[i]}\", \"#{value[i]}\"},\n"
  20.   end
  21.   ofp.printf "\t};\n"
  22.   ofp.printf "}\n"
  23. end
  24.  
  25. make_code_map('../../codes/@items.csv', 'ItemList')
  26. make_code_map('../../codes/@characters.csv', 'CharaList')
  27.