{"size": 1035, "ext": "js", "max_stars_repo_path": "app/js/Model.js", "max_stars_repo_name": "ifeature/pbConverter", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/js/Model.js", "max_issues_repo_name": "ifeature/pbConverter", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/js/Model.js", "max_forks_repo_name": "ifeature/pbConverter", "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": 20.2941176471, "max_line_length": 66, "alphanum_fraction": 0.547826087}
'use strict';

/**
 * Модуль Модель
 * @type {{Currency, Currencies}}
 */
define([], function () {
  const Model = Object.create(null);

  class Currency {
    constructor() {

    }
  }
  class Currencies {
    constructor() {

    }
    /**
     * Метод, позволяющий конвертировать один тип валюты в другой.
     * @param {number} amount Входящая сумма
     * @param {string} from Меняю
     * @param {string} to Получаю
     * @returns {number} Результирующая сумма
     */
    convert(amount, from, to) {
      let result;

      if (from !== 'UAH' && to !== 'UAH') {
        const cur1 = from;
        const cur2 = to;
        const stepOne = this.convert(amount, cur1, 'UAH');
        return this.convert(stepOne, 'UAH', cur2);
      }

      if (from === 'UAH') {
        result = amount / this[to].sale;
      } else if (to === 'UAH') {
        result = amount * this[from].buy;
      }

      return Math.round(result * 1e2) / 1e2;
    }
  }

  Model.Currency = Currency;
  Model.Currencies = Currencies;

  return Model;
});
