projects/maplander/components/src/lib/services/currency-converter/currency-converter.service.ts
Methods |
|
Private getValueByCurrency | |||||||||
getValueByCurrency(currencies: CER[], c: Currency)
|
|||||||||
Parameters :
Returns :
number
|
list | |||||||||||||||
list(prices: number[], currencies: CER[], from: Currency, to: Currency)
|
|||||||||||||||
Parameters :
Returns :
number[]
|
number | |||||||||||||||
number(price: number, currencies: CER[], from: Currency, to: Currency)
|
|||||||||||||||
Parameters :
Returns :
number
|
import {Injectable} from '@angular/core';
import {CER, Currency} from '@maplander/types';
@Injectable()
export class CurrencyConverterService {
list(prices: number[], currencies: CER[], from: Currency, to: Currency): number[] {
const valueFrom = this.getValueByCurrency(currencies, from), valueTo = this.getValueByCurrency(currencies, to);
prices = prices.map(price => {
if (from === to) {
return price;
} else {
return valueTo * (price / valueFrom);
}
});
return prices;
}
number(price: number, currencies: CER[], from: Currency, to: Currency): number {
const valueFrom = this.getValueByCurrency(currencies, from), valueTo = this.getValueByCurrency(currencies, to);
return valueTo * (price / valueFrom);
}
private getValueByCurrency(currencies: CER[], c: Currency): number {
let value = 0;
currencies.forEach(currency => {
if (currency.type === c.toString()) {
value = currency.value;
}
});
return value;
}
}