Class: BibliographicalImporter::BibTex::Reader

Inherits:
Object
  • Object
show all
Includes:
AbstractReader, Enumerable
Defined in:
lib/bibliographical_importer/bibtex.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bibtex_bibliography) ⇒ Reader

Returns a new instance of Reader



214
215
216
217
# File 'lib/bibliographical_importer/bibtex.rb', line 214

def initialize(bibtex_bibliography)
  @bb=bibtex_bibliography
  parse_records
end

Instance Attribute Details

#bbObject (readonly)

Returns the value of attribute bb



208
209
210
# File 'lib/bibliographical_importer/bibtex.rb', line 208

def bb
  @bb
end

#recordsObject (readonly)

Returns the value of attribute records



209
210
211
# File 'lib/bibliographical_importer/bibtex.rb', line 209

def records
  @records
end

Class Method Details

.fix_string(string) ⇒ Object

Deprecated.

for bibtex-ruby>=4.4.5

If ID for a bibtex contains a single quote, class just fail This method just delete the quote, until Bibtex class fix it



226
227
228
229
230
231
232
233
234
# File 'lib/bibliographical_importer/bibtex.rb', line 226

def self.fix_string(string)
  string.each_line.map { |line|
    if line=~/^\s*\@.+\{(.+),$/
      line.gsub("'","")
    else
      line
    end
  }.join("\n")
end

.open(filename) ⇒ Object



219
220
221
222
# File 'lib/bibliographical_importer/bibtex.rb', line 219

def self.open(filename)
  b=BibTeX.open(filename, :strip => false)
  Reader.new(b)
end

.parse(string, bib_db = nil) ⇒ Object

Parse a BibTex file

Parameters:

  • string (String)

    BibTex text

  • bib_db (String) (defaults to: nil)

    NOT USED

Returns:

  • BibTex::Reader



239
240
241
242
243
244
245
# File 'lib/bibliographical_importer/bibtex.rb', line 239

def self.parse(string, bib_db=nil)
  @bib_db=bib_db
  # Scopus generates bibtex with quotes on names. That brokes Bibtex package
  #string_fixed=fix_string(string)
  b=BibTeX.parse(string, :strip => false)
  Reader.new(b)
end

Instance Method Details

#each(&block) ⇒ Object



210
211
212
# File 'lib/bibliographical_importer/bibtex.rb', line 210

def each(&block)
  @records.each(&block)
end

#parse_recordsObject



247
248
249
# File 'lib/bibliographical_importer/bibtex.rb', line 247

def parse_records
  @records=@bb.map {|r| BibTex::Record.create(r)}
end