Closed joshleitzel closed 8 years ago
I have absolutely no idea why I did it like that, but since I have absolutely no idea I think the best approach would be to check Iterator.constants.include?(level.capitalize)
and bail out if it's false
.
I actually think just removing the rescue
clause and adding Line
and Paragraph
would be the best solution. Since you control the internal API and only %w(block paragraph line word symbol)
get the methods defined, there really shouldn't be any error conditions here.
I'd be happy to make the change if you like. :)
Agree, go for it :panda_face:
Done!
Merged, thank you for the patience :panda_face:
First just want to say thanks for your great library, which has made working with Tesseract much easier for me!
I ran into a small bug because I'm using this gem in a Rails project where I've got models named after document sections, including
Paragraph
andLine
. I was baffled because when I tried to invoke those iterators,engine.paragraphs_for
andengine.lines_for
, I was seeing ActiveRecord errors coming back, which made no sense.I traced this to the iterator API, where it falls back on the
Element
class if the constant (Paragraph
orLine
) isn't found. In my case,Paragraph
andLine
were found—it's just that they were my ActiveRecord models.This is easily fixed by including those classes explicitly. With this simple modification all is well in my Rails project again. However, I think a better long-term solution might be to get rid of the
const_get
/rescue
scheme altogether.Let me know if you want me to change anything here.