<commit_before>//
//  HNParseConfig.swift
//  HackerNews2
//
//  Created by <NAME> on 8/09/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation


/**
 Manage to download, store and cache the json file
 used to parse the pages of the website.
 */
class HNParseConfig {
    private let savingKey = "HNParseConfig"
    private let url = "http://localhost:8000/hn.json"
    private var _config: [String: Any]? = nil
    private init() {}
    public static let shared = HNParseConfig()
    
    /// Returns the data if in cache (if not it returns
    /// nil, you need to call getDictionnary to fetch the file)
    public var data:[String: Any]? {
        get {
            if (_config == nil) {
                _config = cacheData
            }
            return _config
        }
    }
    /// Looks for the data in local storage
    private var cacheData: [String: Any]? {
        get {
            let defaults = UserDefaults.standard
            if defaults.object(forKey: self.savingKey) != nil {
                return (defaults.object(forKey: self.savingKey) as! [String: Any])
            } else {
                return nil
            }
        }
    }
    /**<commit_msg>update hn.json path<commit_after>//
//  HNParseConfig.swift
//  HackerNews2
//
//  Created by <NAME> on 8/09/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation


/**
 Manage to download, store and cache the json file
 used to parse the pages of the website.
 */
class HNParseConfig {
    private let savingKey = "HNParseConfig"
    private let url = "https://raw.githubusercontent.com/tsucres/HNScraper/master/hn.json"
    private var _config: [String: Any]? = nil
    private init() {}
    public static let shared = HNParseConfig()
    
    /// Returns the data if in cache (if not it returns
    /// nil, you need to call getDictionnary to fetch the file)
    public var data:[String: Any]? {
        get {
            if (_config == nil) {
                _config = cacheData
            }
            return _config
        }
    }
    /// Looks for the data in local storage
    private var cacheData: [String: Any]? {
        get {
            let defaults = UserDefaults.standard
            if defaults.object(forKey: self.savingKey) != nil {
                return (defaults.object(forKey: self.savingKey) as! [String: Any])
            } else {
                return nil
            }
        }
    }
    /**
{'fraction_non_alphanumeric': 0.10420923579893747, 'fraction_numerical': 0.009807928075194115, 'mean_word_length': 1.843205574912892, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7434060', 'n_tokens_mistral': 733, 'n_tokens_neox': 688, 'n_words': 238}