diff --git a/pyproject.toml b/pyproject.toml index 9bd50e6..55746a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = 'dnd-rolltable' -version = '1.1.1' +version = '1.1.3' license = 'The Unlicense' authors = ['Greg Boyington '] description = 'Generate roll tables using weighted random distributions' diff --git a/rolltable/cli.py b/rolltable/cli.py index 4b32417..039e535 100644 --- a/rolltable/cli.py +++ b/rolltable/cli.py @@ -34,7 +34,7 @@ def create( rt = tables.RollTable([Path(s).read_text() for s in sources], frequency=frequency, die=die) if yaml: - print(rt.as_yaml) + print(rt.as_yaml()) return rows = rt.rows if collapsed else rt.expanded_rows diff --git a/rolltable/tables.py b/rolltable/tables.py index 1a91341..dc21823 100644 --- a/rolltable/tables.py +++ b/rolltable/tables.py @@ -93,6 +93,14 @@ class RollTable: self._generated_values = None self._config() + def as_yaml(self, expanded=False) -> dict: + struct = {} + for row in self.rows[1:]: + struct[row[0]] = {} + for idx, col in enumerate(row[1:]): + struct[row[0]][self.headers[idx]] = col + return yaml.dump(struct) + @property def die(self) -> int: return self._die @@ -170,13 +178,6 @@ class RollTable: def as_markdown(self) -> str: return '' - @property - def as_yaml(self) -> dict: - struct = {'headers': self.rows[0]} - for row in self.rows[1:]: - struct[row[0]] = row[1:] - return yaml.dump(struct) - def _config(self): """ Parse data sources, generate headers, and create the column filters