Class: ECStr
Overview
Usage:
ruby -I . ecstr.rb a.cpp.erb b.c.erb c.cpp.erb
Result:
create a.cpp, b.c, c.cpp, ecstrdef.data
In the erb file,when using a string, write as:
<%= _ "the string which will be encrypted" %>
Remember to <% require 'ecstr' %> at begining of the erb file.
Constant Summary collapse
- DATA_FILE_NAME =
"ecstrdef.data"
Constants inherited from CommonEnc
CommonEnc::CSTR_DICT, CommonEnc::HEX_DICT
Instance Method Summary collapse
Methods inherited from CommonEnc
#_, #add, decrypt, #dict, #encrypt, #files, #gem_root_dir, get_instance, #getstr_funcname, #initialize, #str_to_id
Constructor Details
This class inherits a constructor from CommonEnc
Instance Method Details
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ecstr.rb', line 26 def run @dict = Hash.new b = binding @files.each do |infile| outfile = infile[0..-5] # "a.cpp.erb" => "a.cpp" erbfile = ERB.new(File.read infile) File.write outfile, erbfile.result(b) print "#{infile} --> #{outfile}\n" end ids = "enum {\n __BEGIN = -1,\n" strs = "static const char *estrs[] = {\n" @dict.each do |key, value| ids += " #{key},\n" strs += " \"#{encrypt value}\",\n" end ids += " ENCRYPTED_STR_TOTAL_NUM\n};\n" strs += " NULL\n};\n" File.write DATA_FILE_NAME, "#ifndef __#{DATA_FILE_NAME.gsub('.','_').upcase}__\n#define __#{DATA_FILE_NAME.gsub('.','_').upcase}__\n\n#{ids}\n\n#{strs}\n\n#endif\n" print "Data file #{DATA_FILE_NAME} created.\n" end |