class SearchApnic::File
Constants
- CACHE_FILE
- HOST
- PATH
Public Instance Methods
get_path()
click to toggle source
# File lib/search_apnic/file.rb, line 10 def get_path file = cache_file fresh?(file) ? file : get end
head()
click to toggle source
# File lib/search_apnic/file.rb, line 15 def head Net::HTTP.new(HOST).head(PATH) end
Private Instance Methods
cache_file()
click to toggle source
# File lib/search_apnic/file.rb, line 39 def cache_file "#{CACHE_FILE}.#{last_modified.to_i}" end
fresh?(file)
click to toggle source
# File lib/search_apnic/file.rb, line 35 def fresh?(file) ::FileTest.exist?(file) ? true : false end
get()
click to toggle source
# File lib/search_apnic/file.rb, line 25 def get file = cache_file open(file, 'wb') do |file| open(url) do |data| file.write(data.read) end end file end
last_modified()
click to toggle source
# File lib/search_apnic/file.rb, line 43 def last_modified unless @last_modified @last_modified = Time.parse(head['last-modified']) end @last_modified end
url()
click to toggle source
# File lib/search_apnic/file.rb, line 21 def url "http://#{HOST}#{PATH}" end