Class: BibTeX::Entry::BibTeXMLConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/bibtex/entry/bibtexml_converter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bibtex, options = {}) ⇒ BibTeXMLConverter

Returns a new instance of BibTeXMLConverter.



8
9
10
11
# File 'lib/bibtex/entry/bibtexml_converter.rb', line 8

def initialize(bibtex, options = {})
  @bibtex = bibtex
  @options = options
end

Class Method Details

.convert(bibtex, options = {}) ⇒ Object



4
5
6
# File 'lib/bibtex/entry/bibtexml_converter.rb', line 4

def self.convert(bibtex, options = {})
  new(bibtex, options).convert!
end

Instance Method Details

#convert!Object



13
14
15
16
17
18
19
20
21
# File 'lib/bibtex/entry/bibtexml_converter.rb', line 13

def convert!
  xml = REXML::Element.new('bibtex:entry')
  xml.attributes['id'] = bibtex.key

  fields

  xml.add_element(entry)
  xml
end

#fieldsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bibtex/entry/bibtexml_converter.rb', line 23

def fields
  bibtex.fields.each do |key, value|
    field = REXML::Element.new("bibtex:#{key}")

    if options[:extended] && value.name?
      value.each { |n| field.add_element(n.to_xml) }
    else
      field.text = value.to_s(options)
    end

    entry.add_element(field)
  end
end