Sha256: bacbddfa45d4b00fcbc33a269a1fa13370dd358e01110962de18c28f12931578

Contents?: true

Size: 1.24 KB

Versions: 27

Compression:

Stored size: 1.24 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(', ').capitalize
                    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

27 entries across 27 versions & 1 rubygems

Version Path
commonmeta-ruby-3.4.5 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.4.4 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.4.3 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.4.2 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.4.1 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.4.0 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.18 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.17 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.16 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.15 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.14 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.13 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.12 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.11 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.10 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.9 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.8 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.7 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.6 lib/commonmeta/writers/bibtex_writer.rb
commonmeta-ruby-3.3.5 lib/commonmeta/writers/bibtex_writer.rb