Creation/initialization utilities.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2022-04-28 15:05:45 -05:00
parent 62fa2ab8b9
commit b90c33bf04

View File

@ -15,30 +15,24 @@ HlPerson class >> fromListName [
]
{ #category : #accessing }
{ #category : #initialization }
HlPerson class >> fromListName: aString [
| allNames |
| allNames names |
allNames := aString substrings
collect: [:each | each first asString, each allButFirst asLowercase ].
allNames size = 4
ifTrue: [
^ self new
givenName: allNames first, ' ', allNames second;
familyName: allNames third, ' ', allNames fourth
].
allNames size = 3
ifTrue: [
^ self new
givenName: allNames first, ' ', allNames second;
familyName: allNames third.
].
allNames size = 2
ifTrue: [
^ self new
givenName: allNames first;
familyName: allNames second.
].
allNames size >= 3
ifFalse: [
^ self new
givenName: allNames second;
familyName: allNames first.
].
names := '' writeStream.
(allNames copyFrom: 3 to: allNames size) do: [:each |
names nextPutAll: each, ' '.
].
^ self new
familyName: allNames first, ' ', allNames second;
givenName: names contents trimmed
]
{ #category : #accessing }