added metadata property

This commit is contained in:
evilchili 2023-04-12 11:26:17 -07:00
parent 75a5b884c7
commit 65c5b5199e
2 changed files with 11 additions and 6 deletions

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = 'dnd-rolltable'
version = '1.1.8'
version = '1.1.9'
license = 'The Unlicense'
authors = ['Greg Boyington <evilchili@gmail.com>']
description = 'Generate roll tables using weighted random distributions'

View File

@ -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