Method: Punk::Metadata.parse

Defined in:
lib/punks/dataset/dataset.rb

.parse(row) ⇒ Object

rename metod to build - why? why not?



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/punks/dataset/dataset.rb', line 14

def self.parse( row )   ## rename metod to build - why? why not?
   id            = row['id'].to_i( 10 )
   type          = row['type']

   ## split into array - allow accessores or aattributes key / header
   accessories   = row.has_key?( 'accessories' ) ?  row['accessories'] : row['attribuutes']  
   accessories  =  accessories.split( '/' ).map { |acc| acc.strip }
 
   ## optional count to double check - why? why not?
   count         = row.has_key?( 'count' ) ? row['count'].to_i( 10 ) : nil

   if count && count != accessories.size
      puts "!! ERROR - punk data assertion failed - expected accessories count #{count}; got #{accessories.size}"
      pp row
      exit 1
   end

   new( id: id, 
        type: type,
        accessories: accessories )
end