Class: Cartographie::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/cartographie/map.rb

Overview

Map represents a map, and contains the details regarding a map’s dimensions, zoom level, the image file format, and whether a GPS sensor was used in determining the map’s location.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location = 'Paris, France', options = {}) ⇒ Map

Public: Initialize a Map

location - The String for the map’s location (default: ‘Paris, France’). options - The Hash options used to configure the map (default: {}):

:width       - The Integer width of the map (optional).
:height      - The Integer height of the map (optional).
:zoom        - The Integer zoom level (optional).
:file_format - The String file format for the image (optional).
:sensor      - The Boolean indicating GPS usage (optional).

Examples

Cartographie::Map.new('San Francisco, CA', zoom: 10)


27
28
29
30
# File 'lib/cartographie/map.rb', line 27

def initialize(location='Paris, France', options={})
  self.location = location
  self.options = options
end

Instance Attribute Details

#locationObject

Public: Gets/Sets the String location of the map.



10
11
12
# File 'lib/cartographie/map.rb', line 10

def location
  @location
end

#optionsObject

Public: Gets/Sets the Hash options for the map.



12
13
14
# File 'lib/cartographie/map.rb', line 12

def options
  @options
end

Instance Method Details

#api_endpointObject



79
80
81
# File 'lib/cartographie/map.rb', line 79

def api_endpoint
  options[:api_endpoint] || Config.api_endpoint
end

#file_formatObject

Returns the String file format passed in options, or default



65
66
67
# File 'lib/cartographie/map.rb', line 65

def file_format
  options[:file_format] || Config.file_format
end

#heightObject

Returns the Integer height passed in options, or default



55
56
57
# File 'lib/cartographie/map.rb', line 55

def height
  options[:height] || Config.height
end

#sensorObject

Returns the Boolean indicating sensor usage passed in options, or default



70
71
72
# File 'lib/cartographie/map.rb', line 70

def sensor
  options[:sensor] || Config.sensor
end

#sizeObject

Returns a string combining width and height into dimensions



75
76
77
# File 'lib/cartographie/map.rb', line 75

def size
  "#{width}x#{height}"
end

#uriObject Also known as: to_s

Public: Build a Google Static Maps image URI

Returns the String URI pointing an image of the map



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cartographie/map.rb', line 35

def uri
  params = {
    center: location,
    size: size,
    zoom: zoom,
    format: file_format,
    sensor: sensor.to_s
  }
  Addressable::URI.parse(api_endpoint).tap do |uri|
    uri.query_values = params
  end.to_s
end

#widthObject

Returns the Integer width passed in options, or default



50
51
52
# File 'lib/cartographie/map.rb', line 50

def width
  options[:width] || Config.width
end

#zoomObject

Returns the Integer zoom level passed in options, or default



60
61
62
# File 'lib/cartographie/map.rb', line 60

def zoom
  options[:zoom] || Config.zoom
end