<commit_before>//
//  SwiftyNURE+JSONProtocols.swift
//  SwiftyNURE
//
//  Created by <NAME> on 02.03.16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

extension Group: JSONObject {

    public func toJSON() -> JSON {
        let jsonDict: [String: AnyObject] = [
            "id": id,
            "name": name
        ]
        return jsonDict
    }

    public init?(withJSON json: JSON) {
        guard let id = json["id"] as? Int,
            name = json["name"] as? String
            else { return nil }
        self.init(name: name, id: id)
    }

}

extension Subject: JSONObject {

    public func toJSON() -> JSON {
        let jsonDict: JSON = [
            "id": id,
            "name": name,
            "short_name": shortName
        ]
        return jsonDict
    }

    public init?(withJSON json: JSON) {
        guard let id = json["id"] as? Int,
            name = json["name"] as? String,
            shortName = json["short_name"] as? String
            else { return nil }
        self.init(name: name, shortName: shortName, id: id)
    }

}

extension Teacher: JSONObject {

    public func toJSON() -> JSON {
        let jsonDict: JSON = [
            "id": id,
            "full_name": fullName,
            "short_name": shortName
        ]
        return jsonDict
    }

    public init?(withJSON json: JSON) {
        guard let id = json["id"] as? Int,
            fullName = json["full_name"] as? String,
            shortName = json["short_name"] as? String
            else { return nil }
        self.init(fullName: fullName, shortName: shortName, id: id)
    }

}

extension Teacher.Extended: JSONObject {

    public func toJSON() -> JSON {
        var jsonDict = self.teacher.toJSON()
        jsonDict["faculty_full_name"] = faculty.full
        jsonDict["faculty_short_name"] = faculty.short
        jsonDict["department_full_name"] = department.full
        jsonDict["department_short_name"] = department.short
        return jsonDict
    }

    public init?(withJSON json: JSON) {
        guard let teacher = Teacher(withJSON: json),
            facultyFull = json["faculty_full_name"] as? String,
            facultyShort = json["faculty_short_name"] as? String,
            departmentFull = json["department_full_name"] as? String,
            departmentShort = json["department_short_name"] as? String
            else { return nil }
        let facultyName = FacultyName(full: facultyFull, short: facultyShort)
        let departmentName = DepartmentName(full: departmentFull, short: departmentShort)
        self.init(teacher: teacher, department: departmentName, faculty: facultyName)
    }
<commit_msg>Minor fixes.<commit_after>//
//  SwiftyNURE+JSONProtocols.swift
//  SwiftyNURE
//
//  Created by <NAME> on 02.03.16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

extension Group: JSONObject {

    public func toJSON() -> JSON {
        let jsonDict: [String: AnyObject] = [
            "id": id,
            "name": name
        ]
        return jsonDict
    }

    public init?(withJSON json: JSON) {
        guard let id = json["id"] as? Int,
            name = json["name"] as? String
            else { return nil }
        self.init(name: name, id: id)
    }

}

extension Subject: JSONObject {

    public func toJSON() -> JSON {
        let subjectJsonDict: JSON = [
            "id": id,
            "name": name,
            "short_name": shortName
        ]
        return subjectJsonDict
    }

    public init?(withJSON json: JSON) {
        guard let subjectId = json["id"] as? Int,
            name = json["name"] as? String,
            shortName = json["short_name"] as? String
            else { return nil }
        self.init(name: name, shortName: shortName, id: subjectId)
    }

}

extension Teacher: JSONObject {

    public func toJSON() -> JSON {
        let jsonDict: JSON = [
            "id": id,
            "full_name": fullName,
            "short_name": shortName
        ]
        return jsonDict
    }

    public init?(withJSON json: JSON) {
        guard let teacherId = json["id"] as? Int,
            fullName = json["full_name"] as? String,
            shortName = json["short_name"] as? String
            else { return nil }
        self.init(fullName: fullName, shortName: shortName, id: teacherId)
    }

}

extension Teacher.Extended: JSONObject {

    public func toJSON() -> JSON {
        var jsonDict = self.teacher.toJSON()
        jsonDict["faculty_full_name"] = faculty.full
        jsonDict["faculty_short_name"] = faculty.short
        jsonDict["department_full_name"] = department.full
        jsonDict["department_short_name"] = department.short
        return jsonDict
    }

    public init?(withJSON json: JSON) {
        guard let teacher = Teacher(withJSON: json),
            facultyFull = json["faculty_full_name"] as? String,
            facultyShort = json["faculty_short_name"] as? String,
            departmentFull = json["department_full_name"] as? String,
            departmentShort = json["department_short_name"] as? String
            else { return nil }
        let facultyName = FacultyName(full: facultyFull, short: facultyShort)
        let departmentName = DepartmentName(full: departmentFull, short: departmentShort)
        self.init(teacher: teacher, department: departmentName, faculty: facultyName)
    }

{'fraction_non_alphanumeric': 0.11041009463722397, 'fraction_numerical': 0.0037112636852848395, 'mean_word_length': 2.157586408904511, 'pattern_counts': {'":': 16, '<': 7, '<?xml version=': 0, '>': 15, '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': '7236667', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1542, 'n_words': 423}