Skip to content

Instantly share code, notes, and snippets.

@soxjke
Created October 26, 2017 15:45
Show Gist options
  • Select an option

  • Save soxjke/62cf5180467578b3cd9c84b634785b37 to your computer and use it in GitHub Desktop.

Select an option

Save soxjke/62cf5180467578b3cd9c84b634785b37 to your computer and use it in GitHub Desktop.
Weather - ImmutableMappable
extension Weather: ImmutableMappable {
init(map: Map) throws {
effectiveDate = try map.value("EpochDate", using: DateTransform())
temperature = try map.value("Temperature")
realFeel = try map.value("RealFeelTemperature")
day = try map.value("Day")
night = try map.value("Night")
}
func mapping(map: Map) {
}
}
extension WeatherFeature: ImmutableMappable {
init(map: Map) throws {
if let minimum: T = try? map.value("Minimum.Value"),
let maximum: T = try? map.value("Maximum.Value") { // Min/max
unit = try map.value("Minimum.Unit")
value = .minmax(min: minimum, max: maximum)
}
else { // Single value
unit = try map.value("Unit")
value = .single(value: try map.value("Value"))
}
}
func mapping(map: Map) {
}
}
extension DayNightWeather: ImmutableMappable {
init(map: Map) throws {
windSpeed = try map.value("Wind.Speed")
windDirection = (try? map.value("Wind.Direction.Localized")) ?? ((try? map.value("Wind.Direction.English")) ?? "")
precipitationProbability = try map.value("PrecipitationProbability")
phrase = try map.value("LongPhrase")
icon = try map.value("Icon")
}
func mapping(map: Map) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment