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