class Sec::Firms::Downloader
Attributes
root_path[R]
url[R]
Public Class Methods
new(url)
click to toggle source
# File lib/sec/firms/downloader.rb, line 11 def initialize(url) @url = url @root_path = "#{Sec::Firms.configuration.root_path}/downloads/" end
Public Instance Methods
content()
click to toggle source
# File lib/sec/firms/downloader.rb, line 16 def content if File.exist?(file_name) read_file else save_to_file end end
file_name()
click to toggle source
# File lib/sec/firms/downloader.rb, line 24 def file_name "#{root_path}#{Digest::MD5.hexdigest(url)}.xml" end
Private Instance Methods
read_file()
click to toggle source
# File lib/sec/firms/downloader.rb, line 30 def read_file IO.read(file_name) end
save_to_file()
click to toggle source
# File lib/sec/firms/downloader.rb, line 34 def save_to_file request = Net::HTTP.get_response(URI.parse(url)) if request.code == '200' FileUtils.mkdir_p(root_path) File.write(file_name, request.body) request.body end end