Skip to content

Commit 2f1568c

Browse files
authored
Update action_mapper.py
1 parent 8422e33 commit 2f1568c

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

transformers/action_mapper.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
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
246
from .base_transformer import BaseTransformer
347

448
class ActionMapper(BaseTransformer):

0 commit comments

Comments
 (0)