Use a Set<ParsedAuthor> instead of [ParsedAuthor] array.
This commit is contained in:
parent
9a45ab7996
commit
b1bd1ac75a
|
@ -50,7 +50,7 @@ public struct JSONFeedParser {
|
|||
|
||||
private extension JSONFeedParser {
|
||||
|
||||
static func parseAuthors(_ dictionary: JSONDictionary) -> [ParsedAuthor]? {
|
||||
static func parseAuthors(_ dictionary: JSONDictionary) -> Set<ParsedAuthor>? {
|
||||
|
||||
guard let authorDictionary = dictionary["author"] as? JSONDictionary else {
|
||||
return nil
|
||||
|
@ -63,7 +63,7 @@ private extension JSONFeedParser {
|
|||
return nil
|
||||
}
|
||||
let parsedAuthor = ParsedAuthor(name: name, url: url, avatarURL: avatar, emailAddress: nil)
|
||||
return [parsedAuthor]
|
||||
return Set([parsedAuthor])
|
||||
}
|
||||
|
||||
static func parseHubs(_ dictionary: JSONDictionary) -> Set<ParsedHub>? {
|
||||
|
|
|
@ -132,13 +132,13 @@ private extension RSSInJSONParser {
|
|||
return nil
|
||||
}
|
||||
|
||||
static func parseAuthors(_ itemDictionary: JSONDictionary) -> [ParsedAuthor]? {
|
||||
static func parseAuthors(_ itemDictionary: JSONDictionary) -> Set<ParsedAuthor>? {
|
||||
|
||||
guard let authorEmailAddress = itemDictionary["author"] as? String else {
|
||||
return nil
|
||||
}
|
||||
let parsedAuthor = ParsedAuthor(name: nil, url: nil, avatarURL: nil, emailAddress: authorEmailAddress)
|
||||
return [parsedAuthor]
|
||||
return Set([parsedAuthor])
|
||||
}
|
||||
|
||||
static func parseTags(_ itemDictionary: JSONDictionary) -> [String]? {
|
||||
|
|
|
@ -8,18 +8,31 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public struct ParsedAuthor {
|
||||
public struct ParsedAuthor: Hashable {
|
||||
|
||||
public let name: String?
|
||||
public let url: String?
|
||||
public let avatarURL: String?
|
||||
public let emailAddress: String?
|
||||
|
||||
public let hashValue: Int
|
||||
|
||||
init(name: String?, url: String?, avatarURL: String?, emailAddress: String?) {
|
||||
|
||||
self.name = name
|
||||
self.url = url
|
||||
self.avatarURL = avatarURL
|
||||
self.emailAddress = emailAddress
|
||||
|
||||
var stringToHash = ""
|
||||
stringToHash += name ?? ""
|
||||
stringToHash += url ?? ""
|
||||
stringToHash += avatarURL ?? ""
|
||||
stringToHash += emailAddress ?? ""
|
||||
self.hashValue = stringToHash.hashValue
|
||||
}
|
||||
|
||||
public static func ==(lhs: ParsedAuthor, rhs: ParsedAuthor) -> Bool {
|
||||
|
||||
return lhs.hashValue == rhs.hashValue && lhs.name == rhs.name && lhs.url == rhs.url && lhs.avatarURL == rhs.avatarURL && lhs.emailAddress == rhs.emailAddress
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@ public struct ParsedFeed {
|
|||
public let nextURL: String?
|
||||
public let iconURL: String?
|
||||
public let faviconURL: String?
|
||||
public let authors: [ParsedAuthor]?
|
||||
public let authors: Set<ParsedAuthor>?
|
||||
public let expired: Bool
|
||||
public let hubs: Set<ParsedHub>?
|
||||
public let items: Set<ParsedItem>
|
||||
|
||||
init(type: FeedType, title: String?, homePageURL: String?, feedURL: String?, feedDescription: String?, nextURL: String?, iconURL: String?, faviconURL: String?, authors: [ParsedAuthor]?, expired: Bool, hubs: Set<ParsedHub>?, items: Set<ParsedItem>) {
|
||||
init(type: FeedType, title: String?, homePageURL: String?, feedURL: String?, feedDescription: String?, nextURL: String?, iconURL: String?, faviconURL: String?, authors: Set<ParsedAuthor>?, expired: Bool, hubs: Set<ParsedHub>?, items: Set<ParsedItem>) {
|
||||
|
||||
self.type = type
|
||||
self.title = title
|
||||
|
|
|
@ -23,12 +23,12 @@ public struct ParsedItem: Hashable {
|
|||
public let bannerImageURL: String?
|
||||
public let datePublished: Date?
|
||||
public let dateModified: Date?
|
||||
public let authors: [ParsedAuthor]?
|
||||
public let authors: Set<ParsedAuthor>?
|
||||
public let tags: [String]?
|
||||
public let attachments: [ParsedAttachment]?
|
||||
public let hashValue: Int
|
||||
|
||||
init(syncServiceID: String?, uniqueID: String, feedURL: String, url: String?, externalURL: String?, title: String?, contentHTML: String?, contentText: String?, summary: String?, imageURL: String?, bannerImageURL: String?, datePublished: Date?, dateModified: Date?, authors: [ParsedAuthor]?, tags: [String]?, attachments: [ParsedAttachment]?) {
|
||||
init(syncServiceID: String?, uniqueID: String, feedURL: String, url: String?, externalURL: String?, title: String?, contentHTML: String?, contentText: String?, summary: String?, imageURL: String?, bannerImageURL: String?, datePublished: Date?, dateModified: Date?, authors: Set<ParsedAuthor>?, tags: [String]?, attachments: [ParsedAttachment]?) {
|
||||
|
||||
self.syncServiceID = syncServiceID
|
||||
self.uniqueID = uniqueID
|
||||
|
|
|
@ -45,12 +45,12 @@ private extension RSParsedFeedTransformer {
|
|||
return ParsedItem(syncServiceID: nil, uniqueID: uniqueID, feedURL: parsedArticle.feedURL, url: url, externalURL: externalURL, title: title, contentHTML: contentHTML, contentText: nil, summary: nil, imageURL: nil, bannerImageURL: nil, datePublished: datePublished, dateModified: dateModified, authors: authors, tags: nil, attachments: nil)
|
||||
}
|
||||
|
||||
static func parsedAuthors(_ authorEmailAddress: String?) -> [ParsedAuthor]? {
|
||||
static func parsedAuthors(_ authorEmailAddress: String?) -> Set<ParsedAuthor>? {
|
||||
|
||||
guard let authorEmailAddress = authorEmailAddress else {
|
||||
return nil
|
||||
}
|
||||
let author = ParsedAuthor(name: nil, url: nil, avatarURL: nil, emailAddress: authorEmailAddress)
|
||||
return [author]
|
||||
return Set([author])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue