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
|
2017-07-12 22:25:10 +02:00
|
|
|
import Data
|
|
|
|
import RSDatabase
|
2017-09-05 02:10:02 +02:00
|
|
|
import RSParser
|
2017-07-11 05:54:00 +02:00
|
|
|
|
2017-09-13 22:29:52 +02:00
|
|
|
// MARK: - DatabaseObject
|
|
|
|
|
|
|
|
extension Author: DatabaseObject {
|
|
|
|
|
|
|
|
public func databaseDictionary() -> NSDictionary? {
|
2017-07-11 05:54:00 +02:00
|
|
|
|
2017-09-13 22:29:52 +02:00
|
|
|
var d = NSMutableDictionary()
|
2017-09-05 02:10:02 +02:00
|
|
|
|
2017-09-13 22:29:52 +02:00
|
|
|
// TODO
|
2017-09-09 21:57:24 +02:00
|
|
|
|
2017-09-13 22:29:52 +02:00
|
|
|
if d.count < 1 {
|
2017-09-05 02:10:02 +02:00
|
|
|
return nil
|
|
|
|
}
|
2017-09-13 22:29:52 +02:00
|
|
|
return (d.copy() as! NSDictionary)
|
2017-09-05 02:10:02 +02:00
|
|
|
}
|
2017-09-09 21:57:24 +02:00
|
|
|
|
2017-08-21 00:56:58 +02:00
|
|
|
|
2017-08-21 07:43:46 +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
|
|
|
}
|
|
|
|
}
|
2017-09-09 21:57:24 +02:00
|
|
|
|
|
|
|
// MARK: - Private
|
|
|
|
|
|
|
|
private extension Author {
|
|
|
|
|
2017-09-13 07:27:36 +02:00
|
|
|
init?(row: FMResultSet) {
|
|
|
|
|
|
|
|
let authorID = row.string(forColumn: DatabaseKey.authorID)
|
2017-09-09 21:57:24 +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)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-13 22:29:52 +02:00
|
|
|
// MARK: Author creation from Set<ParsedAuthor>
|
|
|
|
|
|
|
|
extension Set where Element == ParsedAuthor {
|
|
|
|
|
|
|
|
func authors() -> Set<Author>? {
|
|
|
|
|
|
|
|
let createdAuthors = Set(self.flatMap { Author(parsedAuthor: $0) })
|
|
|
|
return createdAuthors.isEmpty ? nil: createdAuthors
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|