<commit_before>//
//  ProgressObserver.swift
//  ProgressObserver
//
//  Created by <NAME> on 09/08/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

/// A simple `NSProgress` subclass that provides a clean delegate based interface to observing progress values.
public class ProgressObserver: NSProgress {
    
    /**
     The delegate for the progress observer. It should conform to the `ProgressObserverDelegate` protocol
     */
    public var delegate: ProgressObserverDelegate? {
        didSet {
            if delegate == nil {
                stopObservingProgress()
            }
            else {
                startObservingProgress()
            }
        }
    }
    var isObserving = false
    
    func startObservingProgress() {
        guard isObserving == false else {
            return
        }
        
        self.addObserver(self,
                         forKeyPath: "fractionCompleted",
                         options: [],
                         context: nil)
        self.addObserver(self,
                         forKeyPath: "completedUnitCount",
                         options: [],
                         context: nil)
        isObserving = true
    }
    
    func stopObservingProgress() {
        guard isObserving == true else {
            return
        }<commit_msg>added convenience initialisers because apple is annoying<commit_after>//
//  ProgressObserver.swift
//  ProgressObserver
//
//  Created by <NAME> on 09/08/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

/// A simple `NSProgress` subclass that provides a clean delegate based interface to observing progress values.
public class ProgressObserver: NSProgress {
    
    /**
     The delegate for the progress observer. It should conform to the `ProgressObserverDelegate` protocol
     */
    public var delegate: ProgressObserverDelegate? {
        didSet {
            if delegate == nil {
                stopObservingProgress()
            }
            else {
                startObservingProgress()
            }
        }
    }
    var isObserving = false
    
    /**
     Please refer to the `NSProgress` docs for this initialiser
     */
    convenience init(totalUnitCount unitCount: Int64) {
        self.init(parent: nil, userInfo: nil)
        totalUnitCount = unitCount
    }
    
    /**
     Please refer to the `NSProgress` docs for this initialiser
     */
    convenience init(totalUnitCount unitCount: Int64,
                        parent: NSProgress,
                        pendingUnitCount portionOfParentTotalUnitCount: Int64) {
        self.init(parent: nil, userInfo: nil)
        parent.addChild(self, withPendingUnitCount: portionOfParentTotalUnitCount)
        totalUnitCount = unitCount
    }
        
    func startObservingProgress() {
        guard isObserving == false else {
            return
        }
        
        self.addObserver(self,
                         forKeyPath: "fractionCompleted",
                         options: [],
                         context: nil)
        self.addObserver(self,
                         forKeyPath: "completedUnitCount",
                         options: [],
                         context: nil)
        isObserving = true
    }
    
    func stopObservingProgress() {
        guard isObserving == true else {
            return
        }
{'fraction_non_alphanumeric': 0.0744336569579288, 'fraction_numerical': 0.0088261253309797, 'mean_word_length': 1.6033690658499233, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5145515', 'n_tokens_mistral': 841, 'n_tokens_neox': 790, 'n_words': 234}