//
//  Track.swift
//  TapALap
//
//  Created by Jeff Kelley on 4/27/15.
//  Copyright (c) 2015 Pragmatic Bookshelf. All rights reserved.
//

import Foundation

struct Track {
    let name: String
    let lapDistance: Double // in meters
    
    init?(dictionary: [NSObject: AnyObject]) {
        if let name = dictionary["name"] as? String,
            lapDistance = dictionary["lapDistance"] as? Double {
            self.name = name
            self.lapDistance = lapDistance
        }
        else {
            return nil
        }
    }
    
    init(name: String, lapDistance: Double) {
        self.name = name
        self.lapDistance = lapDistance
    }
    
    func dictionaryRepresentation() -> [NSObject: AnyObject] {
        return ["name": name, "lapDistance": lapDistance]
    }
}
