<commit_before>//
//  JobsData.swift
//  GitHubJobs
//
//  Created by <NAME> on 9/18/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

class JobData {
	
	static let instance = JobData()
	
	private var description = ""
	private var location:String?
	private var latitude:Double?
	private var longitude:Double?
	private var fullTime = true
	private var page = 1
	private var data:[[String:Any]] = []
	
	private init() { }
	
	func getJobs(description:String, location:String, fullTime:Bool, completion:Completion) {
		guard self.description != description,
			let loc = self.location,
			loc != location,
			self.fullTime != fullTime else {
			return
		}
		self.description = description
		self.location = location
		self.fullTime = fullTime
		self.longitude = nil
		self.latitude = nil
		self.page = 1
		let params:[String:Any] = ["description": description,
		                           "location": location,
		                           "full_time": fullTime]
		jobData(params: params, completion: completion)
	}
	
	func getJobs(description:String, lat:Double, long:Double, fullTime:Bool, completion:Completion) {
		guard self.description != description,
			let _lat = self.latitude,
			_lat != lat,
			let _long = self.longitude,
			_long != long,
			self.fullTime != fullTime else {
			return
		}
			
		self.description = description
		self.latitude = lat
		self.longitude = long
		self.fullTime = fullTime
		self.location = nil
		self.page = 1
		let params:[String:Any] = ["description": description,
		                           "lat": lat,
		                           "long": long,
		                           "full_time": fullTime]
		jobData(params: params, completion: completion)
	}
	
	func nextPage(completion:Completion) {
		page += 1
		guard let loc = location else {
			guard let lat = latitude, let long = longitude else {
				return
			}
			let params:[String:Any] = ["description": description,
			                           "lat": lat,
			                           "long": long,
			                           "full_time": fullTime,
			                           "page":page]
			jobData(params: params, completion: completion)
			return
			
		}
		let params:[String:Any] = ["description": description,
		                           "location": loc,
		                           "full_time": fullTime,
		                           "page":page]
		jobData(params: params, completion: completion)
	}
	
	private func jobData(params:[String:Any], completion:Completion) {
		Api.instance.getJobs(params: params) { (json:[[String : Any]]?) in
			guard let j = json else {
				completion?(nil)
				return
			}
			self.data = j
			completion?(j)
		}
	}
}<commit_msg>Moved page and data reset in jobData method<commit_after>//
//  JobsData.swift
//  GitHubJobs
//
//  Created by <NAME> on 9/18/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

class JobData {
	
	static let instance = JobData()
	
	private var description = ""
	private var location:String?
	private var latitude:Double?
	private var longitude:Double?
	private var fullTime = true
	private var page = 1
	private var data:[[String:Any]] = []
	
	private init() { }
	
	func getJobs(description:String, location:String, fullTime:Bool, completion:Completion) {
		guard self.description != description,
			let loc = self.location,
			loc != location,
			self.fullTime != fullTime else {
			return
		}
		self.description = description
		self.location = location
		self.fullTime = fullTime
		self.longitude = nil
		self.latitude = nil
		let params:[String:Any] = ["description": description,
		                           "location": location,
		                           "full_time": fullTime]
		jobData(params: params, completion: completion)
	}
	
	func getJobs(description:String, lat:Double, long:Double, fullTime:Bool, completion:Completion) {
		guard self.description != description,
			let _lat = self.latitude,
			_lat != lat,
			let _long = self.longitude,
			_long != long,
			self.fullTime != fullTime else {
			return
		}
			
		self.description = description
		self.latitude = lat
		self.longitude = long
		self.fullTime = fullTime
		self.location = nil
		let params:[String:Any] = ["description": description,
		                           "lat": lat,
		                           "long": long,
		                           "full_time": fullTime]
		jobData(params: params, completion: completion)
	}
	
	func nextPage(completion:Completion) {
		page += 1
		guard let loc = location else {
			guard let lat = latitude, let long = longitude else {
				return
			}
			let params:[String:Any] = ["description": description,
			                           "lat": lat,
			                           "long": long,
			                           "full_time": fullTime,
			                           "page":page]
			jobData(params: params, completion: completion)
			return
			
		}
		let params:[String:Any] = ["description": description,
		                           "location": loc,
		                           "full_time": fullTime,
		                           "page":page]
		jobData(params: params, completion: completion)
	}
	
	private func jobData(params:[String:Any], completion:Completion) {
		page = 1
		data.removeAll()
		Api.instance.getJobs(params: params) { (json:[[String : Any]]?) in
			guard let j = json else {
				completion?(nil)
				return
			}
			self.data = j
			completion?(j)
		}
	}
}
{'fraction_non_alphanumeric': 0.11090641120117907, 'fraction_numerical': 0.004605747973470892, 'mean_word_length': 2.2411940298507464, 'pattern_counts': {'":': 32, '<': 7, '<?xml version=': 0, '>': 7, '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': '6478679', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1524, 'n_words': 414}