<commit_before>
//
//  URBNValidatorCompat.swift
//  URBNValidator
//
//  Created by <NAME> on 12/21/15.
//
//

import Foundation


@objc public protocol CompatValidator {
    var localizationBundle: NSBundle { get }

    func validate(key: String?, value: AnyObject?, rule: URBNCompatBaseRule) throws
    func validate(item: CompatValidateable , stopOnFirstError: Bool) throws
}

@objc public protocol CompatValidateable {
    func validationMap() -> [String: CompatValidatingValue]
}

extension CompatValidateable {
    func backingValidationMap() -> [String: ValidatingValue<AnyObject>] {
        return validationMap().reduce([String: ValidatingValue<AnyObject>]()) { (var dict, items: (key: String, value: CompatValidatingValue)) -> [String: ValidatingValue<AnyObject>] in
            dict[items.key] = items.value.backingRules()
            return dict
        }
    }
}

@objc public class URBNCompatValidator: NSObject, CompatValidator {
    private let backingValidator: URBNValidator = URBNValidator()
    
    public var localizationBundle: NSBundle {
        return backingValidator.localizationBundle
    }
    
    public func validate(key: String?, value: AnyObject?, rule: URBNCompatBaseRule) throws {
        try backingValidator.validate(key, value: value, rule: rule.backingRule)
    }
    
    public func validate(item: CompatValidateable , stopOnFirstError: Bool) throws {
        try backingValidator.validate(ConvertCompat(cv: item), stopOnFirstError: stopOnFirstError)
    }
}

class ConvertCompat: Validateable {
    typealias V = AnyObject
    var rules = [String: ValidatingValue<V>]()
    
    init(cv: CompatValidateable) {
        rules = cv.backingValidationMap()
    }
    <commit_msg>Allow setting of localizationBundle in compat<commit_after>
//
//  URBNValidatorCompat.swift
//  URBNValidator
//
//  Created by <NAME> on 12/21/15.
//
//

import Foundation


@objc public protocol CompatValidator {
    var localizationBundle: NSBundle { get }

    func validate(key: String?, value: AnyObject?, rule: URBNCompatBaseRule) throws
    func validate(item: CompatValidateable , stopOnFirstError: Bool) throws
}

@objc public protocol CompatValidateable {
    func validationMap() -> [String: CompatValidatingValue]
}

extension CompatValidateable {
    func backingValidationMap() -> [String: ValidatingValue<AnyObject>] {
        return validationMap().reduce([String: ValidatingValue<AnyObject>]()) { (var dict, items: (key: String, value: CompatValidatingValue)) -> [String: ValidatingValue<AnyObject>] in
            dict[items.key] = items.value.backingRules()
            return dict
        }
    }
}

@objc public class URBNCompatValidator: NSObject, CompatValidator {
    private let backingValidator: URBNValidator = URBNValidator()
    
    public var localizationBundle: NSBundle {
        get {
            return backingValidator.localizationBundle
        }
        set {
            backingValidator.localizationBundle = newValue
        }
    }
    
    public func validate(key: String?, value: AnyObject?, rule: URBNCompatBaseRule) throws {
        try backingValidator.validate(key, value: value, rule: rule.backingRule)
    }
    
    public func validate(item: CompatValidateable , stopOnFirstError: Bool) throws {
        try backingValidator.validate(ConvertCompat(cv: item), stopOnFirstError: stopOnFirstError)
    }
}

class ConvertCompat: Validateable {
    typealias V = AnyObject
    var rules = [String: ValidatingValue<V>]()
    
    init(cv: CompatValidateable) {
        rules = cv.backingValidationMap()
    }
    
{'fraction_non_alphanumeric': 0.0972338642078793, 'fraction_numerical': 0.003352891869237217, 'mean_word_length': 3.4974874371859297, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '1447468', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1006, 'n_words': 251}