Sha256: 74d54791a7efa78427043f1a6959530de0588d658d7ad504aecf97b7b0297b7d

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

module Hyrax
  module CitationsBehaviors
    module Formatters
      class OpenUrlFormatter < BaseFormatter
        def format(work)
          export_text = []
          export_text << "url_ver=Z39.88-2004&ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator"
          field_map.each do |element, kev|
            next unless work.respond_to?(element)
            values = work.send(element)
            Array.wrap(values).each do |value|
              next if value.blank?
              export_text << "rft.#{kev}=#{CGI.escape(value.to_s)}"
            end
          end
          export_text.join('&') unless export_text.blank?
        end

        private

          def field_map
            {
              title: 'title',
              creator: 'creator',
              subject: 'subject',
              description: 'description',
              publisher: 'publisher',
              contributor: 'contributor',
              date_created: 'date',
              resource_type: 'format',
              identifier: 'identifier',
              language: 'language',
              keyword: 'relation',
              based_near: 'coverage',
              rights: 'rights'
            }
          end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
hyrax-1.1.1 app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb
hyrax-1.1.0 app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb
hyrax-1.0.5 app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb
hyrax-1.0.4 app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb
hyrax-1.0.3 app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb
hyrax-1.0.2 app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb
hyrax-1.0.1 app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb
hyrax-1.0.0.rc2 app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb
hyrax-1.0.0.rc1 app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb
test_hyrax-0.0.1.alpha app/helpers/hyrax/citations_behaviors/formatters/open_url_formatter.rb