<commit_before>//
//  Story.swift
//  TopStories
//
//  Created by <NAME> on 20/04/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import CoreData

class Story: NSManagedObject {

    class func fetchRequest() -> NSFetchRequest {
        
        let fetchRequest = NSFetchRequest(entityName: String(Story))
        fetchRequest.sortDescriptors = [ NSSortDescriptor(key: "createdDate", ascending: false) ]
        
        return fetchRequest
    }
    
    class func instancesForContentURLs(URLs: [String],
                                       managedObjectContext: NSManagedObjectContext) -> [Story]? {
        
        let results = self.instancesInManagedObjectContext(managedObjectContext,
                                                           predicate: NSPredicate(format: "contentURL in %@", URLs))
        return results
    }
    
    class func instancesInManagedObjectContext(managedObjectContext: NSManagedObjectContext,
                                               predicate: NSPredicate? = nil) -> [Story]? {
        
        let fetchRequest = self.fetchRequest()
        fetchRequest.predicate = predicate
        
        do {
            let results = try managedObjectContext.executeFetchRequest(fetchRequest)
            return results as? [Story]
            
        } catch {
            // TODO: Handle error
            return nil
        }
    }
    
    func imageURLForSize(imageSize: ImageSize) -> String? {
        switch imageSize {
        case .Default:
            return imageURL
        case .Thumbnail:
            return thumbnailURL
        }
    }

    /**
     Use with imageURLForSize(_:) to return the correct URL for the desired size.
     */
    enum ImageSize: Int {
        case Default
        case Thumbnail
    }
    
}<commit_msg>Adds documentation to Story class.<commit_after>//
//  Story.swift
//  TopStories
//
//  Created by <NAME> on 20/04/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import CoreData

class Story: NSManagedObject {

    /**
     Default fetch request for Story entities.
     
     Returns a fetch request configured to return Story entities, sorted by date created descending.
     
     - returns: NSFetchRequest instance for Story entities.
     */
    class func fetchRequest() -> NSFetchRequest {
        
        let fetchRequest = NSFetchRequest(entityName: String(Story))
        fetchRequest.sortDescriptors = [ NSSortDescriptor(key: "createdDate", ascending: false) ]
        
        return fetchRequest
    }
    
    /**
     Lookup Story instances by contentURL value.
     
     Looks up Story instances based on contentURL value. Ideally we would use something like a unique
     identifier here to refer to unique instances. The API doesn't provide us with such, so we'll
     key off contentURL.
     
     - parameter URLs: Array of contentURLs used to perform the story lookup.
     - parameter managedObjectContext: The managedObjectContext instance to execute a fetch against.
     
     - returns: Array Story entities matching the contentURLs.
     */
    class func instancesForContentURLs(URLs: [String],
                                       managedObjectContext: NSManagedObjectContext) -> [Story]? {
        
        let results = self.instancesInManagedObjectContext(managedObjectContext,
                                                           predicate: NSPredicate(format: "contentURL in %@", URLs))
        return results
    }
    
    /**
     Lookup Story instances by predicate.
     
     Looks up Story instances based on a supplied predicate.
     
     - parameter managedObjectContext: The managedObjectContext instance to execute a fetch against.
     - parameter predicate: The predicate to use in the fetch request.
     
     - returns: Array Story entities matching the predicate.
     */
    class func instancesInManagedObjectContext(managedObjectContext: NSManagedObjectContext,
                                               predicate: NSPredicate? = nil) -> [Story]? {
        
        let fetchRequest = self.fetchRequest()
        fetchRequest.predicate = predicate
        
        do {
            let results = try managedObjectContext.executeFetchRequest(fetchRequest)
            return results as? [Story]
            
        } catch {
            // TODO: Handle error
            return nil
        }
    }
    
    /**
     Return image URL by desired size.
     
     - parameter imageSize: The desired image size, see ImageSize for options.
     
     - returns: Image URL string.
     */
    func imageURLForSize(imageSize: ImageSize) -> String? {
        switch imageSize {
        case .Default:
            return imageURL
        case .Thumbnail:
            return thumbnailURL
        }
    }

    /**
     Use with imageURLForSize(_:) to return the correct URL for the desired size.
     */
    enum ImageSize: Int {
        case Default
        case Thumbnail
    }
    
}
{'fraction_non_alphanumeric': 0.0691861627674465, 'fraction_numerical': 0.004799040191961607, 'mean_word_length': 1.8550228310502284, 'pattern_counts': {'":': 0, '<': 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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4701211', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1188, 'n_words': 390}