/*globals Downsampler,LoadSlicer*/

var MeritTransformator = (function () {
    'use strict';

    function transformSerieValues(serie) {
        if (this.scope.dateSelect.val() > 0) {
            return LoadSlicer.slice(serie, this.scope.dateSelect.val());
        } else {
            return Downsampler.downsample(serie);
        }
    }

    MeritTransformator.prototype = {
        transform: function () {
            this.data.forEach(function(serie) {
                serie.values = transformSerieValues.call(this, serie);
            }.bind(this));


            return this.data;
        }
    };

    function MeritTransformator (scope, data) {
        this.scope = scope;
        this.data  = $.extend(true, [], data);
    }

    return MeritTransformator;
}());

/*globals Downsampler,LoadSlicer*/

var MeritTransformator = (function () {
    'use strict';

    function transformSerieValues(serie) {
        if (this.scope.dateSelect.val() > 0) {
            return LoadSlicer.slice(serie, this.scope.dateSelect.val());
        } else {
            return Downsampler.downsample(serie);
        }
    }

    MeritTransformator.prototype = {
        transform: function () {
            return this.data.map(function(serie) {
                return $.extend(
                    {}, serie,
                    { values: transformSerieValues.call(this, serie) }
                );
            }.bind(this));
        }
    };

    function MeritTransformator (scope, data) {
        this.scope = scope;
        this.data  = data;
    }

    return MeritTransformator;
}());

Clone Merit data as late as possible
Clone Merit data as late as possible

It's not necessary to clone the entire (original) data - especially
since the MeritTransformator isn't reused - but instead we can
shallow-clone each series, and replace the values with those sliced up
or downsampled by the Transformator.
