class BibTeX::Entry::BibTeXMLConverter

Attributes

bibtex[R]
options[R]

Public Class Methods

convert(bibtex, options = {}) click to toggle source
# File lib/bibtex/entry/bibtexml_converter.rb, line 4
def self.convert(bibtex, options = {})
  new(bibtex, options).convert!
end
new(bibtex, options = {}) click to toggle source
# File lib/bibtex/entry/bibtexml_converter.rb, line 8
def initialize(bibtex, options = {})
  @bibtex = bibtex
  @options = options
end

Public Instance Methods

convert!() click to toggle source
# 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
fields() click to toggle source
# 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

Protected Instance Methods

entry() click to toggle source
# File lib/bibtex/entry/bibtexml_converter.rb, line 41
def entry
  @entry ||= REXML::Element.new("bibtex:#{bibtex.type}")
end