-
Notifications
You must be signed in to change notification settings - Fork 8
/
data_scripts.rb
39 lines (37 loc) · 989 Bytes
/
data_scripts.rb
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
# hex to byte array JS syntax string
# INPUT = "".gsub(" ", '')
# output = "["
# INPUT.chars.each_slice(2) do |pair|
# output << "\"#{pair.join.to_i(16).to_s}\","
# end
# puts "#{output[0...-1]}]"
# RLE encode byte array
# INPUT = []
# INPUT << "TERM" # terminate the algorithm cleanly
# output = "["
# current_val = INPUT.first
# current_count = 0
# INPUT.each do |val|
# if current_val != val
# if current_count == 1
# output << "#{current_val},"
# else
# output << "[#{current_val},#{current_count}],"
# end
# current_val = val
# current_count = 0
# end
# current_count += 1
# end
# puts "#{output[0...-1]}]"
# convert metadata into title -> code map
require 'csv'
map = {}
output = "TITLE_TO_CODE = {"
CSV.foreach("metadata.csv", headers: true) do |row|
next if row['ROM Size'] =~ /M/
map[row['Internal Title']&.gsub(' ', '')&.upcase] = row['Code']
end
output += map.map { |k, v| "\"#{k}\":\"#{v}\"" }.join(',')
output += '};'
puts output