Class: MapboxUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/mapbox/mapbox_utils.rb

Class Method Summary collapse

Class Method Details

.encode_url(url) ⇒ Object



4
5
6
7
# File 'lib/mapbox/mapbox_utils.rb', line 4

def self.encode_url(url)
  url.sub!(/^http[s]?\:\/\//, '')
  CGI::escape(url.to_s)
end

.validate_api_id(api_id) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
# File 'lib/mapbox/mapbox_utils.rb', line 31

def self.validate_api_id(api_id)
  raise ArgumentError, "api_id cannot be nil" if api_id.nil?
  api_id
end

.validate_latitude(latitude) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
# File 'lib/mapbox/mapbox_utils.rb', line 9

def self.validate_latitude(latitude)
  latitude = latitude.to_f
  raise ArgumentError, "latitude needs to be between -85 and 85" unless 
    latitude >= -85.0 && latitude <= 85.0 
  latitude
end

.validate_longitude(longitude) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
# File 'lib/mapbox/mapbox_utils.rb', line 16

def self.validate_longitude(longitude)
  longitude = longitude.to_f
  raise ArgumentError, "longitude needs to be between -180 and 180" unless 
    longitude >= -180.0 && longitude <= 180.0 
  longitude
end

.validate_zoom(zoom) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
# File 'lib/mapbox/mapbox_utils.rb', line 23

def self.validate_zoom(zoom)
  zoom = zoom.to_i
  raise ArgumentError, "zoom needs to be between 0 and 22" unless 
    zoom >= 0 && zoom <= 22 
  zoom
end