Skip to content

Commit cbdce94

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

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

transformers/action_mapper.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,38 @@
11
"""Action mapping transformer.
22
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.
55
"""
66

7-
from typing import Any
8-
from typing import Dict
7+
from typing import Dict, Any
98

109
from .base_transformer import BaseTransformer
1110

1211

1312
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."""
2014

2115
def __init__(self, action_map: Dict[str, str]) -> None:
2216
"""Initialize the ActionMapper.
2317
2418
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.
2721
"""
2822
self.action_map = action_map
2923

3024
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.
3229
3330
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.
3632
3733
Returns:
38-
The transformed item with its ``action`` field mapped according
39-
to the configured action map.
34+
The transformed item dictionary.
4035
"""
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]:
5536
action = item.get("action")
5637
if action in self.action_map:
5738
item["action"] = self.action_map[action]

0 commit comments

Comments
 (0)