All files / app/classes city_connection.class.ts

94.59% Statements 70/74
100% Branches 11/11
90.9% Functions 10/11
94.59% Lines 70/74

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 751x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 1x 1x 2x 2x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x         1x 1x 1x 1x 1x 1x 1x  
import { CityConnectionInterface } from '../interfaces/city_connection.interface';
import { CityClass } from './city.class';
 
declare let google: any;
 
export class CityConnectionClass {
	id!: string;
	type!: string;
	travelTime!: number;
	travelMethod!: string;
	endingCity!: CityClass;
	marker: any;
 
	fromJson(json: CityConnectionInterface): void {
		const end = new CityClass();
		end.fromJson(json['ending-city']);
		this.id = json.id;
		this.type = json.type;
 
		this.travelTime = json?.attributes['travel-time'];
		this.travelMethod = json?.attributes['travel-method'];
		this.endingCity = end;
	}
 
	isLand(): boolean {
		return this.travelMethod === 'land';
	}
 
	isAir(): boolean {
		return !this.isLand();
	}
 
	getTravelMethod(): string {
		if (this.isLand()) {
			return 'land';
		}
		return 'plane';
	}
 
	setCity(city: CityClass): void {
		this.endingCity = city;
	}
 
	getCity(): CityClass {
		return this.endingCity;
	}
 
	getTravelTime(): string {
		return this.transform();
	}
 
	transform(): string {
		const temp = this.travelTime * 60;
		const hours = Math.floor(temp / 3600);
		const minutes: number = this.travelTime - 60 * hours;
		return hours + 'h ' + minutes + 'm';
	}
 
	setMarker(marker: any): void {
		this.marker = marker;
	}
 
	bounceMarker(): void {
		if (this.marker) {
			this.marker.setAnimation(google.maps.Animation.BOUNCE);
		}
	}
 
	stopBounceMarker(): void {
		if (this.marker) {
			this.marker.setAnimation(null);
		}
	}
}