refine yaml output format
This commit is contained in:
parent
b43e972d1b
commit
9e7101945c
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = 'dnd-rolltable'
|
||||
version = '1.1.1'
|
||||
version = '1.1.3'
|
||||
license = 'The Unlicense'
|
||||
authors = ['Greg Boyington <evilchili@gmail.com>']
|
||||
description = 'Generate roll tables using weighted random distributions'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user