|
1 | 1 | """Action mapping transformer. |
2 | 2 |
|
3 | | -This module defines a transformer responsible for mapping action values |
4 | | -between vendor-specific representations and the universal data model. |
| 3 | +This module provides the ActionMapper class, which converts action values |
| 4 | +between vendor-specific and universal representations. |
5 | 5 | """ |
6 | 6 |
|
7 | | -from typing import Any |
8 | | -from typing import Dict |
| 7 | +from typing import Dict, Any |
9 | 8 |
|
10 | 9 | from .base_transformer import BaseTransformer |
11 | 10 |
|
12 | 11 |
|
13 | 12 | 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 | | - """ |
| 13 | + """Maps actions from vendor-specific values to universal values and vice versa.""" |
20 | 14 |
|
21 | 15 | def __init__(self, action_map: Dict[str, str]) -> None: |
22 | 16 | """Initialize the ActionMapper. |
23 | 17 |
|
24 | 18 | Args: |
25 | | - action_map: A dictionary mapping source action values to |
26 | | - destination action values. |
| 19 | + action_map: A mapping from vendor-specific action names |
| 20 | + to universal action names. |
27 | 21 | """ |
28 | 22 | self.action_map = action_map |
29 | 23 |
|
30 | 24 | def transform(self, item: Dict[str, Any]) -> Dict[str, Any]: |
31 | | - """Transform an item's action field using the action mapping. |
| 25 | + """Transform the action field of an item using the action map. |
| 26 | +
|
| 27 | + If the item's ``action`` value exists in the action map, it is |
| 28 | + replaced with the mapped universal value. |
32 | 29 |
|
33 | 30 | Args: |
34 | | - item: A dictionary representing a single rule or configuration |
35 | | - entry containing an ``action`` field. |
| 31 | + item: A dictionary representing the item to transform. |
36 | 32 |
|
37 | 33 | Returns: |
38 | | - The transformed item with its ``action`` field mapped according |
39 | | - to the configured action map. |
| 34 | + The transformed item dictionary. |
40 | 35 | """ |
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 |
46 | | -from .base_transformer import BaseTransformer |
47 | | - |
48 | | -class ActionMapper(BaseTransformer): |
49 | | - """Maps actions from vendor to universal and vice versa.""" |
50 | | - |
51 | | - def __init__(self, action_map: Dict[str, str]): |
52 | | - self.action_map = action_map |
53 | | - |
54 | | - def transform(self, item: Dict[str, Any]) -> Dict[str, Any]: |
55 | 36 | action = item.get("action") |
56 | 37 | if action in self.action_map: |
57 | 38 | item["action"] = self.action_map[action] |
|
0 commit comments