-
-
Save fitomad/5b71e97eb09b6638f55e9d91ec894c43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func reportToList(_ stations: [StationRecord]) -> String? | |
{ | |
guard let mainTemplate = self.loadTemplate(ofType: .list), | |
let rowTemplate = self.loadTemplate(ofType: .listRow) | |
else | |
{ | |
return nil | |
} | |
let rows = stations | |
.map({ | |
var ocuppation_style = "" | |
switch $0.occupation | |
{ | |
case .low: | |
ocuppation_style = "low-occupation" | |
case .medium: | |
ocuppation_style = "middle-occupation" | |
case .high: | |
ocuppation_style = "high-occupation" | |
case .unavailable: | |
ocuppation_style = "offline-occupation" | |
} | |
let row = String(format: rowTemplate, ocuppation_style, "\($0.name)", "\($0.bikes)", "\($0.docks)") | |
return row | |
}) | |
.reduce("") { $0 + $1 } | |
let content = String(format: mainTemplate, rows) | |
return content | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment