BasalProfileEntry.swift 803 B

1234567891011121314151617181920212223242526272829
  1. import Foundation
  2. struct BasalProfileEntry: JSON, Equatable {
  3. let start: String
  4. let minutes: Int
  5. let rate: Decimal
  6. }
  7. protocol BasalProfileObserver {
  8. func basalProfileDidChange(_ basalProfile: [BasalProfileEntry])
  9. }
  10. extension BasalProfileEntry {
  11. private enum CodingKeys: String, CodingKey {
  12. case start
  13. case minutes
  14. case rate
  15. }
  16. init(from decoder: Decoder) throws {
  17. let container = try decoder.container(keyedBy: CodingKeys.self)
  18. let start = try container.decode(String.self, forKey: .start)
  19. let minutes = try container.decode(Int.self, forKey: .minutes)
  20. let rate = try container.decode(Double.self, forKey: .rate).decimal ?? .zero
  21. self = BasalProfileEntry(start: start, minutes: minutes, rate: rate)
  22. }
  23. }