Marked ParsedFeed.hubs a Set<ParsedHub>.

This commit is contained in:
Brent Simmons 2017-09-10 10:53:24 -07:00
parent 7415131e8d
commit 9a45ab7996
3 changed files with 23 additions and 10 deletions

View File

@ -66,19 +66,19 @@ private extension JSONFeedParser {
return [parsedAuthor] return [parsedAuthor]
} }
static func parseHubs(_ dictionary: JSONDictionary) -> [ParsedHub]? { static func parseHubs(_ dictionary: JSONDictionary) -> Set<ParsedHub>? {
guard let hubsArray = dictionary["hubs"] as? JSONArray else { guard let hubsArray = dictionary["hubs"] as? JSONArray else {
return nil return nil
} }
let hubs = hubsArray.flatMap { (oneHubDictionary) -> ParsedHub? in let hubs = hubsArray.flatMap { (hubDictionary) -> ParsedHub? in
guard let oneHubURL = oneHubDictionary["url"] as? String, let oneHubType = oneHubDictionary["type"] as? String else { guard let hubURL = hubDictionary["url"] as? String, let hubType = hubDictionary["type"] as? String else {
return nil return nil
} }
return ParsedHub(type: oneHubType, url: oneHubURL) return ParsedHub(type: hubType, url: hubURL)
} }
return hubs.isEmpty ? nil : hubs return hubs.isEmpty ? nil : Set(hubs)
} }
static func parseItems(_ itemsArray: JSONArray, _ feedURL: String) -> Set<ParsedItem> { static func parseItems(_ itemsArray: JSONArray, _ feedURL: String) -> Set<ParsedItem> {

View File

@ -20,10 +20,10 @@ public struct ParsedFeed {
public let faviconURL: String? public let faviconURL: String?
public let authors: [ParsedAuthor]? public let authors: [ParsedAuthor]?
public let expired: Bool public let expired: Bool
public let hubs: [ParsedHub]? public let hubs: Set<ParsedHub>?
public let items: Set<ParsedItem> 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: [ParsedHub]?, 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>) {
self.type = type self.type = type
self.title = title self.title = title

View File

@ -8,8 +8,21 @@
import Foundation import Foundation
public struct ParsedHub { public struct ParsedHub: Hashable {
public let type: String? public let type: String
public let url: String? public let url: String
public let hashValue: Int
init(type: String, url: String) {
self.type = type
self.url = url
self.hashValue = type.hashValue ^ url.hashValue
}
public static func ==(lhs: ParsedHub, rhs: ParsedHub) -> Bool {
return lhs.type == rhs.type && lhs.url == rhs.url
}
} }