Class: Geoblacklight::Document::DownloadLinkComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/geoblacklight/document/download_link_component.rb

Overview

A single resource available for download on a record

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, title: nil, file_type: nil, data_file_type: nil) ⇒ DownloadLinkComponent

Returns a new instance of DownloadLinkComponent.

Parameters:

  • url (String)

    the URL of the download link

  • title (String, nil) (defaults to: nil)

    the title of the download link

  • file_type (String, nil) (defaults to: nil)

    file type for what will be downloaded (e.g. zip)

  • data_file_type (String, nil) (defaults to: nil)

    file type for the actual data (e.g. Shapefile)



13
14
15
16
17
18
19
# File 'app/components/geoblacklight/document/download_link_component.rb', line 13

def initialize(url:, title: nil, file_type: nil, data_file_type: nil)
  @url = url
  @title = title
  @file_type = file_type
  @data_file_type = data_file_type
  super()
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'app/components/geoblacklight/document/download_link_component.rb', line 7

def url
  @url
end

Instance Method Details

#file_typeObject

Infer the file type from the URL if not provided



27
28
29
# File 'app/components/geoblacklight/document/download_link_component.rb', line 27

def file_type
  @file_type || wfs_file_type || requested_file_type || file_extension
end

#titleObject

Use format to label the download if no title is provided



22
23
24
# File 'app/components/geoblacklight/document/download_link_component.rb', line 22

def title
  @title || generated_title_from_format || title_from_format
end