<commit_before>//
//  MenuItemsPlistReader.swift
//  AppMenu
//
//  Created by KazuakiMATSUO on 1/2/15.
//  Copyright (c) 2015 KazuakiMATSUO. All rights reserved.
//

import Foundation

let MenuItemsPlistReaderErrorDomain = "MenuItemsPlistReaderErrorDomain"

enum MenuItemsPlistReaderErrorCode : Int {
    case FileNotFound
}

class MenuItemsPlistReader: MenuItemsReader {
    var plistToReadFrom: String? = nil
    
    func readMenuItems() -> ([[String : String]]?, NSError?) {
        var error: NSError? = nil
        var fileContents: [[String : String]]? = nil
        let bundle = NSBundle(forClass: object_getClass(self))
        
        if let filePath = bundle.pathForResource(plistToReadFrom, ofType: "plist") {
            fileContents = NSArray(contentsOfFile: filePath) as? [[String : String]]
        } else {
            let errorMessage = "\(plistToReadFrom!).plist file doesn't exist in app bundle"
            let userInfo = [NSLocalizedDescriptionKey: errorMessage]
            error = NSError(domain: MenuItemsPlistReaderErrorDomain,
                code: MenuItemsPlistReaderErrorCode.FileNotFound.rawValue,
                userInfo: userInfo)
        }
        
        return (fileContents, error)
    }
}<commit_msg>refactor fileNotFoundError<commit_after>//
//  MenuItemsPlistReader.swift
//  AppMenu
//
//  Created by KazuakiMATSUO on 1/2/15.
//  Copyright (c) 2015 KazuakiMATSUO. All rights reserved.
//

import Foundation

let MenuItemsPlistReaderErrorDomain = "MenuItemsPlistReaderErrorDomain"

enum MenuItemsPlistReaderErrorCode : Int {
    case FileNotFound
}

class MenuItemsPlistReader: MenuItemsReader {
    var plistToReadFrom: String? = nil
    
    func readMenuItems() -> ([[String : String]]?, NSError?) {
        var error: NSError? = nil
        var fileContents: [[String : String]]? = nil
        let bundle = NSBundle(forClass: object_getClass(self))
        
        if let filePath = bundle.pathForResource(plistToReadFrom, ofType: "plist") {
            fileContents = NSArray(contentsOfFile: filePath) as? [[String : String]]
        } else {
            error = fileNotFoundError()
        }
        
        return (fileContents, error)
    }
    
    func fileNotFoundError() -> NSError {
        let errorMessage = "\(plistToReadFrom!).plist file doesn't exist in app bundle"
        let userInfo = [NSLocalizedDescriptionKey: errorMessage]
        return NSError(domain: MenuItemsPlistReaderErrorDomain,
            code: MenuItemsPlistReaderErrorCode.FileNotFound.rawValue,
            userInfo: userInfo)
    }
}
{'fraction_non_alphanumeric': 0.09497859089139743, 'fraction_numerical': 0.006228104320747372, 'mean_word_length': 2.858858858858859, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2481802', 'n_tokens_mistral': 768, 'n_tokens_neox': 737, 'n_words': 178}