NetNewsWire/Frameworks/Account/FeedProvider/Twitter/TwitterEntities.swift

65 lines
1.2 KiB
Swift
Raw Normal View History

2020-04-18 19:03:37 +02:00
//
// TwitterEntities.swift
// Account
//
// Created by Maurice Parker on 4/18/20.
// Copyright © 2020 Ranchero Software, LLC. All rights reserved.
//
import Foundation
2020-04-20 02:19:39 +02:00
protocol TwitterEntity {
var indices: [Int]? { get }
func renderAsHTML() -> String
}
extension TwitterEntity {
var startIndex: Int? {
if indices?.count ?? 0 > 0 {
return indices?[0]
}
return nil
}
var endIndex: Int? {
if indices?.count ?? 0 > 1 {
return indices?[1]
}
return nil
}
}
2020-04-18 19:03:37 +02:00
struct TwitterEntities: Codable {
let hashtags: [TwitterHashtag]?
let urls: [TwitterURL]?
let userMentions: [TwitterMention]?
let symbols: [TwitterSymbol]?
enum CodingKeys: String, CodingKey {
case hashtags = "hashtags"
case urls = "urls"
case userMentions = "user_mentions"
case symbols = "symbols"
}
2020-04-20 02:19:39 +02:00
func combineAndSort() -> [TwitterEntity] {
var entities = [TwitterEntity]()
if let hashtags = hashtags {
entities.append(contentsOf: hashtags)
}
if let urls = urls {
entities.append(contentsOf: urls)
}
if let userMentions = userMentions {
entities.append(contentsOf: userMentions)
}
if let symbols = symbols {
entities.append(contentsOf: symbols)
}
return entities
}
2020-04-18 19:03:37 +02:00
}