Class: FootballNow::DB
Class Method Summary collapse
- .file_path_from(url_array) ⇒ Object
- .get_html(url) ⇒ Object
- .get_leagues_html(url) ⇒ Object
- .get_results_html(url) ⇒ Object
- .get_standings_html(url) ⇒ Object
- .not_expired?(file_path) ⇒ Boolean
- .return_html(url_array, url) ⇒ Object
- .save_as_file(url_array, html) ⇒ Object
- .strip_url(url) ⇒ Object
Class Method Details
.file_path_from(url_array) ⇒ Object
45 46 47 48 |
# 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) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# 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) ⇒ Object
16 17 18 19 20 21 |
# 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) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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) ⇒ Boolean
50 51 52 |
# 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) ⇒ Object
64 65 66 |
# 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) ⇒ Object
58 59 60 61 62 |
# 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) ⇒ Object
54 55 56 |
# File 'lib/db.rb', line 54 def self.strip_url(url) url.gsub("http://", "").split("/") end |