class FootballNow::DB

Public Class Methods

file_path_from(url_array) click to toggle source
# File lib/db.rb, line 45
def self.file_path_from(url_array)
  url_array[1] == nil ? "#{FootballNow::DB_PATH}/leagues.html" :
    "#{FootballNow::DB_PATH}/#{url_array[2]}-#{url_array[3]}.html"
end
get_html(url) click to toggle source
# File lib/db.rb, line 5
def self.get_html(url)
  url_array = strip_url(url)
  file_path = file_path_from(url_array)

  if File.exists?(file_path) && not_expired?(file_path)
    File.read(file_path)
  else
    return_html(url_array, url)
  end
end
get_leagues_html(url) click to toggle source
# File lib/db.rb, line 16
def self.get_leagues_html(url)
  page_html = open(url).read
  url_array = strip_url(url)
  save_as_file(url_array, page_html)
  page_html
end
get_results_html(url) click to toggle source
# File lib/db.rb, line 32
def self.get_results_html(url)
  visit(url)
  sleep(1)
  click_link("Show more matches")
  sleep(2)
  click_link("Show more matches")
  sleep(2)

  url_array = strip_url(url)
  save_as_file(url_array, page.html)
  page.html
end
get_standings_html(url) click to toggle source
# File lib/db.rb, line 23
def self.get_standings_html(url)
  visit(url)
  sleep(1)

  url_array = strip_url(url)
  save_as_file(url_array, page.html)
  page.html
end
not_expired?(file_path) click to toggle source
# File lib/db.rb, line 50
def self.not_expired?(file_path)
  Time.now - File.mtime(file_path) < FootballNow::TIME_OUT
end
return_html(url_array, url) click to toggle source
# File lib/db.rb, line 64
def self.return_html(url_array, url)
  url_array[1] == nil ? get_leagues_html(url) : send("get_#{url_array[3]}_html", url)
end
save_as_file(url_array, html) click to toggle source
# File lib/db.rb, line 58
def self.save_as_file(url_array, html)
  leagues_file = open(file_path_from(url_array), "w")
  leagues_file.write(html)
  leagues_file.close
end
strip_url(url) click to toggle source
# File lib/db.rb, line 54
def self.strip_url(url)
  url.gsub("http://", "").split("/")
end