|
1 | | -from typing import Dict, Any |
| 1 | +"""Action mapping transformer. |
| 2 | +
|
| 3 | +This module defines a transformer responsible for mapping action values |
| 4 | +between vendor-specific representations and the universal data model. |
| 5 | +""" |
| 6 | + |
| 7 | +from typing import Any |
| 8 | +from typing import Dict |
| 9 | + |
| 10 | +from .base_transformer import BaseTransformer |
| 11 | + |
| 12 | + |
| 13 | +class ActionMapper(BaseTransformer): |
| 14 | + """Map action values between vendor and universal models. |
| 15 | +
|
| 16 | + This transformer replaces the ``action`` field of an item using a |
| 17 | + predefined mapping dictionary. If the action is not found in the |
| 18 | + mapping, it is left unchanged. |
| 19 | + """ |
| 20 | + |
| 21 | + def __init__(self, action_map: Dict[str, str]) -> None: |
| 22 | + """Initialize the ActionMapper. |
| 23 | +
|
| 24 | + Args: |
| 25 | + action_map: A dictionary mapping source action values to |
| 26 | + destination action values. |
| 27 | + """ |
| 28 | + self.action_map = action_map |
| 29 | + |
| 30 | + def transform(self, item: Dict[str, Any]) -> Dict[str, Any]: |
| 31 | + """Transform an item's action field using the action mapping. |
| 32 | +
|
| 33 | + Args: |
| 34 | + item: A dictionary representing a single rule or configuration |
| 35 | + entry containing an ``action`` field. |
| 36 | +
|
| 37 | + Returns: |
| 38 | + The transformed item with its ``action`` field mapped according |
| 39 | + to the configured action map. |
| 40 | + """ |
| 41 | + action = item.get("action") |
| 42 | + if action in self.action_map: |
| 43 | + item["action"] = self.action_map[action] |
| 44 | + |
| 45 | + return itemfrom typing import Dict, Any |
2 | 46 | from .base_transformer import BaseTransformer |
3 | 47 |
|
4 | 48 | class ActionMapper(BaseTransformer): |
|
0 commit comments