Skip to content

Commit

Permalink
add doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
TShapinsky committed May 16, 2023
1 parent af4a9af commit 3cb694c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions buildingmotif/ingresses/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,36 @@ def records(self) -> List[Record]:
raise NotImplementedError("Must be overridden by subclass")

def dump(self, path: PathLike):
"""
Takes the contents of the records of this handler and writes them to a JSON file
:param path: path to write output file to
:type path: PathLike
"""
output_string = self.dumps()
Path(path).write_text(output_string)

def dumps(self) -> str:
"""
Takes the contents of the records of this handler and writes them to a string
"""
records = [
{"rtype": record.rtype, "fields": record.fields} for record in self.records
]
return json.dumps(records)

@classmethod
def load(cls, path: PathLike):
"""
Takes a file generated by 'dump' and creates a new ingress handler with those records
"""
return cls.loads(Path(path).read_text())

@classmethod
def loads(cls, s: str):
"""
Takes the string output by 'dumps' and creates a new ingress handler with those records
"""
self = cls.__new__(cls)
records = []
for record in json.loads(s):
Expand Down

0 comments on commit 3cb694c

Please sign in to comment.