Modularizing the code.

This commit is contained in:
Offray Vladimir Luna Cárdenas 2021-11-22 12:25:48 -05:00
parent 40ab1d0000
commit 7c8c897d60
2 changed files with 17 additions and 13 deletions

View File

@ -1,16 +1,8 @@
accessing
fromDictionary: aDictionary
| optionsTable |
name := aDictionary at: 'Name' ifAbsent: [ name := aDictionary at: 'Display name' ].
name := aDictionary
at: 'Name'
ifAbsent: [ name := aDictionary at: 'Display name' ].
intro := aDictionary at: 'Description'.
optionsTable := aDictionary at: 'Table'.
optionsTable doWithIndex: [:opt :i | | key value prevKey |
(i = 1)
ifTrue: [key := 1 to: (opt at: 'Chance') asInteger]
ifFalse: [
prevKey := ((optionsTable at: (i-1)) at: 'Chance').
key := (prevKey asInteger + 1) to: (opt at: 'Chance') asInteger.
].
value := (opt at: 'Description') capitalized.
self options at: key put: value .
].
self optionsFromDictionary: (aDictionary at: 'Table')

View File

@ -0,0 +1,12 @@
accessing
optionsFromDictionary: aDictionary
aDictionary doWithIndex: [ :opt :i |
| key value prevKey |
i = 1
ifTrue: [ key := 1 to: (opt at: 'Chance') asInteger ]
ifFalse: [
prevKey := (aDictionary at: i - 1) at: 'Chance'.
key := prevKey asInteger + 1 to: (opt at: 'Chance') asInteger ].
value := (opt at: 'Description') capitalized.
self options at: key put: value ]