From 5c57d262d5fed3f910afb5ae3ca6a312d9f28a1b Mon Sep 17 00:00:00 2001 From: evilchili Date: Tue, 19 Dec 2023 21:29:39 -0800 Subject: [PATCH] refactoring datasource to make subclassing easier --- rolltable/tables.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rolltable/tables.py b/rolltable/tables.py index 1862ac5..32e600f 100644 --- a/rolltable/tables.py +++ b/rolltable/tables.py @@ -44,16 +44,22 @@ class DataSource: """ if self.data: return + self.read_source() + self.init_headers() + self.init_frequencies() + def read_source(self) -> None: self.data = yaml.safe_load(self.source) self.metadata = self.data.pop('metadata', {}) - num_keys = len(self.data.keys()) - default_freq = num_keys / 100 - + def init_headers(self) -> None: if 'headers' in self.metadata: self.headers = self.metadata['headers'] + def init_frequencies(self) -> None: + num_keys = len(self.data.keys()) + default_freq = num_keys / 100 + frequencies = { 'default': dict([(k, default_freq) for k in self.data.keys()]) }