Class: Punk::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/punks/dataset/dataset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, type:, accessories: []) ⇒ Metadata

Returns a new instance of Metadata.



36
37
38
39
40
# File 'lib/punks/dataset/dataset.rb', line 36

def initialize( id:, type:, accessories: [] )
  @id          = id
  @type        = type
  @accessories = accessories
end

Instance Attribute Details

#accessoriesObject (readonly) Also known as: attributes

Returns the value of attribute accessories.



7
8
9
# File 'lib/punks/dataset/dataset.rb', line 7

def accessories
  @accessories
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/punks/dataset/dataset.rb', line 7

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/punks/dataset/dataset.rb', line 7

def type
  @type
end

Class Method Details

.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