I have this following test data that needs to export to the format shown in my desired output with ruby programming. The real data array has 1000000 records.
data_array1=aaaa
data_array2=bbbb
----------------
----------------
data_array8=hhhh , which means there are 8 data array, those have the following format :
aaaa= [a,[1,2,3,4],20]
bbbb= [b,[8,7,9,19],23]
-----------------------
-----------------------
hhhh= [h,[25,26,29,30],28]
My desired out put needs to be exported to text file (headers just for FYI,no need to include in the output file) :
output.txt
hash tx time
a 1 20
a 2 20
a 3 20
a 4 20
b 8 25
b 7 25
b 9 25
b 19 25
------------
------------
h 25 28
h 26 28
h 29 28
h 30 28
I am a newbie in Ruby and so far I have done this, which inconclusive:
def bhash
1.upto(8) do |bid|
blk=[bid]
keys = %w[hash tx time ]
data = keys.map{|key| blk[key]}
hash, txids, time, difficulty = data
CSV.open('output.txt', 'w', headers: keys, write_headers: true, col_sep:
"\t") do |csv|
txids.each do |tx|
csv << [hash,tx,time]
end
end
end
Thanks in advance for all your help.