diff --git a/src/MiniDocs/Array.extension.st b/src/MiniDocs/Array.extension.st index ee27e93..e3a24f7 100644 --- a/src/MiniDocs/Array.extension.st +++ b/src/MiniDocs/Array.extension.st @@ -26,3 +26,20 @@ Array >> bagOfWordsFor: sentenceArray [ ]. ^ bagOfWords ] + +{ #category : #'*MiniDocs' } +Array >> replaceWithUniqueNilsAndBooleans [ + | response | + (self includesAny: #(true false nil)) + ifFalse: [ response := self ] + ifTrue: [ | newItem | + response := OrderedCollection new. + self do: [:item | + (item isBoolean or: [ item isNil ]) + ifTrue: [ newItem := item asString, '-', (NanoID generate copyFrom: 1 to: 3) ] + ifFalse: [ newItem := item ]. + response add: newItem. + ]. + ]. + ^ response +] diff --git a/src/MiniDocs/OrderedDictionary.extension.st b/src/MiniDocs/OrderedDictionary.extension.st index 4c763e4..b15b516 100644 --- a/src/MiniDocs/OrderedDictionary.extension.st +++ b/src/MiniDocs/OrderedDictionary.extension.st @@ -48,7 +48,7 @@ OrderedDictionary >> replaceNilsWith: aCharacter [ { #category : #'*MiniDocs' } OrderedDictionary >> replaceWithUniqueNilsAndBooleansStartingAt: anInteger [ - | totalNils shortUID | + | totalNils shortUID newArray | totalNils := self flattened asDataSeries countNils. shortUID := [NanoID generate copyFrom: 1 to: 3]. self associations doWithIndex: [:assoc :i | | subIndex | @@ -58,21 +58,8 @@ OrderedDictionary >> replaceWithUniqueNilsAndBooleansStartingAt: anInteger [ assoc value isBoolean ifTrue: [ self at: assoc key put: assoc value asString, '-', subIndex ]. assoc value isDictionary ifTrue: [assoc replaceWithUniqueNilsAndBooleansStartingAt: i]. - assoc value isArray ifTrue: [ | newArray| - newArray := (assoc value asDataSeries replaceNilsWith: 'nil-', shortUID value) asArray. - (newArray includesAny: #(true false)) - ifTrue: [ | response newItem | - response := OrderedCollection new. - self do: [ :item | - item isBoolean - ifTrue: [ newItem := item asString, '-', shortUID value] - ifFalse: [ newItem := item ]. - response add: newItem. - ]. - newArray := response asArray. - ]. - self at: assoc key put: newArray - ] + assoc value isArray + ifTrue: [ self at: assoc key put: (assoc value replaceWithUniqueNilsAndBooleans)] ] ]