Sha256: 1dc0e4d3d157ea30dceae2960a4444a440a98db703397458c66a37299cf1caef

Contents?: true

Size: 1.27 KB

Versions: 16

Compression:

Stored size: 1.27 KB

Contents

module Sufia
  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

16 entries across 16 versions & 1 rubygems

Version Path
sufia-7.4.1 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.4.0 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.3.1 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.3.0 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.3.0.rc3 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.3.0.rc2 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.3.0.rc1 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.2.0 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.1.0 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.0.0 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.0.0.rc2 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.0.0.rc1 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.0.0.beta4 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.0.0.beta3 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.0.0.beta2 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb
sufia-7.0.0.beta1 app/helpers/sufia/citations_behaviors/formatters/open_url_formatter.rb