class RandomShakespeare::Downloader
Constants
- FILENAME
- URL
Public Class Methods
new(filename = nil)
click to toggle source
# File lib/random_shakespeare/downloader.rb, line 8 def initialize(filename = nil) @filename = filename || FILENAME end
Public Instance Methods
file()
click to toggle source
# File lib/random_shakespeare/downloader.rb, line 12 def file download unless File.exist? @filename open_file end
Private Instance Methods
download()
click to toggle source
# File lib/random_shakespeare/downloader.rb, line 19 def download begin f = open(URL) IO.copy_stream(f, @filename) rescue Exception => e raise "Check your connection: #{e.inspect}" end end
open_file()
click to toggle source
# File lib/random_shakespeare/downloader.rb, line 28 def open_file begin File.open(@filename, &:read) rescue Exception => e raise "Unable to open file: #{e.inspect}" end end