Class: AtpScraper::Html

Inherits:
Object
  • Object
show all
Defined in:
lib/atp_scraper/html.rb

Overview

Get and parse html from atpworldtour.com

Constant Summary collapse

BASE =
"http://www.atpworldtour.com"

Class Method Summary collapse

Class Method Details

.get(uri) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/atp_scraper/html.rb', line 12

def self.get(uri)
  charset = nil
  html = open(BASE + uri) do |f|
    charset = f.charset
    f.read
  end
  { html: html, charset: charset }
end

.get_and_parse(uri) ⇒ Object



7
8
9
10
# File 'lib/atp_scraper/html.rb', line 7

def self.get_and_parse(uri)
  html = get(uri)
  parse(html[:html], html[:charset])
end

.parse(html, charset) ⇒ Object



21
22
23
# File 'lib/atp_scraper/html.rb', line 21

def self.parse(html, charset)
  Nokogiri::HTML.parse(html, nil, charset)
end