NetNewsWire/Frameworks/Database/Extensions/Author+Database.swift

50 lines
1.2 KiB
Swift
Raw Normal View History

2017-07-11 05:54:00 +02:00
//
// Author+Database.swift
// Database
//
// Created by Brent Simmons on 7/8/17.
// Copyright © 2017 Ranchero Software. All rights reserved.
//
import Foundation
import Data
import RSDatabase
import RSParser
2017-07-11 05:54:00 +02:00
extension Author {
2017-08-21 00:56:58 +02:00
init?(authorID: String, row: FMResultSet) {
2017-07-11 05:54:00 +02:00
let name = row.string(forColumn: DatabaseKey.name)
let url = row.string(forColumn: DatabaseKey.url)
let avatarURL = row.string(forColumn: DatabaseKey.avatarURL)
let emailAddress = row.string(forColumn: DatabaseKey.emailAddress)
2017-07-11 05:54:00 +02:00
2017-08-21 00:56:58 +02:00
self.init(authorID: authorID, name: name, url: url, avatarURL: avatarURL, emailAddress: emailAddress)
}
init?(parsedAuthor: ParsedAuthor) {
self.init(authorID: nil, name: parsedAuthor.name, url: parsedAuthor.url, avatarURL: parsedAuthor.avatarURL, emailAddress: parsedAuthor.emailAddress)
}
static func authorsWithParsedAuthors(_ parsedAuthors: [ParsedAuthor]?) -> Set<Author>? {
guard let parsedAuthors = parsedAuthors else {
return nil
}
let authors = Set(parsedAuthors.flatMap { Author(parsedAuthor: $0) })
2017-09-05 17:53:45 +02:00
return authors.isEmpty ? nil : authors
}
2017-08-21 00:56:58 +02:00
}
extension Author: DatabaseObject {
2017-08-21 00:56:58 +02:00
public var databaseID: String {
2017-08-21 00:56:58 +02:00
get {
return authorID
}
2017-07-11 05:54:00 +02:00
}
}