Sha256: b43d33662b8a43a902991169764724c644c77aa1878fce0f256691effa6e42ee

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module OembedProxy
  # Google Maps Engine Fauxembed
  class GoogleMapsengine
    MAPSENGINE_REGEXES = [
      %r{\Ahttps://mapsengine\.google\.com/map/(?:edit|view)\?mid=(.+)},
      %r{\Ahttps://www\.google\.com/maps/d/edit\?mid=(.+)},
    ].freeze

    def handles_url?(url)
      !get_matching_regex(url).nil?
    end

    def get_data(url, _other_params = {})
      return nil unless handles_url? url

      {
        'type' => 'rich',
        'version' => '1.0',
        'provider_name' => 'Google Maps Engine',
        'provider_url' => 'https://mapsengine.google.com/',
        'html' => "<iframe class=\"google-map\" width=\"640\" height=\"480\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"https://mapsengine.google.com/map/embed?mid=#{url.match(get_matching_regex(url))[1]}\"></iframe>",
        'width' => 500,
        'height' => 500,
      }
    end

    private

    def get_matching_regex(str)
      MAPSENGINE_REGEXES.each do |regex|
        return regex unless (str =~ regex).nil?
      end

      nil
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
oembed_proxy-0.3 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.2.6 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.2.5 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.2.4 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.2.3 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.2.2 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.2.1 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.2.0 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.1.4 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.1.3 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.1.2 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.1.1 lib/oembed_proxy/google_mapsengine.rb
oembed_proxy-0.1.0 lib/oembed_proxy/google_mapsengine.rb