damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

Block+Tests.swift (959B)


      1 //
      2 //  Block+Tests.swift
      3 //  damusTests
      4 //
      5 //  Created by Kyle Roucis on 9/1/23.
      6 //
      7 
      8 import Foundation
      9 @testable import damus
     10 
     11 
     12 extension Block {
     13     var asText: String? {
     14         switch self {
     15         case .text(let text):
     16             return text
     17         default:
     18             return nil
     19         }
     20     }
     21     
     22     var isText: Bool {
     23         return self.asText != nil
     24     }
     25     
     26     var asURL: URL? {
     27         switch self {
     28         case .url(let url):
     29             return url
     30         default:
     31             return nil
     32         }
     33     }
     34     
     35     var isURL: Bool {
     36         return self.asURL != nil
     37     }
     38     
     39     var asMention: Mention<MentionRef>? {
     40         switch self {
     41         case .mention(let mention):
     42             return mention
     43         default:
     44             return nil
     45         }
     46     }
     47     
     48     var asHashtag: String? {
     49         switch self {
     50         case .hashtag(let hashtag):
     51             return hashtag
     52         default:
     53             return nil
     54         }
     55     }
     56 }