Skip to content
This repository has been archived by the owner on Nov 29, 2019. It is now read-only.

Commit

Permalink
Fixing undefined method [] for nil:NilClass error
Browse files Browse the repository at this point in the history
When extracting some PDF papers you can get the `error: undefined method []' for nil:NilClass` error on `lib/analysis/titles.rb` file on line 30. The fix is to verify before if there is some title inside `titles` variable before check.
  • Loading branch information
Junior Grossi committed Jun 16, 2015
1 parent 719e176 commit 0be525b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/pdf/extract/analysis/titles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ def self.include_in pdf

# be no less tall than a factor of the tallest text,
titles.sort_by! { |r| -r[:line_height] }
tallest_line = titles.first[:line_height]
title_slop = tallest_line - (tallest_line * pdf.settings[:title_slop])
titles.reject! { |r| r[:line_height] < title_slop }
if not titles.count.zero?
tallest_line = titles.first[:line_height]
title_slop = tallest_line - (tallest_line * pdf.settings[:title_slop])
titles.reject! { |r| r[:line_height] < title_slop }
end

# be on the earliest page with text,
titles.sort_by! { |r| r[:page] }
first_page = titles.first[:page]
titles.reject! { |r| r[:page] != first_page }
if not titles.count.zero?
first_page = titles.first[:page]
titles.reject! { |r| r[:page] != first_page }
end

# be the highest of the above.
titles.sort_by! { |r| -r[:y] }
Expand Down

0 comments on commit 0be525b

Please sign in to comment.