Sha256: 27f180f4d7dab9f0029466a791da5b85d2c3ae3afc00aef24c5dc3e5e3d4bfb2

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Onebox
  module Engine
    class GoogleDocsOnebox
      include Engine
      include StandardEmbed
      include LayoutSupport

      SUPPORTED_ENDPOINTS = %w(spreadsheets document forms presentation)
      SHORT_TYPES = {
        spreadsheets: :sheets,
        document: :docs,
        presentation: :slides,
        forms: :forms,
      }

      matches_regexp(/^(https?:)?\/\/(docs\.google\.com)\/(?<endpoint>(#{SUPPORTED_ENDPOINTS.join('|')}))\/d\/((?<key>[\w-]*)).+$/)
      always_https

      private

      def data
        og_data = get_opengraph
        short_type = SHORT_TYPES[match[:endpoint].to_sym]

        description = if Onebox::Helpers.blank?(og_data.description)
          "This #{short_type.to_s.chop.capitalize} is private"
        else
          Onebox::Helpers.truncate(og_data.description, 250)
        end

        {
          link: link,
          title: og_data.title || "Google #{short_type.to_s.capitalize}",
          description: description,
          type: short_type
        }
      end

      def match
        @match ||= @url.match(@@matcher)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
onebox-2.2.19 lib/onebox/engine/google_docs_onebox.rb
onebox-2.2.18 lib/onebox/engine/google_docs_onebox.rb
onebox-2.2.17 lib/onebox/engine/google_docs_onebox.rb
onebox-2.2.16 lib/onebox/engine/google_docs_onebox.rb
onebox-2.2.15 lib/onebox/engine/google_docs_onebox.rb