CorrectionRangeOverrides.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // CorrectionRangeOverrides.swift
  3. // LoopKit
  4. //
  5. // Created by Rick Pasetto on 7/14/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import HealthKit
  9. import Foundation
  10. public struct CorrectionRangeOverrides: Equatable {
  11. public enum Preset: Hashable, CaseIterable {
  12. case preMeal
  13. case workout
  14. }
  15. public var ranges: [Preset: ClosedRange<HKQuantity>]
  16. public init(preMeal: DoubleRange?, workout: DoubleRange?, unit: HKUnit) {
  17. ranges = [:]
  18. ranges[.preMeal] = preMeal?.quantityRange(for: unit)
  19. ranges[.workout] = workout?.quantityRange(for: unit)
  20. }
  21. public var preMeal: ClosedRange<HKQuantity>? { ranges[.preMeal] }
  22. public var workout: ClosedRange<HKQuantity>? { ranges[.workout] }
  23. }
  24. public extension CorrectionRangeOverrides.Preset {
  25. var title: String {
  26. switch self {
  27. case .preMeal:
  28. return LocalizedString("Pre-Meal", comment: "Title for pre-meal mode")
  29. case .workout:
  30. return LocalizedString("Workout", comment: "Title for workout mode")
  31. }
  32. }
  33. var therapySetting: TherapySetting {
  34. switch self {
  35. case .preMeal: return .preMealCorrectionRangeOverride
  36. case .workout: return .workoutCorrectionRangeOverride
  37. }
  38. }
  39. }