Source/Operator.js

"use strict";
/**
 *  @module     Operator
 *  @overview   Defines the `Operator` class.
 *
 *  @author     Animesh Mishra <hello@animesh.ltd>
 *  @copyright  © Animesh Ltd. All Rights Reserved.
 */
Object.defineProperty(exports, "__esModule", { value: true });
/**
 *  The `Operator` class models a telecom operator and/or other service
 *  providers that offer products that can be recharged through the Magic
 *  Batua platform. So prepaid mobile companies, DTH operators and datacard
 *  companies all are instances of `Operator`.
 */
class Operator {
    /**
     *  Initialises an `Operator` instance.
     *  @param {GetOperatorResponse} json  The `GetOperatorResponse` is defined in `Source/Operator.ts`.
     */
    constructor(json) {
        this.name = json.operator_name;
        this.code = json.operator_code;
        // Margin is reported in the form "xx.xxxx%", we'd like to store it
        // as a floating-point number
        let fraction = json.margin.substr(0, json.margin.indexOf("%"));
        this.margin = Number(fraction) / 100.0;
    }
    /**
    *  Given an array of provider responses from Rocket in Pocket, instantiates and
    *  returns a `Operator` array.
    */
    static InitList(json) {
        let providers = Array();
        for (var provider of json) {
            providers.push(new Operator(provider));
        }
        return providers;
    }
    /**
     *  Returns an `Operator` with the given provider `code` amongst the list of
     *  `operators` given. If no match is found, returns `null`.
     */
    static WithCode(code, operators) {
        for (var operator of operators) {
            if (operator.code == code) {
                return operator;
            }
        }
        return null;
    }
}
exports.Operator = Operator;
//# sourceMappingURL=Operator.js.map