Skip to content

Commit

Permalink
Migrating OSVer and SystemConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Jan 15, 2025
1 parent 2143561 commit 32a5cb9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
14 changes: 9 additions & 5 deletions Sources/BushelFoundation/PrereleaseLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ public struct PrereleaseLabel: Sendable {
/// The prerelease label.
public let label: String
private let baseNumber: Int
private let factor: Int

/// Initializes a new instance of `PrereleaseLabel`.
///
/// - Parameters:
/// - label: The prerelease label.
/// - baseNumber: The base number for the prerelease label.
public init(label: String, baseNumber: Int) {
public init(label: String, baseNumber: Int, factor: Int) {
self.label = label
self.baseNumber = baseNumber
self.factor = factor
}
}

Expand All @@ -53,6 +55,8 @@ extension PrereleaseLabel {
case label = "Label"
/// The key for the base number.
case base = "Base"
/// The key for the factor of the offset
case factor = "Factor"
}

/// Initializes a new instance of `PrereleaseLabel` from a dictionary.
Expand All @@ -73,7 +77,8 @@ extension PrereleaseLabel {
return nil
}
#endif
self.init(label: label, baseNumber: base)
let factor = dictionary[Keys.factor.rawValue] as? Int ?? 1
self.init(label: label, baseNumber: base, factor: factor)
}

/// Calculates the offset from the build number based on the prerelease label.
Expand All @@ -85,9 +90,8 @@ extension PrereleaseLabel {
/// - Returns: The calculated offset.
public func offset(
fromBuildNumber buildNumber: Int,
additionalOffset: Int,
factorOf factor: Int
additionalOffset: Int
) -> Int {
(buildNumber - self.baseNumber + additionalOffset) / factor
(buildNumber - self.baseNumber + additionalOffset) / self.factor
}
}
47 changes: 47 additions & 0 deletions Sources/BushelFoundation/SystemConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// SystemConfiguration.swift
// BushelKit
//
// Created by Leo Dion.
// Copyright © 2025 BrightDigit.
//
// 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.
//

public struct SystemConfiguration: Sendable, Codable, Equatable {
public let operatingSystemVersionString: String
public let physicalMemory: Int
public let processorCount: Int
public let activeProcessorCount: Int

public init(
operatingSystemVersionString: String,
physicalMemory: Int,
processorCount: Int,
activeProcessorCount: Int
) {
self.operatingSystemVersionString = operatingSystemVersionString
self.physicalMemory = physicalMemory
self.processorCount = processorCount
self.activeProcessorCount = activeProcessorCount
}
}
2 changes: 1 addition & 1 deletion Sources/BushelFoundation/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ extension Version {

return
// swiftlint:disable:next line_length
"\(self.marketingSemVer) \(prereleaseLabel.label) \(prereleaseLabel.offset(fromBuildNumber: self.buildNumber, additionalOffset: 1, factorOf: 2))"
"\(self.marketingSemVer) \(prereleaseLabel.label) \(prereleaseLabel.offset(fromBuildNumber: self.buildNumber, additionalOffset: 1))"
}

/// Creates a new `Version` instance by parsing a marketing version string, build number string,
Expand Down

0 comments on commit 32a5cb9

Please sign in to comment.