# File lib/bibtex/entry/citeproc_converter.rb, line 51 def self.convert(bibtex, options = {}) new(bibtex, options).convert! end
# File lib/bibtex/entry/citeproc_converter.rb, line 55 def initialize(bibtex, options = {}) @bibtex = bibtex @options = { quotes: [] }.merge(options) end
# File lib/bibtex/entry/citeproc_converter.rb, line 78 def conferences return unless [:conference, :proceedings, :inproceedings].include?(bibtex.type) if bibtex.field?(:organization) && bibtex.field?(:publisher) hash['authority'] = bibtex[:organization] hash['publisher'] = bibtex[:publisher] end if bibtex.field? :address hash['event-place'] = bibtex[:address] end end
# File lib/bibtex/entry/citeproc_converter.rb, line 60 def convert! bibtex.parse_names bibtex.parse_month bibtex.each_pair do |key, value| convert key, value end bibtex.inherited_fields.each do |key| convert key, bibtex.parent.provide(key) end methods = self.class.instance_methods(false) - [:convert!, :hash] methods.each { |m| send(m) } hash end
# File lib/bibtex/entry/citeproc_converter.rb, line 96 def date case when bibtex.field?(:date) hash['issued'] = { 'date-parts' => bibtex.date.to_s.split('/').map { |part| part.split('-').map(&:to_i) } } when bibtex.field?(:year) case bibtex[:year].to_s when /^\d+$/ parts = [bibtex[:year].to_s] if bibtex.field?(:month) parts.push BibTeX::Entry::MONTHS.find_index(bibtex[:month].to_s.intern) parts[1] = parts[1] + 1 unless parts[1].nil? if bibtex.field?(:day) parts.push bibtex[:day] end end hash['issued'] = { 'date-parts' => [parts.compact.map(&:to_i)] } else hash['issued'] = { 'literal' => bibtex[:year].to_s } end else # no date present end end
# File lib/bibtex/entry/citeproc_converter.rb, line 129 def key hash['id'] = bibtex.key.to_s end
# File lib/bibtex/entry/citeproc_converter.rb, line 91 def techreport return unless [:techreport, :report].include?(bibtex.type) hash['number'] = bibtex[:number].to_s if bibtex.field? :number end
# File lib/bibtex/entry/citeproc_converter.rb, line 133 def type hash['type'] = CSL_TYPES[bibtex.type].to_s return if hash.key?('genre') case bibtex.type when :mastersthesis hash['genre'] = "Master's thesis" when :phdthesis hash['genre'] = 'PhD thesis' end end
# File lib/bibtex/entry/citeproc_converter.rb, line 149 def convert(key, value) return if BibTeX::Entry::DATE_FIELDS.include?(key) cp_key = CSL_FILTER[key].to_s if hash.key?(cp_key) hash[key] = value.to_citeproc(options) else hash[cp_key] = value.to_citeproc(options) end end
# File lib/bibtex/entry/citeproc_converter.rb, line 161 def hash @hash ||= {} end