class Voom::Presenters::Plugins::GoogleMaps::GoogleMap

Attributes

google_api_key[R]
height[R]
url[R]
width[R]

Public Class Methods

new(**attribs_, &block) click to toggle source
# File lib/voom/presenters/plugins/google_maps/google_map.rb, line 11
def initialize(**attribs_, &block)
  super(type: :google_map, **attribs_, &block)
  @address = attribs.delete(:address)
  @latitude = attribs.delete(:latitude)
  @longitude = attribs.delete(:longitude)
  @width = attribs.delete(:width) { 640 }
  @height = attribs.delete(:height) { 640 }
  @zoom = attribs.delete(:zoom) { 14 }
  @scale = attribs.delete(:scale) { 1 }
  @google_api_key = attribs.delete(:google_api_key) { ENV['GOOGLE_API_KEY'] }
  @url = build_static_map_image_url
  expand!
end

Private Instance Methods

build_static_map_image_url() click to toggle source
# File lib/voom/presenters/plugins/google_maps/google_map.rb, line 27
def build_static_map_image_url
  return @img_url if locked?
  @img_url = "https://maps.googleapis.com/maps/api/staticmap?center=#{query_string}&zoom=#{@zoom}&scale=#{@scale}&size=#{@width}x#{@height}&markers=|#{query_string}&key=#{@google_api_key}"
end
query_string() click to toggle source
# File lib/voom/presenters/plugins/google_maps/google_map.rb, line 32
def query_string
  return "#{@latitude},#{@longitude}" if @latitude && @longitude
  URI.escape(@address)
end