Sha256: 7a0c8b7f96dd804961c6da8fc907bf3c698611c1817fbae3e9410343f2a40dc4

Contents?: true

Size: 1.43 KB

Versions: 12

Compression:

Stored size: 1.43 KB

Contents

module Calagator

module GoogleEventExportHelper
  # Return a Google Calendar export URL.

  def google_event_export_link(event)
    GoogleEventExportLink.new(event, self).render
  end

  class GoogleEventExportLink < Struct.new(:event, :context)
    def render
      truncate(url + query)
    end

    private

    def url
      "http://www.google.com/calendar/event?action=TEMPLATE&trp=true&"
    end

    def query
      fields.collect do |field|
        send(field).to_query(field)
      end.compact.join("&")
    end

    def fields
      [:text, :dates, :location, :sprop, :details]
    end

    def text
      event.title
    end

    def dates
      google_time_format = "%Y%m%dT%H%M%SZ"
      end_time = event.end_time || event.start_time
      "#{event.start_time.utc.strftime(google_time_format)}/#{end_time.utc.strftime(google_time_format)}"
    end

    def location
      location = event.venue.try(:title)
      if address = event.venue.try(:geocode_address)
        location += ", #{address}" if address.present?
      end
      location
    end

    def sprop
      if event.url.present?
        "website:#{event.url.sub(/^http.?:\/\//, '')}"
      end
    end

    def details
      "Imported from: #{context.event_url(event)} \n\n#{event.description}"
    end

    def truncate string
      omission = "...[truncated]"
      length = 1024 - omission.length
      context.truncate(string, length: length, omission: omission)
    end
  end
end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
grokus-1.0.0.9 app/helpers/calagator/google_event_export_helper.rb
grokus-1.0.0.8 app/helpers/calagator/google_event_export_helper.rb
grokus-1.0.0.7 app/helpers/calagator/google_event_export_helper.rb
grokus-1.0.0.6 app/helpers/calagator/google_event_export_helper.rb
grokus-1.0.0.5 app/helpers/calagator/google_event_export_helper.rb
grokus-1.0.0.3 app/helpers/calagator/google_event_export_helper.rb
grokus-1.0.0.2 app/helpers/calagator/google_event_export_helper.rb
grokus-1.0.0.1 app/helpers/calagator/google_event_export_helper.rb
calagator-1.0.0.rc3 app/helpers/calagator/google_event_export_helper.rb
calagator-1.0.0.rc2 app/helpers/calagator/google_event_export_helper.rb
calagator-1.0.0.rc1 app/helpers/calagator/google_event_export_helper.rb
calagator-0.0.1.pre1 app/helpers/calagator/google_event_export_helper.rb