Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Sources/Gedcom/AddressStructure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ n ADDR <Special> {1:1} g7:ADDR
+1 CTRY <Special> {0:1} g7:CTRY
*/

public class AddressStructure : RecordProtocol {
public class AddressStructure : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var address: String
public var adr1: String?
public var adr2: String?
Expand Down Expand Up @@ -56,7 +57,7 @@ public class AddressStructure : RecordProtocol {
var mutableSelf = self
for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}

Expand Down Expand Up @@ -90,6 +91,12 @@ public class AddressStructure : RecordProtocol {
record.children.append(Record(level: 1, tag: "CTRY", value: country))
}

for node in extensions {

record.children.append(node.export())

}

return record
}
}
Expand Down
48 changes: 36 additions & 12 deletions Sources/Gedcom/Dates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
+1 <<NOTE_STRUCTURE>> {0:M}
*/

public class DateTime : RecordProtocol {
public class DateTime : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var date: String = ""
public var parsedDate: GedcomDate? { GedcomDateParser.parse(date) }
public var time: String?
Expand All @@ -50,7 +51,7 @@ public class DateTime : RecordProtocol {

for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}
if let wkp = kp as? WritableKeyPath<DateTime, String> {
Expand All @@ -67,11 +68,15 @@ public class DateTime : RecordProtocol {
let timeRecord = Record(level: 1, tag: "TIME", value: time)
record.children.append(timeRecord)
}
for node in extensions {
record.children.append(node.export())
}
return record
}
}

public class DateTimeExact : RecordProtocol {
public class DateTimeExact : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var date: String = ""
public var parsedDate: GedcomDate? { GedcomDateParser.parse(date) }
public var time: String?
Expand All @@ -95,7 +100,7 @@ public class DateTimeExact : RecordProtocol {

for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}
if let wkp = kp as? WritableKeyPath<DateTimeExact, String> {
Expand All @@ -112,11 +117,15 @@ public class DateTimeExact : RecordProtocol {
let timeRecord = Record(level: 1, tag: "TIME", value: time)
record.children.append(timeRecord)
}
for node in extensions {
record.children.append(node.export())
}
return record
}
}

public class DateValue : RecordProtocol {
public class DateValue : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var date: String = ""
public var parsedDate: GedcomDate? { GedcomDateParser.parse(date) }
public var time: String?
Expand All @@ -135,7 +144,7 @@ public class DateValue : RecordProtocol {
var mutableSelf = self
for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}

Expand All @@ -155,11 +164,15 @@ public class DateValue : RecordProtocol {
let phraseRecord = Record(level: 1, tag: "PHRASE", value: phrase)
record.children.append(phraseRecord)
}
for node in extensions {
record.children.append(node.export())
}
return record
}
}

public class DatePeriod : RecordProtocol {
public class DatePeriod : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var date: String = ""
public var parsedDate: GedcomDate? { GedcomDateParser.parse(date) }
public var time: String?
Expand All @@ -178,7 +191,7 @@ public class DatePeriod : RecordProtocol {
var mutableSelf = self
for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}

Expand All @@ -198,12 +211,16 @@ public class DatePeriod : RecordProtocol {
let phraseRecord = Record(level: 1, tag: "PHRASE", value: phrase)
record.children.append(phraseRecord)
}
for node in extensions {
record.children.append(node.export())
}
return record
}
}


public class CreationDate : RecordProtocol {
public class CreationDate : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var date: DateTime = DateTime()
nonisolated(unsafe) static let keys : [String:AnyKeyPath] = [
"DATE" : \CreationDate.date,
Expand All @@ -217,7 +234,7 @@ public class CreationDate : RecordProtocol {
var mutableSelf = self
for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}

Expand All @@ -231,10 +248,14 @@ public class CreationDate : RecordProtocol {
let record = Record(level: 0, tag: "CREA")
let exportedDate = date.export()
record.children.append(exportedDate)
for node in extensions {
record.children.append(node.export())
}
return record
}
}
public class ChangeDate : RecordProtocol {
public class ChangeDate : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var date: DateTime = DateTime()
public var notes: [NoteStructure] = []

Expand All @@ -252,7 +273,7 @@ public class ChangeDate : RecordProtocol {
var mutableSelf = self
for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}

Expand All @@ -272,6 +293,9 @@ public class ChangeDate : RecordProtocol {
let exportedNote = note.export()
record.children.append(exportedNote)
}
for node in extensions {
record.children.append(node.export())
}
return record
}
}
67 changes: 55 additions & 12 deletions Sources/Gedcom/Family.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
//
import Foundation

public class LdsSpouseSealing : RecordProtocol {
public class LdsSpouseSealing : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var date: DateValue?
public var temple: String?
public var place: PlaceStructure?
Expand Down Expand Up @@ -58,7 +59,7 @@ public class LdsSpouseSealing : RecordProtocol {

for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}

Expand Down Expand Up @@ -102,12 +103,19 @@ public class LdsSpouseSealing : RecordProtocol {
record.children += [citation.export()]
}

for node in extensions {

record.children.append(node.export())

}

return record
}
}


public class SpouseAge : RecordProtocol {
public class SpouseAge : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
var kind: String
public var age: Age

Expand All @@ -126,7 +134,7 @@ public class SpouseAge : RecordProtocol {

for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}

Expand All @@ -141,6 +149,12 @@ public class SpouseAge : RecordProtocol {

record.children += [age.export()]

for node in extensions {

record.children.append(node.export())

}

return record
}
}
Expand All @@ -152,7 +166,8 @@ public enum FamilyAttributeKind : String {
case FACT
}

public class FamilyAttribute : RecordProtocol {
public class FamilyAttribute : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var kind: FamilyAttributeKind
public var text: String?
public var type: String?
Expand Down Expand Up @@ -230,7 +245,7 @@ public class FamilyAttribute : RecordProtocol {

for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}
if let wkp = kp as? WritableKeyPath<FamilyAttribute, String?> {
Expand Down Expand Up @@ -339,6 +354,12 @@ public class FamilyAttribute : RecordProtocol {
record.children += [Record(level: 1, tag: "UID", value: uuid.uuidString.lowercased())]
}

for node in extensions {

record.children.append(node.export())

}

return record
}
}
Expand All @@ -357,7 +378,8 @@ public enum FamilyEventKind : String {
case EVEN
}

public class NonFamilyEventStructure : RecordProtocol {
public class NonFamilyEventStructure : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var kind: FamilyEventKind
public var date: DatePeriod?
public var notes: [NoteStructure] = []
Expand Down Expand Up @@ -390,7 +412,7 @@ public class NonFamilyEventStructure : RecordProtocol {

for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}

Expand Down Expand Up @@ -419,11 +441,18 @@ public class NonFamilyEventStructure : RecordProtocol {
record.children += [citation.export()]
}

for node in extensions {

record.children.append(node.export())

}

return record
}
}

public class FamilyEvent : RecordProtocol {
public class FamilyEvent : RecordProtocol, GedcomExtensionContainer {
public var extensions: [GedcomExtensionNode] = []
public var kind: FamilyEventKind
public var text: String?
public var occured: Bool // Text == Y
Expand Down Expand Up @@ -541,7 +570,7 @@ public class FamilyEvent : RecordProtocol {

for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}

Expand Down Expand Up @@ -660,12 +689,19 @@ public class FamilyEvent : RecordProtocol {
record.children += [Record(level: 1, tag: "UID", value: uuid.uuidString.lowercased())]
}

for node in extensions {

record.children.append(node.export())

}

return record
}
}

public class Family : RecordProtocol {
public class Family : RecordProtocol, GedcomExtensionContainer {
public var xref: String
public var extensions: [GedcomExtensionNode] = []
public var restrictions: [Restriction] = []

public var attributes: [FamilyAttribute] = []
Expand Down Expand Up @@ -742,7 +778,7 @@ public class Family : RecordProtocol {

for child in record.children {
guard let kp = Self.keys[child.line.tag] else {
// throw GedcomError.badRecord
extensions.append(GedcomExtensionNode(record: child))
continue
}

Expand Down Expand Up @@ -850,7 +886,14 @@ public class Family : RecordProtocol {
record.children += [creationDate.export()]
}

for node in extensions {
record.children.append(node.export())
}

record.setLevel(0)
for node in extensions {
record.children.append(node.export())
}
return record
}
}
Loading
Loading