]>
Commit | Line | Data |
---|---|---|
1 | extension Map { | |
2 | static func parse(content: String) -> ParsedMap { | |
3 | ||
4 | let parsers = [ | |
5 | AnyMapParserStrategy(VertexParserStrategy()), | |
6 | AnyMapParserStrategy(EdgeParserStrategy()), | |
7 | AnyMapParserStrategy(BlockerParserStrategy()), | |
8 | AnyMapParserStrategy(OpportunityParserStrategy()), | |
9 | AnyMapParserStrategy(StageParserStrategy()), | |
10 | ] | |
11 | let builder = MapBuilder() | |
12 | ||
13 | let lines = content.split(whereSeparator: \.isNewline) | |
14 | ||
15 | for (index, line) in lines.enumerated() { | |
16 | for parser in parsers { | |
17 | if parser.canHandle(line: String(line)) { | |
18 | let (type, object) = parser.handle( | |
19 | index: index, line: String(line), vertices: builder.vertices) | |
20 | builder.addObjectToMap(type: type, object: object) | |
21 | break | |
22 | } | |
23 | } | |
24 | } | |
25 | ||
26 | return builder.build() | |
27 | } | |
28 | } |