From 65c5b5199e8517364bb34eb3f11c59ed9e6b66ad Mon Sep 17 00:00:00 2001 From: evilchili Date: Wed, 12 Apr 2023 11:26:17 -0700 Subject: [PATCH] added metadata property --- pyproject.toml | 2 +- rolltable/tables.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index aa1669c..61f0d13 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = 'dnd-rolltable' -version = '1.1.8' +version = '1.1.9' license = 'The Unlicense' authors = ['Greg Boyington '] description = 'Generate roll tables using weighted random distributions' diff --git a/rolltable/tables.py b/rolltable/tables.py index 77de980..00d4e64 100644 --- a/rolltable/tables.py +++ b/rolltable/tables.py @@ -35,6 +35,7 @@ class DataSource: self.headers = [] self.frequencies = None self.data = None + self.metadata = None self.load_source() def load_source(self) -> None: @@ -45,19 +46,19 @@ class DataSource: return self.data = yaml.safe_load(self.source) - metadata = self.data.pop('metadata', {}) + self.metadata = self.data.pop('metadata', {}) num_keys = len(self.data.keys()) default_freq = num_keys / 100 - if 'headers' in metadata: - self.headers = metadata['headers'] + if 'headers' in self.metadata: + self.headers = self.metadata['headers'] frequencies = { 'default': dict([(k, default_freq) for k in self.data.keys()]) } - if 'frequencies' in metadata: - frequencies.update(**metadata['frequencies']) + if 'frequencies' in self.metadata: + frequencies.update(**self.metadata['frequencies']) self.frequencies = frequencies[self.frequency] @@ -106,6 +107,10 @@ class RollTable: struct[row[0]][self.headers[idx] if idx < len(self.headers) else '_'] = col return yaml.dump(struct, sort_keys=False) + @property + def datasources(self) -> List: + return self._data + @property def die(self) -> int: return self._die