mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-26 02:01:00 +00:00
28 lines
621 B
Swift
28 lines
621 B
Swift
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
struct AttachmentViewModel {
|
|
let attachment: Attachment
|
|
|
|
init(attachment: Attachment) {
|
|
self.attachment = attachment
|
|
}
|
|
}
|
|
|
|
extension AttachmentViewModel {
|
|
var aspectRatio: Double? {
|
|
if
|
|
let info = attachment.meta?.original,
|
|
let width = info.width,
|
|
let height = info.height,
|
|
width != 0,
|
|
height != 0 {
|
|
let aspectRatio = Double(width) / Double(height)
|
|
|
|
return aspectRatio.isNaN ? nil : aspectRatio
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|