Class: EJStr
Constant Summary
collapse
- JAVA_TEMPLATE_FILE =
"ejstr.java.erb"
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, #str_to_id
Constructor Details
#initialize(files, pkg_name, clz_name) ⇒ EJStr
10
11
12
13
14
|
# File 'lib/ejstr.rb', line 10
def initialize(files, pkg_name, clz_name)
super(files)
@@package_name = pkg_name
@@class_name = clz_name
end
|
Instance Method Details
#_(str) ⇒ Object
45
46
47
48
|
# File 'lib/ejstr.rb', line 45
def _(str)
id = add(str_to_id(str), str)
return "#{getstr_funcname}(#{@@package_name}.#{@@class_name}._ENJSTR_IDS.#{id})"
end
|
#getstr_funcname ⇒ Object
6
7
8
|
# File 'lib/ejstr.rb', line 6
def getstr_funcname
"#{@@package_name}.#{@@class_name}._"
end
|
#run ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/ejstr.rb', line 16
def run
@dict = Hash.new
b = binding
@files.each do |infile|
outfile = infile[0..-5]
erbfile = ERB.new(File.read infile)
File.write outfile, erbfile.result(b)
print "#{infile} -> #{outfile}\n"
end
idx = 0
ids = "" strs = ""
@dict.each do |key, value|
ids += " public static final int #{key} = #{idx};\n"
idx += 1
strs += " \"#{encrypt value}\",\n"
end
ids += " public static final int ENCRYPTED_STR_TOTAL_NUM = #{idx};"
strs += " null"
str_src_file = "#{@@class_name}.java"
erbfile = ERB.new(File.read File.join(gem_root_dir, "lib/#{JAVA_TEMPLATE_FILE}"))
File.write str_src_file, erbfile.result(binding)
end
|