Skip to content

Commit

Permalink
Merge cae2f63
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvc committed Oct 10, 2023
2 parents cca7fbb + cae2f63 commit 63cbd24
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ MACSVMappedPragmaBuilder >> map: fieldName fieldTo: descriptionSelector using: r
descriptionSelector - returning the description to be used
reader - typically a block, where arguments are:
1) the field string input and
2) the description"
2) the description
A typical pattern is to customize the description and then use the default reader with something like this:
`desc defaultCsvReader cull: input trimmed`"

self map at: descriptionSelector put: { fieldName. reader }
]
2 changes: 1 addition & 1 deletion repository/Neo-CSV-Magritte/MACSVTwoStageImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ MACSVTwoStageImporter >> initializeDomainObject: anObject fromRecord: aDictionar
fieldReader := desc
propertyAt: self fieldReaderPropertyKey
ifAbsent: [ desc csvReader ].
value := fieldReader value: stringValue.
value := fieldReader cull: stringValue cull: desc.
desc write: value to: anObject ] ] ].
^ anObject
]
Expand Down
7 changes: 5 additions & 2 deletions repository/Neo-CSV-Magritte/MAElementDescription.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ MAElementDescription >> csvReader [
{ #category : #'*Neo-CSV-Magritte' }
MAElementDescription >> csvReader: aBlock [
"
aBlock - should take the input string as its argument and return a value appropriate to the field e.g. aDate for MADateDescription."
aBlock
- 1st argument - the input string
- 2nd (optional) argument - this description
- return value - a value appropriate to the field e.g. aDate for MADateDescription."
^ self propertyAt: #csvReader put: aBlock
]

Expand All @@ -33,7 +36,7 @@ MAElementDescription >> defaultCsvReader [
MAElementDescription >> fromCSV: aStringOrNil [
| value |
(aStringOrNil isNil or: [ aStringOrNil isEmpty ]) ifTrue: [ ^ nil ].
value := self csvReader value: aStringOrNil trimmed.
value := self csvReader cull: aStringOrNil trimmed cull: self.
(self default = value and: [ self shouldCacheDefault not ]) ifTrue: [ ^ nil ].
^ value
"Implementation note: this was extracted from NeoCSVReader's Magritte field adding because it is useful in other places e.g. MACSVImporter"
Expand Down

0 comments on commit 63cbd24

Please sign in to comment.