-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds ability to specify pdftotext options #31
Conversation
* Adds test for `-table` option that produces tabular output
@philgooch thank you for the PR! I still need to pull it down and try it out but excited to see this 🤘 To be future proof I think I'd like to see options be a hash instead of an array, maybe with a |
* Makes `Page.text()` options a hash where `flags` takes an array of `pdftotext` flags
@jonmagic good idea, I've just pushed an update. One thing I've found is that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of small changes and then I think this is ready to 🚢
lib/grim/page.rb
Outdated
@@ -47,11 +47,11 @@ def save(path, options={}) | |||
# pdf[1].text | |||
# # => "This is text from slide 2.\n\nAnd even more text from slide 2." | |||
# | |||
# pdf[1].text(options=["-table"]) | |||
# pdf[1].text(options={flags: ["-table"]}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just be:
# pdf[1].text({flags: ["-table"]})
lib/grim/page.rb
Outdated
# Returns a String. | ||
# | ||
def text(options=[]) | ||
command = [@pdftotext_path, "-enc", "UTF-8", "-f", @number, "-l", @number, options.join(", "), Shellwords.escape(@pdf.path), "-"].join(' ') | ||
def text(options={flags: []}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should change to something more like:
def text(options={})
flags = options.fetch(:flags, [])
command_parts = [@pdftotext_path, "-enc", "UTF-8", "-f", @number, "-l", @number]
command_parts += flags if flags.length > 0
command_parts += [Shellwords.escape(@pdf.path), "-"]
command = command_parts.join(' ')
spec/lib/grim/page_spec.rb
Outdated
@@ -53,7 +53,7 @@ | |||
|
|||
it "should extract tabular data with the -table option" do | |||
pdf = Grim::Pdf.new(fixture_path("table.pdf")) | |||
expect(pdf[0].text(options=["-table"])).to \ | |||
expect(pdf[0].text(options={flags: ["-table"]})).to \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can drop the options=
here similar to the comment above.
@jonmagic thanks for reviewing the PR, changes made as requested 😸 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent ✨
-table
option that produces tabular output