Skip to content

Commit

Permalink
doc: update tsm_mapping and tsm_list_mapping doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Oct 21, 2024
1 parent 7fabb18 commit 6fb6c8a
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ schema = ...
[
"tsm_mapper",
{"English": "eng"},
"English",
"English"
]
],
]
},
...
```
Expand All @@ -233,22 +233,45 @@ Works as `tsm_mapper` but with list. Doesn't have a `default` value. Third argum

If `remove` set to True, removes values from the list if they don't have a corresponding mapping. Defaults to `False`.

Example without `remove`:

```py
data = {"topic": ["Health", "Military", "Utilities"]}

schema = ...
"language": {
"topic": {
"validators": [
[
"tsm_mapper",
{"English": "eng"},
"English",
"tsm_list_mapper",
{"Military": "Army", "Utilities": "Utility"}
]
],
]
},
...
```

The result here will be `["Health", "Army", "Utility"]`
And here's an example with remove:

```py
data: dict[str, Any] = {"topic": ["Health", "Military", "Utilities"]}

tsm_schema = build_schema(
{
"topic": {
"validators": [
[
"tsm_list_mapper",
{"Military": "Army", "Utilities": "Utility"},
True
]
]
},
}
)
```
This will result in `["Army", "Utility"]`, and the `Health` will be deleted, cause it doesn't have a mapping.

### Keywords
1. `map` (`str`) - changes the `field.name` in result dict.
2. `validators` (`list[str]`) - a list of transmutators that will be applied to a `field.value`. A transmutator could be a `string` or a `list` where the first item must be transmutator name and others are arbitrary values. Example:
Expand Down

0 comments on commit 6fb6c8a

Please sign in to comment.