Module: GoogleMapsService::Validator

Defined in:
lib/google_maps_service/validator.rb

Overview

Validate value that is accepted by Google Maps.

Class Method Summary collapse

Class Method Details

.avoid(avoid) ⇒ String

Validate route restriction. The valid value of route restriction are tolls, highways or ferries.

Parameters:

  • avoid (String, Symbol)

    Route restriction to be validated.

Returns:

  • (String)

    Valid route restriction.

Raises:

  • ArgumentError The route restriction is invalid.



32
33
34
35
36
37
# File 'lib/google_maps_service/validator.rb', line 32

def avoid(avoid)
  unless [:tolls, :highways, :ferries].include?(avoid.to_sym)
    raise ArgumentError, 'Invalid route restriction.'
  end
  avoid
end

.travel_mode(mode) ⇒ String

Validate travel mode. The valid value of travel mode are driving, walking, bicycling or transit.

Parameters:

  • mode (String, Symbol)

    Travel mode to be validated.

Returns:

  • (String)

    Valid travel mode.

Raises:

  • ArgumentError The travel mode is invalid.



16
17
18
19
20
21
22
23
# File 'lib/google_maps_service/validator.rb', line 16

def travel_mode(mode)
  # NOTE(broady): the mode parameter is not validated by the Maps API
  # server. Check here to prevent silent failures.
  unless [:driving, :walking, :bicycling, :transit].include?(mode.to_sym)
    raise ArgumentError, 'Invalid travel mode.'
  end
  mode
end