class AutoHtml::GoogleMaps

Google Maps filter

Public Class Methods

new(width: 420, height: 315, type: :normal, zoom: 18, show_info: false) click to toggle source
# File lib/auto_html/google_maps.rb, line 8
def initialize(width: 420, height: 315, type: :normal, zoom: 18, show_info: false)
  @width = width
  @height = height
  @type = type
  @zoom = zoom
  @show_info = show_info
end

Public Instance Methods

call(text) click to toggle source
# File lib/auto_html/google_maps.rb, line 16
def call(text)
  regex = %r{(https?)://maps\.google\.([a-z\.]+)/maps\?(.*)}
  text.gsub(regex) do
    country = Regexp.last_match(2)
    path = "//maps.google.#{country}/maps"
    query = Regexp.last_match(3)
    link = link_tag(path, query)
    iframe_tag(path, query) << tag(:br) << tag(:small) { link }
  end
end

Private Instance Methods

iframe_tag(path, map_query) click to toggle source
# File lib/auto_html/google_maps.rb, line 29
def iframe_tag(path, map_query)
  params = ['f=q', 'source=s_q', map_query, 'output=embed'] + map_options
  tag(
    :iframe,
    width: @width,
    height: @height,
    frameborder: 0,
    scrolling: 'no',
    marginheight: 0,
    marginwidth: 0,
    src: path + '?' + params.join('&amp;')) { '' }
end
map_options() click to toggle source
# File lib/auto_html/google_maps.rb, line 52
def map_options
  map_options = []
  map_options << 'iwloc=near' if @show_info
  map_options << map_types[@type]
  map_options << "z=#{@zoom}"
end
map_types() click to toggle source
# File lib/auto_html/google_maps.rb, line 59
def map_types
  @map_types ||= {
    normal: 't=m',
    satellite: 't=k',
    terrain: 't=p',
    hibrid: 't=h'
  }
end