preheat_open.api.factories.AppliedPriceComponentFactory

class preheat_open.api.factories.AppliedPriceComponentFactory(input_dict={})

Bases: Factory

__init__(input_dict={})

Initialize the factory with input configuration.

Parameters:

input_dict (dict[str, Any]) – Dictionary containing configuration data

Example:
>>> factory = Factory.__new__(Factory)
>>> factory.__init__({"test": "value"})
>>> factory.input_dict
{'test': 'value'}

Methods

__init__([input_dict])

Initialize the factory with input configuration.

build(**kwargs)

Build the target object from the configuration dictionary.

make_sub_classes()

Create any necessary sub-objects before building the main object.

translate(obj)

Translate an object back to its dictionary representation.

build(**kwargs)

Build the target object from the configuration dictionary.

This method processes the input dictionary, creates any necessary sub-objects, and instantiates the target class with the translated parameters.

Parameters:

kwargs – Additional keyword arguments to merge with input_dict

Returns:

Instance of the target class

Return type:

Any

Raises:

TypeError – If translation fails

Example:
>>> class TestClass:
...     def __init__(self, name):
...         self.name = name
>>>
>>> class TestFactory(Factory):
...     def __init__(self, input_dict=None):
...         super().__init__(input_dict or {})
...         self._return_class = TestClass
...         self._translation_dict = {"name": "test_name"}
>>>
>>> factory = TestFactory({"test_name": "example"})
>>> obj = factory.build()
>>> obj.name
'example'
make_sub_classes()

Create any necessary sub-objects before building the main object.

This method is called before building the main object and allows the factory to create any dependent objects or modify the input dictionary as needed. :rtype: None

Note

Override this method in subclasses to implement custom sub-object creation logic.

classmethod translate(obj)

Translate an object back to its dictionary representation.

This class method reverses the build process, converting an object back to the dictionary format expected by the factory.

Parameters:

obj – Object to translate

Returns:

Dictionary representation of the object

Return type:

Any

Raises:

TypeError – If object is not of the expected type

Example:
>>> class TestClass:
...     def __init__(self, name):
...         self.name = name
>>>
>>> class TestFactory(Factory):
...     _return_class = TestClass
...     _translation_dict = {"name": "test_name"}
>>>
>>> obj = TestClass("example")
>>> result = TestFactory.translate(obj)
>>> result
{'test_name': 'example'}