Update data documentation
This commit is contained in:
parent
50e30153bc
commit
ce65d545d0
|
@ -14,7 +14,19 @@ import Foundation
|
||||||
*/
|
*/
|
||||||
public protocol CsvParser {
|
public protocol CsvParser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Parse a CVS file with a certain name and extension in a
|
||||||
|
certain bundle.
|
||||||
|
|
||||||
|
The file content will be parsed line by line, splitting
|
||||||
|
each line using the provided `separator`.
|
||||||
|
*/
|
||||||
func parseCvsFile(named fileName: String, withExtension ext: String, in bundle: Bundle, separator: Character) throws -> [[String]]
|
func parseCvsFile(named fileName: String, withExtension ext: String, in bundle: Bundle, separator: Character) throws -> [[String]]
|
||||||
|
|
||||||
|
/**
|
||||||
|
Parse a CVS string line by line, splitting up each line
|
||||||
|
using the provided `separator`.
|
||||||
|
*/
|
||||||
func parseCvsString(_ string: String, separator: Character) -> [[String]]
|
func parseCvsString(_ string: String, separator: Character) -> [[String]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This struct lets you specify a list of available as well as
|
This struct lets you specify available and selected options
|
||||||
selected `FilterOption`s.
|
of a certain type.
|
||||||
*/
|
*/
|
||||||
public struct Filter<T: FilterOption>: Equatable {
|
public struct Filter<T: FilterOption>: Equatable {
|
||||||
|
|
||||||
|
@ -25,27 +25,27 @@ public struct Filter<T: FilterOption>: Equatable {
|
||||||
|
|
||||||
public extension Filter {
|
public extension Filter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Deselect a certain option.
|
||||||
|
*/
|
||||||
mutating func deselect(_ option: T) {
|
mutating func deselect(_ option: T) {
|
||||||
selected = selected.filter { $0 != option }
|
selected = selected.filter { $0 != option }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Select a certain option.
|
||||||
|
*/
|
||||||
mutating func select(_ option: T) {
|
mutating func select(_ option: T) {
|
||||||
selected = Array(Set(selected + [option]))
|
selected = Array(Set(selected + [option]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Whether or not the filter is identical to another value.
|
||||||
|
*/
|
||||||
func isIdentical(to filter: Filter<T>) -> Bool {
|
func isIdentical(to filter: Filter<T>) -> Bool {
|
||||||
isAvailableIdentical(to: filter) && isSelectedIdentical(to: filter)
|
let isAvailableIdentical = available.sorted() == filter.available.sorted()
|
||||||
}
|
let isSelectedIdentical = selected.sorted() == filter.selected.sorted()
|
||||||
}
|
return isAvailableIdentical && isSelectedIdentical
|
||||||
|
|
||||||
private extension Filter {
|
|
||||||
|
|
||||||
func isAvailableIdentical(to filter: Filter<T>) -> Bool {
|
|
||||||
available.sorted() == filter.available.sorted()
|
|
||||||
}
|
|
||||||
|
|
||||||
func isSelectedIdentical(to filter: Filter<T>) -> Bool {
|
|
||||||
selected.sorted() == filter.selected.sorted()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,13 @@ public class StandardCsvParser: CsvParser {
|
||||||
|
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
public func parseCvsString(
|
/**
|
||||||
_ string: String,
|
Parse a CVS file with a certain name and extension in a
|
||||||
separator: Character) -> [[String]] {
|
certain bundle.
|
||||||
let allRows = string.components(separatedBy: .newlines)
|
|
||||||
let rows = allRows.filter { $0.trimmingCharacters(in: .whitespaces).count > 0 }
|
|
||||||
return rows.map { $0.split(separator: separator).map { String($0) } }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
The file content will be parsed line by line, splitting
|
||||||
|
each line using the provided `separator`.
|
||||||
|
*/
|
||||||
public func parseCvsFile(
|
public func parseCvsFile(
|
||||||
named fileName: String,
|
named fileName: String,
|
||||||
withExtension ext: String,
|
withExtension ext: String,
|
||||||
|
@ -31,4 +30,16 @@ public class StandardCsvParser: CsvParser {
|
||||||
guard let string = try? String(contentsOfFile: path, encoding: .utf8) else { throw invalidData }
|
guard let string = try? String(contentsOfFile: path, encoding: .utf8) else { throw invalidData }
|
||||||
return parseCvsString(string, separator: separator)
|
return parseCvsString(string, separator: separator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Parse a CVS string line by line, splitting up each line
|
||||||
|
using the provided `separator`.
|
||||||
|
*/
|
||||||
|
public func parseCvsString(
|
||||||
|
_ string: String,
|
||||||
|
separator: Character) -> [[String]] {
|
||||||
|
let allRows = string.components(separatedBy: .newlines)
|
||||||
|
let rows = allRows.filter { $0.trimmingCharacters(in: .whitespaces).count > 0 }
|
||||||
|
return rows.map { $0.split(separator: separator).map { String($0) } }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,8 @@ import Foundation
|
||||||
*/
|
*/
|
||||||
public protocol StringDecoder: AnyObject {
|
public protocol StringDecoder: AnyObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Decode a string to another string.
|
||||||
|
*/
|
||||||
func decode(_ string: String) -> String?
|
func decode(_ string: String) -> String?
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,8 @@ import Foundation
|
||||||
*/
|
*/
|
||||||
public protocol StringEncoder: AnyObject {
|
public protocol StringEncoder: AnyObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Encode a string to something else.
|
||||||
|
*/
|
||||||
func encode(_ string: String) -> String?
|
func encode(_ string: String) -> String?
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue