// LoopFollow
// InsulinMetric.swift

import Foundation

class InsulinMetric: Metric {
    init?(from dictionary: [String: AnyObject], key: String) {
        guard let value = dictionary[key] as? Double else {
            return nil
        }
        super.init(value: value, maxFractionDigits: 2, minFractionDigits: 0)
    }

    init?(from object: AnyObject?, key: String) {
        guard let dictionary = object as? [String: AnyObject], let value = dictionary[key] as? Double else {
            return nil
        }
        super.init(value: value, maxFractionDigits: 2, minFractionDigits: 0)
    }

    override func formattedValue() -> String {
        let decimals = abs(value) >= 10 ? 0 : 1
        return Localizer.formatToLocalizedString(value, maxFractionDigits: decimals, minFractionDigits: 0)
    }
}
