Class: BibTeX::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/bibtex_parser.rb

Class Method Summary collapse

Class Method Details

.parse_bibtex(bibtex_string) ⇒ Object



141
142
143
144
145
146
# File 'lib/bibtex_parser.rb', line 141

def Parser.parse_bibtex(bibtex_string)

  stream = StringIO.new(bibtex_string)
  return parse_stream(stream)
  
end

.parse_bibtex_file(filename) ⇒ Object



148
149
150
151
152
153
# File 'lib/bibtex_parser.rb', line 148

def Parser.parse_bibtex_file(filename)

  f = File.open(filename)
  return parse_stream(f)
  
end

.parse_stream(stream) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/bibtex_parser.rb', line 155

def Parser.parse_stream(stream)

  blocks = []
  entries = []

  while (!stream.eof?)
    line = stream.gets

    if ((line =~ /^\s*@[[:alpha:]]+/) && (line !~ /@(string|preamble)/i))
      blocks << extract_block(stream,line)
    end

  end

  blocks.each do |block|
    entries << BibTeX::Entry.new(block)
  end

  return entries

end