⚙️ supporte plusieurs remplacement d'un coup
parent
a63d02601f
commit
c0bd229cde
|
@ -71,30 +71,7 @@ export default (rules, rule, parsedRules) => {
|
|||
nonApplicableRules.map(referenceName => {
|
||||
return disambiguateRuleReference(rules, rule, referenceName)
|
||||
}),
|
||||
remplace: reference => {
|
||||
const referenceName =
|
||||
typeof reference === 'string' ? reference : reference.règle
|
||||
let replacementNode = reference.par
|
||||
if (replacementNode) {
|
||||
replacementNode = parse(rules, rule, parsedRules)(replacementNode)
|
||||
}
|
||||
let [whiteListedNames, blackListedNames] = [
|
||||
reference.dans,
|
||||
reference['sauf dans']
|
||||
]
|
||||
.map(name => name && coerceArray(name))
|
||||
.map(
|
||||
names =>
|
||||
names &&
|
||||
names.map(name => disambiguateRuleReference(rules, rule, name))
|
||||
)
|
||||
return {
|
||||
referenceName: disambiguateRuleReference(rules, rule, referenceName),
|
||||
replacementNode,
|
||||
whiteListedNames,
|
||||
blackListedNames
|
||||
}
|
||||
},
|
||||
remplace: evolveReplacement(rules, rule, parsedRules),
|
||||
formule: value => {
|
||||
let evaluate = (cache, situationGate, parsedRules, node) => {
|
||||
let explanation = evaluateNode(
|
||||
|
@ -232,3 +209,29 @@ let evolveCond = (name, rule, rules, parsedRules) => value => {
|
|||
explanation: child
|
||||
}
|
||||
}
|
||||
|
||||
let evolveReplacement = (rules, rule, parsedRules) => replacements =>
|
||||
coerceArray(replacements).map(reference => {
|
||||
const referenceName =
|
||||
typeof reference === 'string' ? reference : reference.règle
|
||||
let replacementNode = reference.par
|
||||
if (replacementNode != null) {
|
||||
replacementNode = parse(rules, rule, parsedRules)(replacementNode)
|
||||
}
|
||||
let [whiteListedNames, blackListedNames] = [
|
||||
reference.dans,
|
||||
reference['sauf dans']
|
||||
]
|
||||
.map(name => name && coerceArray(name))
|
||||
.map(
|
||||
names =>
|
||||
names &&
|
||||
names.map(name => disambiguateRuleReference(rules, rule, name))
|
||||
)
|
||||
return {
|
||||
referenceName: disambiguateRuleReference(rules, rule, referenceName),
|
||||
replacementNode,
|
||||
whiteListedNames,
|
||||
blackListedNames
|
||||
}
|
||||
})
|
||||
|
|
|
@ -60,12 +60,15 @@ export let parseAll = flatRules => {
|
|||
nonApplicableMapping[rule.dottedName] = parsed['rend non applicable']
|
||||
}
|
||||
|
||||
const descriptor = parsed['remplace']
|
||||
if (descriptor) {
|
||||
replacedByMapping[descriptor.referenceName] = [
|
||||
...(replacedByMapping[descriptor.referenceName] ?? []),
|
||||
{ ...descriptor, referenceName: rule.dottedName }
|
||||
]
|
||||
const replaceDescriptors = parsed['remplace']
|
||||
if (replaceDescriptors) {
|
||||
replaceDescriptors.forEach(
|
||||
descriptor =>
|
||||
(replacedByMapping[descriptor.referenceName] = [
|
||||
...(replacedByMapping[descriptor.referenceName] ?? []),
|
||||
{ ...descriptor, referenceName: rule.dottedName }
|
||||
])
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -136,14 +136,24 @@
|
|||
valeur attendue: 40
|
||||
applicable si: exemple4
|
||||
|
||||
- test: remplacement de plusieurs variables d'un coup
|
||||
formule: cotisations
|
||||
remplace:
|
||||
- règle: cotisations . chômage
|
||||
par: 10
|
||||
- règle: cotisations . maladie
|
||||
par: 0
|
||||
exemples:
|
||||
- situation:
|
||||
exemple5: oui
|
||||
valeur attendue: 110
|
||||
applicable si: exemple5
|
||||
|
||||
- nom: exemple1
|
||||
formule: non
|
||||
- nom: exemple2
|
||||
formule: non
|
||||
- nom: exemple3
|
||||
formule: non
|
||||
- nom: exemple4
|
||||
formule: non
|
||||
- nom: exemple5
|
||||
|
||||
- nom: A
|
||||
formule: 1
|
||||
|
|
Loading…
Reference in New Issue