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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/cryptopunks/dataset.rb', line 6
def self.read( path='./datasets/punks/*.csv' )
datasets = Dir.glob( path )
rows = []
datasets.each do |dataset|
rows += CsvHash.read( dataset )
end
punks = []
rows.each do |row|
id = row['id'].to_i
type_q = row['type']
count = row['count'].to_i
accessories_q = row['accessories'].split( %r{[ ]*/[ ]*} )
if count != accessories_q.size
puts "!! ERROR - punk data assertion failed - expected accessories count #{count}; got #{accessories_q.size}"
pp row
exit 1
end
type = Metadata::Type.find( type_q )
if type.nil?
puts "!! ERROR - punk data assertion failed - unknown punk type >#{type_q}<"
pp row
exit 1
end
accessories = []
accessories_q.each do |acc_q|
acc = Metadata::Accessory.find( acc_q )
if acc.nil?
puts "!! ERROR - punk data assertion failed - unknown punk accessory type >#{acc_q}<"
pp row
exit 1
end
accessories << acc
end
punks << Metadata.new( id, type, accessories )
end
punks
end
|