Class: NtrResults::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/ntr_results/scraper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#dateObject

Returns the value of attribute date.



2
3
4
# File 'lib/ntr_results/scraper.rb', line 2

def date
  @date
end

#locationObject

Returns the value of attribute location.



2
3
4
# File 'lib/ntr_results/scraper.rb', line 2

def location
  @location
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/ntr_results/scraper.rb', line 2

def name
  @name
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/ntr_results/scraper.rb', line 2

def url
  @url
end

#winnerObject

Returns the value of attribute winner.



2
3
4
# File 'lib/ntr_results/scraper.rb', line 2

def winner
  @winner
end

Class Method Details

.allObject



4
5
6
7
# File 'lib/ntr_results/scraper.rb', line 4

def self.all
  # scrape nationalteamroping.com
  self.scrape_events
end

.scrape_eventsObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/ntr_results/scraper.rb', line 9

def self.scrape_events
  events = []

  events << self.scrape_ntr1
  events << self.scrape_ntr2
  events << self.scrape_ntr3
  # events << self.scrape_ntr  

  events
end

.scrape_ntr1Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ntr_results/scraper.rb', line 32

def self.scrape_ntr1
  doc = Nokogiri::HTML(open("http://nationalteamroping.com/article-812-rancho-rio-qualifier.html"))

  event = self.new
  event.name = doc.search("#article-812 p")[0].text
  event.date  = doc.search("#article-812 p")[1].text
  event.location = doc.search("#article-812 p")[2].text
  event.winner = doc.search("#article-812 p")[10].text  # => "1st in Ave - 33.62 on 4, Sam Scott & John Miller  $1350"

  event
end

.scrape_ntr2Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ntr_results/scraper.rb', line 44

def self.scrape_ntr2
  doc = Nokogiri::HTML(open("http://nationalteamroping.com/article-815-tgif-4_7_17.html"))

  event = self.new
  event.name = doc.search("#article-815 p")[0].text
  event.date  = doc.search("#article-815 p")[1].text
  event.location = doc.search("#article-815 p")[2].text
  event.winner = doc.search("#article-815 p")[7].text  # => "1st in Ave - 40.31 on 4, Bruce Northrop & Richard Mayfield  $1840"

  event
end

.scrape_ntr3Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ntr_results/scraper.rb', line 56

def self.scrape_ntr3
  doc = Nokogiri::HTML(open("http://nationalteamroping.com/article-816-%25245000-sat.html"))

  event = self.new
  event.name = doc.search("#article-816 p")[0].text
  event.date  = doc.search("#article-816 p")[1].text
  event.location = doc.search("#article-816 p")[2].text
  event.winner = doc.search("#article-816 p")[7].text  # =>  "1st in Ave - 38.35 on 4, Jerry Turk & Pat Danehey  $5000"

  event
end