Class: Punk::Metadata
- Inherits:
-
Object
- Object
- Punk::Metadata
- Defined in:
- lib/punks/dataset/dataset.rb
Instance Attribute Summary collapse
-
#accessories ⇒ Object
(also: #attributes)
readonly
Returns the value of attribute accessories.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.parse(row) ⇒ Object
rename metod to build - why? why not?.
Instance Method Summary collapse
-
#initialize(id:, type:, accessories: []) ⇒ Metadata
constructor
A new instance of Metadata.
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
#accessories ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/punks/dataset/dataset.rb', line 7 def id @id end |
#type ⇒ Object (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 |