Sha256: 1c19fca22ec1d7a3900f6104979ca02d6cc0578d4dc86ded33bc201c44e035cc

Contents?: true

Size: 1.04 KB

Versions: 23

Compression:

Stored size: 1.04 KB

Contents

module CurationConcerns
  class SingleUseLinkPresenter
    include ActionView::Helpers::TranslationHelper

    attr_reader :link

    delegate :downloadKey, :expired?, :to_param, to: :link

    # @param link [SingleUseLink]
    def initialize(link)
      @link = link
    end

    def human_readable_expiration
      if hours < 1
        t('curation_concerns.single_use_links.expiration.lesser_time')
      else
        t('curation_concerns.single_use_links.expiration.time', value: hours)
      end
    end

    def short_key
      link.downloadKey.first(6)
    end

    def link_type
      if download?
        t('curation_concerns.single_use_links.download.type')
      else
        t('curation_concerns.single_use_links.show.type')
      end
    end

    def url_helper
      if download?
        "download_single_use_link_url"
      else
        "show_single_use_link_url"
      end
    end

    private

      def download?
        link.path =~ /downloads/
      end

      def hours
        (link.expires - Time.zone.now).to_i / 3600
      end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.7.7 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-2.0.0 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-2.0.0.rc2 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.7.6 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.7.5 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.7.4 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.7.3 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.7.2 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-2.0.0.rc1 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.7.1 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.7.0 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.7.0.beta1 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.6.3 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.6.2 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.6.1 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.6.0 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.5.0 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.4.0 app/presenters/curation_concerns/single_use_link_presenter.rb
curation_concerns-1.3.3 app/presenters/curation_concerns/single_use_link_presenter.rb