class BibTeX::Bibliography

Attributes

filepath[RW]

Public Class Methods

from_bcf(path) click to toggle source
# File lib/bibtex_munge/bcf.rb, line 16
def from_bcf(path)
  File.open(path, "r") do |f|
    @bcf = Nokogiri::XML(f).remove_namespaces!
  end
  filepath = File.dirname(path) + "/" + @bcf.at_xpath("//datasource").content
  citekeys = @bcf.xpath("//citekey", 'bcf'=>'URI').map(&:content)
  bib = open(filepath, :filter => 'latex')
  bib.filepath = filepath
  trim_unnecessary_entries!(bib, citekeys)
  bib.sort! { |a,b| a.author <=> b.author }
  bib.extend(BibtexMunge)
  bib.fix_everything!
  return bib
end
trim_unnecessary_entries!(bib, citekeys) click to toggle source
# File lib/bibtex_munge/bcf.rb, line 8
def trim_unnecessary_entries!(bib, citekeys)
  bib.entries.each do |k,v|
    if !citekeys.include? k 
      bib.delete(k)
    end
  end
end