-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRakefile
46 lines (39 loc) · 1.14 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
44
45
46
require 'fileutils'
require 'plist'
require 'csv'
bundle_path = File.path './GB2260/data'
data_path = File.path './data'
task default: %w[help]
task :init do
FileUtils.mkdir_p bundle_path
puts "Init folder -- #{bundle_path}"
end
task :cleanup do
FileUtils.rmdir bundle_path
puts "Cleanup folder -- #{bundle_path}"
end
task :reinit => [:cleanup, :init]
task :update => [:reinit] do
Dir["#{data_path.to_s}/*.tsv"].each do |file|
plist_name = File.basename(file, '.*')
plist_path = "#{bundle_path}/#{plist_name}.plist"
print "Writing to file #{plist_path}... "
plist = {revision: plist_name}
data = {}
CSV.read(file, { col_sep: "\t", headers: true}).each do |row|
data[row['Code']] = row['Name']
end
plist.merge!({data: data})
File.write(plist_path, plist.to_plist)
puts "- Done!"
end
end
task :help do
puts """Available commands:
init Create the data folder
cleanup Remove the data folder
reinit Reinit the data folder
update Reinit dataset and transfer original tsv data to plists.
help Display general or command-specific help
"""
end