{"size": 1026, "ext": "js", "max_stars_repo_path": "app/components/search/services/searchSvc.js", "max_stars_repo_name": "ravigkl/happybazar", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/components/search/services/searchSvc.js", "max_issues_repo_name": "ravigkl/happybazar", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/components/search/services/searchSvc.js", "max_forks_repo_name": "ravigkl/happybazar", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.3181818182, "max_line_length": 104, "alphanum_fraction": 0.6510721248}
angular.module("search.services", ["data.appData", "messaging.services"])

.factory("searchSvc", [ "productData", "messageSvc", function(productData, messageSvc) {

	function searchByTitle(title) {

		if( !(title && ( typeof title.trim == "function" )) ) {
			  return [];			  
		}

		if( !(productData && productData.usedGames && (typeof productData.usedGames.filter == "function")) ) {
			return [];
		}

		var loweredTitle = title.trim().toLowerCase();

		var gamesFound = productData.usedGames.filter( function(game) {
			return game.name.toLowerCase().indexOf(loweredTitle) > -1;
		});

		// new user msg for lookup outcome
		messageSvc.displayMsg(createResultsMsg(gamesFound.length));

		return gamesFound;
	}


	function createResultsMsg(resultSize) {
		var quantifier = resultSize > 0 ? resultSize : "No";
		var noun = resultSize === 1 ? "game" : "games";
		var terminator = resultSize > 0 ? "!" : ".";
		
		return quantifier + " " + noun + " found" + terminator;
	}


	return {
		search : searchByTitle
	};
	
} ]);


