Module: Hyrax::DisplaysTranscripts

Extended by:
ActiveSupport::Concern
Included in:
AnnotatesContent, FileSetPresenter
Defined in:
app/presenters/hyrax/displays_transcripts.rb

Instance Method Summary collapse

Instance Method Details

#language_code(language) ⇒ String or NilClass

Try our best to convert language field to an ISO 639-1 code for use in the IIIF manifest.

Parameters:

Returns:

  • (String or NilClass)
    • the 2-letter code, or nil if no value or value is unparseable


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/presenters/hyrax/displays_transcripts.rb', line 31

def language_code(language)
  return if language.empty?
  value = language.first
  if URI.parse(value).scheme
    # This is probably a Library of Congress languages URI
    # like http://id.loc.gov/vocabulary/iso639-3/eng, which can
    # be configured with the Questioning Authority gem.
    # Try to extract the code from the URI.
    LanguageList::LanguageInfo.find(value.split("/").last).try(:iso_639_1)
  else
    # Otherwise, assume it is a language code or name and try
    # to convert it to a 2-letter code
    LanguageList::LanguageInfo.find(value).try(:iso_639_1)
  end
end

#transcript_url(document, host: request.base_url, file_ext: "vtt") ⇒ Object



22
23
24
# File 'app/presenters/hyrax/displays_transcripts.rb', line 22

def transcript_url(document, host: request.base_url, file_ext: "vtt")
  Hyrax::Engine.routes.url_helpers.transcript_url(document.id, host: host, file_ext: file_ext)
end

#transcriptsArray<SolrDocument>

the audio/video file set's transcript_ids

Returns:

  • (Array<SolrDocument>)

    the solr documents represented by



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/presenters/hyrax/displays_transcripts.rb', line 8

def transcripts
  return [] if transcript_ids.blank?
  @transcripts ||= begin
                      results = Hyrax::SolrQueryService.new
                                                       .accessible_by(
                                                         ability: (try(:current_ability) || ability),
                                                         action: :read
                                                       )
                                                       .with_ids(ids: transcript_ids)
                                                       .solr_documents
                      sort_transcripts_by_language(results)
                    end
end