12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/anystyle/format/bibtex.rb', line 12
def format_bibtex(dataset, **opts)
require 'bibtex'
b = ::BibTeX::Bibliography.new
format_hash(dataset).each do |hash|
flatten_values hash, skip: Normalizer::Names.keys
hash[:bibtex_type] = TYPES[hash[:type]] || hash[:type] || 'misc'
hash.delete :type
case hash[:bibtex_type]
when 'article'
rename_value hash, :'container-title', :journal
rename_value hash, :issue, :number
when 'techreport'
rename_value hash, :publisher, :institution
when 'thesis'
rename_value hash, :publisher, :school
end
Normalizer::Names.keys.each do |role|
names_to_bibtex hash, role
end
rename_value hash, :'collection-title', :series
rename_value hash, :'container-title', :booktitle
rename_value hash, :accessed, :urldate
rename_value hash, :genre, :type
rename_value hash, :location, :address
b << ::BibTeX::Entry.new(hash)
end
b
end
|