-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from yumemi-inc/feature/separate-type-definitions
型定義をファイル毎に分割しました。
- Loading branch information
Showing
12 changed files
with
146 additions
and
107 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Sources/YumemiWeather/InternalValueRepresentations/Area.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Area.swift | ||
// | ||
|
||
enum Area: String, CaseIterable, Codable { | ||
case sapporo = "Sapporo" | ||
case sendai = "Sendai" | ||
case niigata = "Niigata" | ||
case kanazawa = "Kanazawa" | ||
case tokyo = "Tokyo" | ||
case nagoya = "Nagoya" | ||
case osaka = "Osaka" | ||
case hiroshima = "Hiroshima" | ||
case kochi = "Kochi" | ||
case fukuoka = "Fukuoka" | ||
case kagoshima = "Kagoshima" | ||
case naha = "Naha" | ||
} |
10 changes: 10 additions & 0 deletions
10
Sources/YumemiWeather/InternalValueRepresentations/AreaRequest.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// AreaRequest.swift | ||
// | ||
|
||
import Foundation | ||
|
||
struct AreaRequest: Decodable { | ||
let areas: [String] | ||
let date: Date | ||
} |
8 changes: 8 additions & 0 deletions
8
Sources/YumemiWeather/InternalValueRepresentations/AreaResponse.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// AreaResponse.swift | ||
// | ||
|
||
struct AreaResponse: Codable { | ||
let area: Area | ||
let info: Response | ||
} |
10 changes: 10 additions & 0 deletions
10
Sources/YumemiWeather/InternalValueRepresentations/Request.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// Request.swift | ||
// | ||
|
||
import Foundation | ||
|
||
struct Request: Decodable { | ||
let area: String | ||
let date: Date | ||
} |
12 changes: 12 additions & 0 deletions
12
Sources/YumemiWeather/InternalValueRepresentations/Response.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Response.swift | ||
// | ||
|
||
import Foundation | ||
|
||
struct Response: Codable, Equatable { | ||
let weatherCondition: String | ||
let maxTemperature: Int | ||
let minTemperature: Int | ||
let date: Date | ||
} |
10 changes: 10 additions & 0 deletions
10
Sources/YumemiWeather/InternalValueRepresentations/WeatherCondition.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// WeatherCondition.swift | ||
// | ||
|
||
enum WeatherCondition: String, CaseIterable { | ||
case sunny | ||
case cloudy | ||
case rainy | ||
} | ||
|
File renamed without changes.
70 changes: 70 additions & 0 deletions
70
Sources/YumemiWeather/RandomizationFeatures/RandomResponse.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// RandomResponse.swift | ||
// | ||
// | ||
// Created by Tomohiro Kumagai on 2024/06/20. | ||
// | ||
|
||
import Foundation | ||
|
||
extension YumemiWeather { | ||
|
||
/// 引数の値でResponse構造体を作成する。引数がnilの場合はランダムに値を作成する。 | ||
/// - Parameters: | ||
/// - weatherCondition: 天気状況を表すenum | ||
/// - maxTemperature: 最高気温 | ||
/// - minTemperature: 最低気温 | ||
/// - date: 日付 | ||
/// - Returns: Response構造体 | ||
static func makeRandomResponse( | ||
weatherCondition: WeatherCondition? = nil, | ||
maxTemperature: Int? = nil, | ||
minTemperature: Int? = nil, | ||
date: Date? = nil | ||
) -> Response { | ||
return makeRandomResponse(using: &ControllableGenerator.shared, weatherCondition: weatherCondition, maxTemperature: maxTemperature, minTemperature: minTemperature) | ||
} | ||
|
||
/// 引数の値でResponse構造体を作成する。引数がnilの場合はランダムに値を作成する。 | ||
/// - Parameters: | ||
/// - weatherCondition: 天気状況を表すenum | ||
/// - maxTemperature: 最高気温 | ||
/// - minTemperature: 最低気温 | ||
/// - date: 日付 | ||
/// - Returns: Response構造体 | ||
static func makeRandomResponse( | ||
using generator: inout some RandomNumberGenerator, | ||
weatherCondition: WeatherCondition? = nil, | ||
maxTemperature: Int? = nil, | ||
minTemperature: Int? = nil, | ||
date: Date? = nil | ||
) -> Response { | ||
let weatherCondition = weatherCondition ?? .random(using: &generator) | ||
let maxTemperature = maxTemperature ?? .random(in: 10...40, using: &generator) | ||
let minTemperature = minTemperature ?? .random(in: -40..<maxTemperature, using: &generator) | ||
let date = date ?? Date() | ||
|
||
return Response( | ||
weatherCondition: weatherCondition.rawValue, | ||
maxTemperature: maxTemperature, | ||
minTemperature: minTemperature, | ||
date: date | ||
) | ||
} | ||
} | ||
|
||
extension WeatherCondition { | ||
|
||
/// 天候をランダムで取得します。 | ||
/// - Returns: なにかしらの天候を返します。 | ||
static func random() -> Self { | ||
random(using: &ControllableGenerator.shared) | ||
} | ||
|
||
/// 天候をランダムで取得します。 | ||
/// - Parameter generator: ランダムで取得するのに使う乱数生成期です。 | ||
/// - Returns: なにかしらの天候を返します。 | ||
static func random(using generator: inout some RandomNumberGenerator) -> Self { | ||
allCases.randomElement(using: &generator)! | ||
} | ||
} |
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// YumemiWeatherError.swift | ||
// | ||
|
||
public enum YumemiWeatherError: Error { | ||
case invalidParameterError | ||
case unknownError | ||
} |
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