-
Notifications
You must be signed in to change notification settings - Fork 780
/
BorderSide.swift
executable file
·63 lines (50 loc) · 1.39 KB
/
BorderSide.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// Created by Jake Lin on 12/9/15.
// Copyright © 2015 IBAnimatable. All rights reserved.
//
import Foundation
public enum BorderSide: String {
case top
case right
case bottom
case left
}
public struct BorderSides: OptionSet {
public let rawValue: Int
public static let unknown = BorderSides([])
public static let top = BorderSides(rawValue: 1)
public static let right = BorderSides(rawValue: 1 << 1)
public static let bottom = BorderSides(rawValue: 1 << 2)
public static let left = BorderSides(rawValue: 1 << 3)
public static let AllSides: BorderSides = [.top, .right, .bottom, .left]
public init(rawValue: Int) {
self.rawValue = rawValue
}
init(rawValue: String?) {
guard let rawValue = rawValue, !rawValue.isEmpty else {
self = .AllSides
return
}
let sideElements = rawValue.lowercased().split(separator: ",")
.map(String.init)
.map { BorderSide(rawValue: $0.trimmingCharacters(in: CharacterSet.whitespaces)) }
.map { BorderSides(side: $0) }
guard !sideElements.contains(.unknown) else {
self = .AllSides
return
}
self = BorderSides(sideElements)
}
init(side: BorderSide?) {
guard let side = side else {
self = .unknown
return
}
switch side {
case .top: self = .top
case .right: self = .right
case .bottom: self = .bottom
case .left: self = .left
}
}
}