Separate parser and helpers from Password class for better testability
This commit is contained in:
parent
2abbceb2e9
commit
7c12263458
17 changed files with 913 additions and 537 deletions
47
passKit/Parser/AdditionField.swift
Normal file
47
passKit/Parser/AdditionField.swift
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
//
|
||||
// AdditionField.swift
|
||||
// passKit
|
||||
//
|
||||
// Created by Danny Moesch on 30.09.18.
|
||||
// Copyright © 2018 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
public struct AdditionField: Hashable {
|
||||
|
||||
public let title: String, content: String
|
||||
|
||||
var asString: String {
|
||||
return title.isEmpty ? content : title + ": " + content
|
||||
}
|
||||
|
||||
var asTuple: (String, String) {
|
||||
return (title, content)
|
||||
}
|
||||
}
|
||||
|
||||
extension AdditionField {
|
||||
|
||||
static func | (left: String, right: AdditionField) -> String {
|
||||
return left | right.asString
|
||||
}
|
||||
|
||||
static func | (left: AdditionField, right: String) -> String {
|
||||
return left.asString | right
|
||||
}
|
||||
|
||||
static func | (left: AdditionField, right: AdditionField) -> String {
|
||||
return left.asString | right
|
||||
}
|
||||
}
|
||||
|
||||
extension AdditionField: Equatable {
|
||||
|
||||
public static func == (first: AdditionField, second: AdditionField) -> Bool {
|
||||
return first.asTuple == second.asTuple
|
||||
}
|
||||
}
|
||||
|
||||
infix operator =>: MultiplicationPrecedence
|
||||
func => (key: String, value: String) -> AdditionField {
|
||||
return AdditionField(title: key, content: value)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue