Both
Module
PDFHighlights.Internal.Both — ModuleThis module contains functions that can be applied to both PDF and CSV files.
Functions
PDFHighlights.Internal.Both.get_authors — Methodget_authors(target::String) -> Vector{String}Get values from the Authors column if a CSV file is passed, or get the authors of all PDFs found recursively if a directory is passed.
Arguments
target::String: a CSV file or a directory with PDF files
Returns
Vector{String}: the authors
Throws
NotCSVorDir: the specified path does not end in.csvand is not a directory- Exceptions from:
_get_authors_from_CSV,_get_authors_from_PDF
Example
using PDFHighlights
HEADER = PDFHighlights.Internal.Constants.HEADER
path_to_pdf_dir = joinpath(pathof(PDFHighlights) |> dirname |> dirname, "test", "pdf")
(get_authors(path_to_pdf_dir) == ["Pavel Sobolev"]) |> println
_file, io = mktemp()
println(io, HEADER, '\n', ",,Susanna Kaysen,,1")
flush(io)
file = _file * ".csv"
mv(_file, file)
get_authors(file) == ["Susanna Kaysen"]PDFHighlights.Internal.Both.get_highlights — Methodget_highlights(target::String; concatenate::Bool=true) -> Vector{String}Get values from the Highlights column if a CSV file is passed, or get the highlights from a PDF file if it is passed, or get the highlights from all PDFs found recursively if a directory is passed.
Arguments
target::String: a CSV file, or a PDF file, or a directory with PDF files
Keywords
concatenate::Bool=true: iftrue, concatenate the highlights (only for PDFs)
Returns
Vector{String}: the highlights
Throws
NotCSVorPDForDir: the specified path does not end in.csvor.pdfand is not a directory- Exceptions from:
_get_highlights_from_CSV,_get_highlights_from_PDF
Example
using PDFHighlights
HEADER = PDFHighlights.Internal.Constants.HEADER
path_to_pdf_dir = joinpath(pathof(PDFHighlights) |> dirname |> dirname, "test", "pdf")
path_to_pdf = joinpath(path_to_pdf_dir, "TestPDF.pdf")
(get_highlights(path_to_pdf_dir) == get_highlights(path_to_pdf) == String[
"Highlight 1",
"Highlight 2 Highlight 3",
"Highlight 4",
"Highhighlight 5",
"6th Highhigh light-",
"High light 7",
"8th Highlight-",
]) |> println
_file, io = mktemp()
println(io, HEADER, '\n', "The world didn't stop spinning,,,,1")
flush(io)
file = _file * ".csv"
mv(_file, file)
get_highlights(file) == ["The world didn't stop spinning"]PDFHighlights.Internal.Both.get_titles — Methodget_titles(target::String) -> Vector{String}Get values from the Titles column if a CSV file is passed, or get the titles of all PDFs found recursively if a directory is passed.
Arguments
target::String: a CSV file or a directory with PDF files
Returns
Vector{String}: the titles
Throws
NotCSVorDir: the specified path does not end in.csvand is not a directory- Exceptions from:
_get_titles_from_CSV,_get_titles_from_PDF
Example
using PDFHighlights
HEADER = PDFHighlights.Internal.Constants.HEADER
path_to_pdf_dir = joinpath(pathof(PDFHighlights) |> dirname |> dirname, "test", "pdf")
(get_titles(path_to_pdf_dir) == ["A dummy PDF for tests"]) |> println
_file, io = mktemp()
println(io, HEADER, '\n', ",\"Girl, Interrupted\",,,1")
flush(io)
file = _file * ".csv"
mv(_file, file)
get_titles(file) == ["Girl, Interrupted"]