CrossRef / pdfextract

MOVED TO https://gitlab.com/crossref/pdfextract
https://gitlab.com/crossref/pdfextract
MIT License
508 stars 89 forks source link

Title.rb line 30 error: undefined method `[]' for nil:NilClass #28

Closed jgrossi closed 9 years ago

jgrossi commented 9 years ago

Hi!

I'm using pdf-extract to get some papers data and everything was working well, but for some PDF papers I'm receiving this error message: undefined method '[]' for nil:NilClass on line 30 of the file lib/analysis/titles.rb, like above:

titles.sort_by! { |r| -r[:line_height] }
tallest_line = titles.first[:line_height] # this is line 30 --> titles is an empty array []
title_slop = tallest_line - (tallest_line * pdf.settings[:title_slop])
titles.reject! { |r| r[:line_height] < title_slop }

Any idea how to solve this?

Thanks!

jgrossi commented 9 years ago

Solved changed the code according pull request #29. When title is not found the titles variable is nil, so, just check before if it is not `nil.