/**
 * Created by apizzimenti on 12/28/15.
 */

/**
 * @desc formats JSON
 * @param json - javascript object containing weather information
 * @returns {string}
 */

var clc = require('cli-color');

module.exports = Format;

function Format (json) {
    var obj = JSON.parse(json),
        now = obj.currently,
        predict = obj.daily.data.splice(1, 4),
        dates = [],
        maxtemps = [],
        mintemps = [],
        icons = [],

        current;

    predict.forEach (function (obj) {
        var date = new Date(obj.time * 1000),
            formatted = date.toDateString();

        dates.push(formatted);
        maxtemps.push(Math.floor(obj.temperatureMax).toString() + '˚');
        mintemps.push(Math.floor(obj.temperatureMin).toString() + '˚');
        icons.push(predict.icon);
    });

    current =
        '\nCurrent Conditions\n' +
        '==================\n' +
        (now.temperature >= 32 ? clc.red(Math.floor(now.temperature)) : clc.blue(Math.floor(now.temperature)) + clc.blue('˚')) +
        ' - ' + Math.floor(now.windSpeed).toString() + 'mph wind - ' +
        now.summary.toLowerCase() + ' - ' + (now.precipProbability * 100) + '% chance of precipitation\n';

    return {
        current: current,
        week: week(dates, maxtemps, mintemps, icon(icons))
    }
}

function week(dates, maxtemp, mintemp, icons) {
    return dates[0] + '|\t' + dates[1] + '|\t' + dates[2] + '\n' +
        clc.red(maxtemp[0]) + '|\t\t' +  clc.red(maxtemp[1]) + '|\t\t' + clc.red(maxtemp[2]) + '|\n' +
        clc.blue(mintemp[0]) + '|\t\t' + clc.blue(mintemp[1]) + '|\t\t' + clc.blue(mintemp[2]) + '|\n' +
        icons[0] + '|\t\t' + icons[1] + '|\t\t' + icons[2] + '|\n';
}

function icon(array) {
    var icons = [];

    array.forEach(function (name) {
        switch (name) {
            case 'clear-day':case 'clear-night':
                icons.push('☀ clear');
                break;
            case 'rain':
                icons.push('☂ rain');
                break;
            case 'snow':
                icons.push('❄ snow');
                break;
            case 'sleet':
                icons.push('☂❄ sleet');
                break;
            case 'wind':
                icons.push(name);
                break;
            default:
                icons.push('☁ clouds');
                break;
        }
    });

    return icons;
};
@@ -196,15 +196,8 @@
 );%0A%0A
-module.
 expo
@@ -206,1489 +206,79 @@
 s = 
-Format;%0A%0Afunction Format (json) %7B%0A    var obj = JSON.parse(json),%0A        now = obj.currently,%0A        predict = obj.daily.data.splice(1, 4),%0A        dates = %5B%5D,%0A        maxtemps = %5B%5D,%0A        mintemps = %5B%5D,%0A        icons = %5B%5D,%0A%0A        current;%0A%0A    predict.forEach (function (obj) %7B%0A        var date = new Date(obj.time * 1000),%0A            formatted = date.toDateString();%0A%0A        dates.push(formatted);%0A        maxtemps.push(Math.floor(obj.temperatureMax).toString() + '%CB%9A');%0A        mintemps.push(Math.floor(obj.temperatureMin).toString() + '%CB%9A');%0A        icons.push(predict.icon);%0A    %7D);%0A%0A    current =%0A        '%5CnCurrent Conditions%5Cn' +%0A        '==================%5Cn' +%0A        (now.temperature %3E= 32 ? clc.red(Math.floor(now.temperature)) : clc.blue(Math.floor(now.temperature)) + clc.blue('%CB%9A')) +%0A        ' - ' + Math.floor(now.windSpeed).toString() + 'mph wind - ' +%0A        now.summary.toLowerCase() + ' - ' + (now.precipProbability * 100) + '%25 chance of precipitation%5Cn';%0A%0A    return %7B%0A        current: current,%0A        week: week(dates, maxtemps, mintemps, icon(icons))%0A    %7D%0A%7D%0A%0Afunction week(dates, maxtemp, mintemp, icons) %7B%0A    return dates%5B0%5D + '%7C%5Ct' + dates%5B1%5D + '%7C%5Ct' + dates%5B2%5D + '%5Cn' +%0A        clc.red(maxtemp%5B0%5D) + '%7C%5Ct%5Ct' +  clc.red(maxtemp%5B1%5D) + '%7C%5Ct%5Ct' + clc.red(maxtemp%5B2%5D) + '%7C%5Cn' +%0A        clc.blue(mintemp%5B0%5D) + '%7C%5Ct%5Ct' + clc.blue(mintemp%5B1%5D) + '%7C%5Ct%5Ct' + clc.blue(mintemp%5B2%5D) + '%7C%5Cn' +%0A        icons%5B0%5D + '%7C%5Ct%5Ct' + icons%5B1%5D + '%7C%5Ct%5Ct' + icons%5B2%5D + '%7C%5Cn'
+module.exports = Format;%0A%0Afunction Format(json) %7B%0A    this.weeks = null
 ;%0A%7D%0A

test branch