Skip to content

Commit

Permalink
Add Paper#save for saving PDFs
Browse files Browse the repository at this point in the history
  • Loading branch information
eonu committed Jan 26, 2021
1 parent 78972d4 commit d3cd13b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/arx/entities/paper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,19 @@ def ==(paper)
end
end

# Downloads the paper and saves it in PDF format at the specified path.
#
# @param path [String] The file path to store the PDF at.
def save(path)
begin
pdf_content = URI.open(pdf_url).read
File.open(path, 'wb') {|f| f.write pdf_content}
rescue
File.delete(path) if File.file? path
raise
end
end

inspector *ATTRIBUTES
end
end
17 changes: 17 additions & 0 deletions spec/arx/entities/paper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,21 @@
it { is_expected.not_to eq 1 }
end
end
context '#save' do
context 'with an existing directory' do
# TODO
end
context 'with a non-existing directory' do
# TODO
end
context 'with an existing file path' do
# TODO
end
context 'with a non-existing file path' do
# TODO
end
context 'with an invalid file path type' do
# TODO
end
end
end

0 comments on commit d3cd13b

Please sign in to comment.