<commit_before>//
//  Attachment.swift
//  Rocket.Chat
//
//  Created by <NAME> on 01/10/16.
//  Copyright © 2016 Rocket.Chat. All rights reserved.
//

import Foundation

enum AttachmentType {
    case image
    case audio
    case video
}

class Attachment: BaseModel {
    var type: AttachmentType {
        get { return .image }
    }
    
    dynamic var title = ""
    dynamic var title_link = ""
    dynamic var title_link_download = true
    
    dynamic var image_url = ""
    dynamic var image_type = ""
    dynamic var image_size = ""
    dynamic var image_dimensions = ""
    
    dynamic var audio_url = ""
    dynamic var audio_type = ""
    dynamic var audio_size = ""
    
    dynamic var video_url = ""
    dynamic var video_type = ""
    dynamic var video_size = ""
}<commit_msg>Map JSON dict into Realm model<commit_after>//
//  Attachment.swift
//  Rocket.Chat
//
//  Created by <NAME> on 01/10/16.
//  Copyright © 2016 Rocket.Chat. All rights reserved.
//

import Foundation
import SwiftyJSON
import RealmSwift

enum AttachmentType {
    case image
    case audio
    case video
}

class Attachment: BaseModel {
    var type: AttachmentType {
        get { return .image }
    }
    
    dynamic var title = ""
    dynamic var titleLink = ""
    dynamic var titleLinkDownload = true
    
    dynamic var imageURL: String? = nil
    dynamic var imageType: String? = nil
    dynamic var imageSize = 0
    
    dynamic var audioURL: String? = nil
    dynamic var audioType: String? = nil
    dynamic var audioSize = 0
    
    dynamic var videoURL: String? = nil
    dynamic var videoType: String? = nil
    dynamic var videoSize = 0
    

    // MARK: ModelMapping

    override func update(_ dict: JSON) {
        if self.identifier == nil {
            self.identifier = String.random(30)
        }
        
        if let title = dict["title"].string {
            self.title = title
        }
        
        if let titleLink = dict["title_link"].string {
            self.titleLink = titleLink
        }
        
        self.titleLinkDownload = dict["title_link_download"].bool ?? true
        
        self.imageURL = dict["image_url"].string
        self.imageType = dict["image_type"].string
        self.imageSize = dict["image_size"].int ?? 0
        
        self.audioURL = dict["audio_url"].string
        self.audioType = dict["audio_type"].string
        self.audioSize = dict["audio_size"].int ?? 0
        
        self.videoURL = dict["video_url"].string
        self.videoType = dict["video_type"].string
        self.videoSize = dict["video_size"].int ?? 0
    }
}
{'fraction_non_alphanumeric': 0.09946236559139784, 'fraction_numerical': 0.010752688172043012, 'mean_word_length': 2.1235011990407675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5144979', 'n_tokens_mistral': 780, 'n_tokens_neox': 749, 'n_words': 217}