@votemike/property
Version:
Property class and related classes
30 lines (29 loc) • 775 B
JavaScript
import { round } from './helpers';
export default class Payment {
constructor(amount, interval) {
this.amount = amount;
this.interval = interval;
}
get monthlyCost() {
return round(this.calculateMonthlyCost());
}
get yearlyCost() {
return round(this.calculateYearlyCost());
}
calculateYearlyCost() {
if (this.interval === 'yearly') {
return this.amount;
}
return this.amount * 12;
}
calculateMonthlyCost() {
if (this.interval === 'monthly') {
return this.amount;
}
return this.amount / 12;
}
static fromJson(json) {
const payment = Object.create(Payment.prototype);
return Object.assign(payment, json);
}
}