Created a new flow generator + tests for it.
This commit is contained in:
parent
b8d4893026
commit
2b249063e0
2 changed files with 64 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Union, Iterable, Dict, Callable
|
||||
from typing import Union, Iterable, Dict, Callable, Type
|
||||
import re
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
|
@ -553,3 +553,38 @@ class ParsingFlow:
|
|||
issues[field.field_name] = this_field_issues
|
||||
|
||||
return issues
|
||||
|
||||
|
||||
class ParsingFlowGenerator:
|
||||
"""
|
||||
Class for creating multiple, empty flows based on a group of instructions.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
parsing_flow_class: Type[ParsingFlow],
|
||||
instructions_to_attach_with_params: Dict[
|
||||
Type[BaseTargetFieldInstructions], dict
|
||||
],
|
||||
) -> None:
|
||||
"""
|
||||
Set the flow class and group of instructions to use when creating new
|
||||
instances of the flow class.
|
||||
:param parsing_flow_class: the flow class to instantiate
|
||||
:param instructions_to_attach_with_params: a key-value pair of field
|
||||
instructions class and the paramteres to use when instantiating them
|
||||
"""
|
||||
self._parsing_flow_class = parsing_flow_class
|
||||
self._instructions_to_attach_with_params = instructions_to_attach_with_params
|
||||
|
||||
def get_new_flow(self) -> ParsingFlow:
|
||||
"""
|
||||
Instantiate a new parsing flow with the instantiated classes attached.
|
||||
:return: the new parsing flow
|
||||
"""
|
||||
new_parsing_flow = self._parsing_flow_class()
|
||||
|
||||
for instruction, params in self._instructions_to_attach_with_params.items():
|
||||
new_parsing_flow.add_instructions(instruction(**params))
|
||||
|
||||
return new_parsing_flow
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue