diff --git a/repository/Neo-CSV-Magritte/MACSVWriter.class.st b/repository/Neo-CSV-Magritte/MACSVWriter.class.st index d49533d..6e7498d 100644 --- a/repository/Neo-CSV-Magritte/MACSVWriter.class.st +++ b/repository/Neo-CSV-Magritte/MACSVWriter.class.st @@ -8,7 +8,8 @@ Class { 'subjects', 'map', 'subjectDescription', - 'ignoresUnkownFields' + 'ignoresUnkownFields', + 'includesHeader' ], #category : #'Neo-CSV-Magritte-Visitors' } @@ -85,6 +86,14 @@ MACSVWriter >> map: aString fieldDo: aBlock [ self map add: field. ] +{ #category : #accessing } +MACSVWriter >> map: aString fieldSource: aBlock [ + + self + map: aString + fieldDo: [ :field | field descriptionSource: aBlock ] +] + { #category : #accessing } MACSVWriter >> subjectDescription [ ^ subjectDescription ifNil: [ subjectDescription := self subjects first magritteDescription ] @@ -128,10 +137,15 @@ MACSVWriter >> writeToStream: aStream [ | converter wrappedConverter | converter := field propertyAt: self fieldWriterPropertyKey - ifAbsent: [ [ :anObject | field read: anObject ] ]. + ifAbsent: #yourself. wrappedConverter := [ :anObject | (self ignoresUnknownFields not or: [ field accessor canRead: anObject ]) - ifTrue: [ converter value: anObject ] + ifTrue: [ + | aValue | + aValue := field read: anObject. + aValue = field undefinedValue ifTrue: [ + aValue := field default ]. + converter cull: aValue cull: anObject ] ifFalse: [ nil ] ]. self writer addField: wrappedConverter ]. diff --git a/repository/Neo-CSV-Magritte/MACSVWriterTests.class.st b/repository/Neo-CSV-Magritte/MACSVWriterTests.class.st index b135dc2..333da13 100644 --- a/repository/Neo-CSV-Magritte/MACSVWriterTests.class.st +++ b/repository/Neo-CSV-Magritte/MACSVWriterTests.class.st @@ -30,7 +30,6 @@ MACSVWriterTests >> testAddedDescription [ MAUrlDescription new accessor: #wikipediaUrl; priority: 25; - csvFieldName: 'Wikipedia'; yourself ] ]; execute.