NetNewsWire/Frameworks/Data/Author.swift

50 lines
1.1 KiB
Swift
Raw Normal View History

//
// Author.swift
// DataModel
//
// Created by Brent Simmons on 7/1/17.
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
//
import Foundation
2017-07-13 22:38:47 +02:00
import RSCore
public struct Author: Hashable {
2017-07-13 22:38:47 +02:00
public let databaseID: String // calculated
public let name: String?
public let url: String?
public let avatarURL: String?
public let emailAddress: String?
public let hashValue: Int
2017-07-13 22:38:47 +02:00
public init?(databaseID: String?, name: String?, url: String?, avatarURL: String?, emailAddress: String?) {
if name == nil && url == nil && emailAddress == nil {
return nil
}
self.name = name
self.url = url
self.avatarURL = avatarURL
self.emailAddress = emailAddress
var s = name ?? ""
s += url ?? ""
s += avatarURL ?? ""
s += emailAddress ?? ""
self.hashValue = s.hashValue
if let databaseID = databaseID {
self.databaseID = databaseID
}
else {
self.databaseID = databaseIDWithString(s)
2017-07-13 22:38:47 +02:00
}
}
public static func ==(lhs: Author, rhs: Author) -> Bool {
2017-07-13 22:38:47 +02:00
return lhs.hashValue == rhs.hashValue && lhs.databaseID == rhs.databaseID
}
}