Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created September 2, 2018 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/5b71e97eb09b6638f55e9d91ec894c43 to your computer and use it in GitHub Desktop.
Save fitomad/5b71e97eb09b6638f55e9d91ec894c43 to your computer and use it in GitHub Desktop.
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