adding ability to set frequency on a DataSourceSet
This commit is contained in:
parent
e751702610
commit
51d9aa02b4
|
@ -38,8 +38,15 @@ class DataSourceSet(WeightedSet):
|
|||
|
||||
def __init__(self, source: Path):
|
||||
self.source = DataSource(source.read_text())
|
||||
self._populate()
|
||||
|
||||
def _populate(self):
|
||||
super().__init__(*[(key, value) for key, value in self.source.frequencies.items()])
|
||||
|
||||
def set_frequency(self, frequency: str):
|
||||
self.source.set_frequency(frequency)
|
||||
self._populate()
|
||||
|
||||
def random(self):
|
||||
random_key = super().random()
|
||||
return self.source.as_dict()[random_key]
|
||||
|
|
Loading…
Reference in New Issue
Block a user