Sha256: fff47475da35e66ab7db2f3bf8044bd422478d7a9d3a1d9b3e96b354eef07b89

Contents?: true

Size: 1.23 KB

Versions: 25

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Commonmeta
  module Writers
    module BibtexWriter
      def bibtex
        pages = if container.to_h['firstPage'].present?
                  [container['firstPage'], container['lastPage']].compact.join('-')
                end

        bib = {
          bibtex_type: Commonmeta::Utils::CM_TO_BIB_TRANSLATIONS.fetch(type, 'misc'),
          bibtex_key: normalize_id(id),
          doi: doi_from_url(id),
          url: url,
          author: authors_as_string(creators),
          keywords: if subjects.present?
                      Array.wrap(subjects).map do |k|
                        parse_attributes(k, content: 'subject', first: true)
                      end.join(', ')
                    end,
          language: language,
          title: parse_attributes(titles, content: 'title', first: true),
          journal: container && container['title'],
          volume: container.to_h['volume'],
          issue: container.to_h['issue'],
          pages: pages,
          publisher: publisher.to_h['name'],
          year: date.to_h['published'] && date['published'].split('-').first,
          copyright: license.to_h['id']
        }.compact
        BibTeX::Entry.new(bib).to_s
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
commonmeta-ruby-3.2.13 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.12 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.11 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.10 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.9 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.8 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.7 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.6 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.5 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.4 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.3 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.2 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.1 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.2.0 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.0.10 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.0.9 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.0.8 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.0.7 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.0.6 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.0.5 lib/commonmeta/writers/bibtex_writer.rb