-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDocument.py
35 lines (27 loc) · 1.19 KB
/
Document.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import abc
from Interchange import Interchange
from Configuration import EdiDocumentConfiguration
from Settings import CurrentSettings
from Reports import ValidationReport
class Document(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def parse_text(self, text_to_parse):
return
class EdiDocument(Document):
"""An EDI X12 document"""
def __init__(self):
self.document_text = ""
self.document_configuration = EdiDocumentConfiguration(CurrentSettings.version,
CurrentSettings.element_separator,
CurrentSettings.segment_terminator,
CurrentSettings.sub_element_separator)
self.interchange = Interchange()
def format_as_edi(self):
"""Format this document as EDI and return it as a string"""
return self.interchange.format_as_edi(self.document_configuration)
def validate(self):
"""Validate this document and return a validation report"""
report = ValidationReport()
self.interchange.validate(report)
return report