From 3ee6ea6ebea579d2d8910970bb0d896b0eb5d1fb Mon Sep 17 00:00:00 2001 From: Shawn Zivontsis Date: Wed, 13 Nov 2024 15:01:08 -0500 Subject: [PATCH] Refactor placeholder replacement into separate function --- rendercv/data/models/computers.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/rendercv/data/models/computers.py b/rendercv/data/models/computers.py index 043ccbd2..c53069fd 100644 --- a/rendercv/data/models/computers.py +++ b/rendercv/data/models/computers.py @@ -89,11 +89,8 @@ def format_date(date: Date, date_style: Optional[str] = None) -> str: return date_string # type: ignore -def convert_string_to_path(value: str) -> pathlib.Path: - """Converts a string to a `pathlib.Path` object by replacing the placeholders - with the corresponding values. If the path is not an absolute path, it is - converted to an absolute path by prepending the current working directory. - """ +def replace_placeholders(value: str) -> str: + """Replaces the placeholders in a string with the corresponding values.""" name = curriculum_vitae["name"] # Curriculum Vitae owner's name full_month_names = LOCALE_CATALOG["full_names_of_months"] short_month_names = LOCALE_CATALOG["abbreviations_for_months"] @@ -120,6 +117,16 @@ def convert_string_to_path(value: str) -> pathlib.Path: for placeholder, placeholder_value in placeholders.items(): value = value.replace(placeholder, placeholder_value) + return value + + +def convert_string_to_path(value: str) -> pathlib.Path: + """Converts a string to a `pathlib.Path` object by replacing the placeholders + with the corresponding values. If the path is not an absolute path, it is + converted to an absolute path by prepending the current working directory. + """ + value = replace_placeholders(value) + return pathlib.Path(value).absolute()