diff --git a/Package.swift b/Package.swift index 6c47e5d..b5454b5 100644 --- a/Package.swift +++ b/Package.swift @@ -4,7 +4,7 @@ import PackageDescription let package = Package( - name: "MetobsKit", + name: "Forecast", platforms: [ .macOS(.v10_15), .iOS(.v13), @@ -14,8 +14,8 @@ let package = Package( products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( - name: "MetobsKit", - targets: ["MetobsKit"]), + name: "Forecast", + targets: ["Forecast"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -25,10 +25,10 @@ let package = Package( // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( - name: "MetobsKit", + name: "Forecast", dependencies: []), .testTarget( - name: "MetobsKitTests", - dependencies: ["MetobsKit"]), + name: "ForecastTests", + dependencies: ["Forecast"]), ] ) diff --git a/README.md b/README.md index b323f44..687b00a 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ -# MetobsKit +# Forecast This package is a wrapper for the PMP3g API provided by [SMHI](https://smhi.se). ### Usage -Add MetobsKit to your `Package.swift` manifest. +Add Forecast to your `Package.swift` manifest. ```swift ... /// Append the package to the list of dependencies dependencies: [ - .package(url: "https://github.com/devmaximilian/MetobsKit.git", from: "0.4.0") + .package(url: "https://github.com/devmaximilian/Forecast.git", from: "1.0.0") ], /// Append the library to the list of target dependencies targets: [ .target( name: "MyProject", - dependencies: ["MetobsKit"]) + dependencies: ["Forecast"]) ] ... ``` diff --git a/Sources/MetobsKit/ForecastPublisher.swift b/Sources/Forecast/ForecastPublisher.swift similarity index 92% rename from Sources/MetobsKit/ForecastPublisher.swift rename to Sources/Forecast/ForecastPublisher.swift index 390dbbc..c03822b 100644 --- a/Sources/MetobsKit/ForecastPublisher.swift +++ b/Sources/Forecast/ForecastPublisher.swift @@ -1,5 +1,5 @@ // -// Service.swift +// ForecastPublisher.swift // // Copyright (c) 2019 Maximilian Wendel // @@ -29,6 +29,7 @@ import class Foundation.URLSession import struct Foundation.URLError import struct Foundation.Data import struct Foundation.URL +import func Foundation.pow import protocol Combine.Publisher import protocol Combine.Subscriber import class Combine.PassthroughSubject @@ -173,3 +174,14 @@ extension JSONDecoder { self.dateDecodingStrategy = dateDecodingStrategy } } + +/// An extension to add the rounded method +extension Double { + /// Rounds the `Double` to a specified precision-level (number of decimals) + /// - Note: This method is present as the forecast service only accepts a maximum of six decimals + /// - Parameter precision: The precision-level to use + fileprivate func rounded(toPrecision precision: Int) -> Double { + let multiplier: Double = pow(10, Double(precision)) + return (self * multiplier).rounded() / multiplier + } +} diff --git a/Sources/MetobsKit/Models/Forecast.swift b/Sources/Forecast/Models/Forecast.swift similarity index 94% rename from Sources/MetobsKit/Models/Forecast.swift rename to Sources/Forecast/Models/Forecast.swift index 88b35bc..0ba7af1 100644 --- a/Sources/MetobsKit/Models/Forecast.swift +++ b/Sources/Forecast/Models/Forecast.swift @@ -24,6 +24,7 @@ import struct Foundation.Date + /// A `Forecast` is a collection of `Value`s for a set of `Parameter`s public struct Forecast: Codable { /// A timestamp for when the `Forecast` is valid @@ -40,6 +41,8 @@ public struct Forecast: Codable { } ?? .unknown } + /// Get `Value` for a `Parameter` + /// - Parameter parameter: The `Parameter` to get `Value` for public subscript(parameter: Parameter) -> Value { return self.parameters.first { (value) -> Bool in value.name == parameter diff --git a/Sources/MetobsKit/Models/Geometry.swift b/Sources/Forecast/Models/Geometry.swift similarity index 100% rename from Sources/MetobsKit/Models/Geometry.swift rename to Sources/Forecast/Models/Geometry.swift diff --git a/Sources/MetobsKit/Models/Level.swift b/Sources/Forecast/Models/Level.swift similarity index 100% rename from Sources/MetobsKit/Models/Level.swift rename to Sources/Forecast/Models/Level.swift diff --git a/Sources/MetobsKit/Models/Observation.swift b/Sources/Forecast/Models/Observation.swift similarity index 99% rename from Sources/MetobsKit/Models/Observation.swift rename to Sources/Forecast/Models/Observation.swift index b241d13..ac9ab89 100644 --- a/Sources/MetobsKit/Models/Observation.swift +++ b/Sources/Forecast/Models/Observation.swift @@ -24,6 +24,7 @@ import struct Foundation.Date + /// An `Observation` is a collection of `Forecast` instances public struct Observation: Codable { /// A timestamp for when the `Forecast` was approved diff --git a/Sources/MetobsKit/Models/Parameter.swift b/Sources/Forecast/Models/Parameter.swift similarity index 100% rename from Sources/MetobsKit/Models/Parameter.swift rename to Sources/Forecast/Models/Parameter.swift diff --git a/Sources/MetobsKit/Models/Value.swift b/Sources/Forecast/Models/Value.swift similarity index 100% rename from Sources/MetobsKit/Models/Value.swift rename to Sources/Forecast/Models/Value.swift diff --git a/Sources/MetobsKit/Utils.swift b/Sources/MetobsKit/Utils.swift deleted file mode 100644 index 98aaa3f..0000000 --- a/Sources/MetobsKit/Utils.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// Utils.swift -// -// Copyright (c) 2019 Maximilian Wendel -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the Software), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -import func Foundation.pow - -/// An extension to add the rounded method -extension Double { - /// Rounds the `Double` to a specified precision-level (number of decimals) - /// - Note: This method is present as the forecast service only accepts a maximum of six decimals - /// - Parameter precision: The precision-level to use - func rounded(toPrecision precision: Int) -> Double { - let multiplier: Double = pow(10, Double(precision)) - return (self * multiplier).rounded() / multiplier - } -} diff --git a/Tests/MetobsKitTests/ForecastPublisherTests.swift b/Tests/ForecastTests/ForecastPublisherTests.swift similarity index 98% rename from Tests/MetobsKitTests/ForecastPublisherTests.swift rename to Tests/ForecastTests/ForecastPublisherTests.swift index 754041b..a4fd4bd 100644 --- a/Tests/MetobsKitTests/ForecastPublisherTests.swift +++ b/Tests/ForecastTests/ForecastPublisherTests.swift @@ -1,5 +1,5 @@ import Foundation -import MetobsKit +import Forecast import XCTest import Combine diff --git a/Tests/MetobsKitTests/XCTestManifests.swift b/Tests/ForecastTests/XCTestManifests.swift similarity index 100% rename from Tests/MetobsKitTests/XCTestManifests.swift rename to Tests/ForecastTests/XCTestManifests.swift diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 38748bd..dda336e 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -1,7 +1,7 @@ import XCTest -import MetobsKitTests +import ForecastTests var tests = [XCTestCaseEntry]() -tests += MetobsKitTests.allTests() +tests += ForecastTests.allTests() XCTMain(tests)