instagram-graph-api
Version:
A library to help perform requests to the Instagram Graph API.
113 lines (112 loc) • 3.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleMetric = void 0;
const AbstractMetric_1 = require("./AbstractMetric");
/**
* Class to represent a simple metric.
*
* @author Tiago Grosso <tiagogrosso99@gmail.com>
* @since 0.1.0
*/
class SimpleMetric extends AbstractMetric_1.AbstractMetric {
/**
* Gets the metric values that match the provided expression.
*
* @param expression expression to match the values to.
*
* @returns the metric values that match the provided expression.
*/
getByExpression(expression) {
return this.metricData.values.filter(expression);
}
/**
* Gets the metric values greater than the provided limit.
*
* @param limit the limit.
*
* @returns the metric values greater than the provided limit.
*/
getGreaterThan(limit) {
return this.getByExpression((elem) => elem.value > limit);
}
/**
* Gets the metric values greater than or equal to the provided limit.
*
* @param limit the limit.
*
* @returns the metric values greater than or equal to the provided limit.
*/
getGreaterThanOrEqual(limit) {
return this.getByExpression((elem) => elem.value >= limit);
}
/**
* Gets the metric values smaller than the provided limit.
*
* @param limit the limit.
*
* @returns the metric values smaller than the provided limit.
*/
getLessThan(limit) {
return this.getByExpression((elem) => elem.value < limit);
}
/**
* Gets the metric values smaller than or equal to the provided limit.
*
* @param limit the limit.
*
* @returns the metric values smaller than or equal to the provided limit.
*/
getLessThanOrEqual(limit) {
return this.getByExpression((elem) => elem.value <= limit);
}
/**
* Gets the metric values equal to the provided value.
*
* @param value the limit.
*
* @returns the metric values equal to the provided value.
*/
getEqual(value) {
return this.getByExpression((elem) => elem.value === value);
}
/**
* Gets the metric values between the provided bounds (non-inclusive).
*
* @param lower the lower bound.
* @param upper the upper bound.
*
* @returns the metric values between the provided bounds (non-inclusive).
*/
getBetween(lower, upper) {
return this.getByExpression((elem) => upper > elem.value && elem.value > lower);
}
/**
* Returns the the highest value of the metric. In case of a tie, the first value found is returned.
*
* @returns the highest value of the metric.
*/
getHighest() {
let highest;
this.metricData.values.forEach((metric) => {
if (highest == undefined || metric.value > highest.value) {
highest = metric;
}
});
return highest;
}
/**
* Returns the the lowest value of the metric. In case of a tie, the first value found is returned.
*
* @returns the lowest value of the metric.
*/
getLowest() {
let lowest;
this.metricData.values.forEach((metric) => {
if (lowest == undefined || metric.value < lowest.value) {
lowest = metric;
}
});
return lowest;
}
}
exports.SimpleMetric = SimpleMetric;