All files / src/search/builders RideTypesSearchBuilder.js

52.63% Statements 10/19
25% Branches 2/8
100% Functions 0/0
52.63% Lines 10/19
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    1x   1x 1x 1x       1x   1x       1x 1x   1x         1x                                          
'use es6';
 
import {Map} from 'immutable';
 
import Coordinate from '../../data/Coordinate';
import CoordinateBuilder from '../../data/builders/CoordinateBuilder';
import RideTypesSearch from '../RideTypesSearch';
 
export default class RideTypesSearchBuilder {
  static build(json) {
    let args = Map();
 
    Iif (!('start' in json)) {
      throw new TypeError('start is not in the search');
    }
 
    let startCoordinate = CoordinateBuilder.build(json['start']);
    args = args.set('startCoordinate', startCoordinate);
 
    Iif ('rideType' in json) {
      let rideType = RideTypesSearchBuilder.validateRideType(json['rideType']);
      args = args.set('rideType', rideType);
    }
 
    return new RideTypesSearch(args);
  }
 
  static validateRideType(rideType) {
    if (!Object.prototype.toString.call(rideType) === '[object String]') {
      throw new TypeError('rideType is not a string');
    }
 
    const rideTypes = [
      'lyft',
      'lyft_line',
      'lyft_plus',
    ];
 
    if (rideTypes.indexOf(rideType) === -1) {
      throw new RangeError('rideType must be either \'lyft\', \'lyft_line\', or \'lyft_plus\'');
    }
 
    return rideType;
  }
}