Class: Headline

Inherits:
Object
  • Object
show all
Extended by:
HeadlineChoice
Defined in:
lib/nfl_top_stories/headline.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from HeadlineChoice

get_choice, get_headlines

Instance Attribute Details

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/nfl_top_stories/headline.rb', line 2

def title
  @title
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/nfl_top_stories/headline.rb', line 2

def url
  @url
end

Class Method Details

.scrape_cbsObject

——————- CBS Sports Headlines ——————- ##



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nfl_top_stories/headline.rb', line 38

def self.scrape_cbs
  main_url = "http://www.cbssports.com"
  doc = Nokogiri::HTML(open("http://www.cbssports.com/nfl"))

  i = 0
  while i < 6
    cbs_headline = self.new
    cbs_headline.title = doc.search("ul#homeArenaHeadlines span")[i].text
    cbs_headline.url = doc.search("ul#homeArenaHeadlines a")[i].attributes["href"].value
    @headlines << cbs_headline
    i += 1
  end
end

.scrape_espnObject

——————- ESPN Headlines ——————- ##



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nfl_top_stories/headline.rb', line 8

def self.scrape_espn
  main_url = "http://espn.go.com"
  doc = Nokogiri::HTML(open("http://espn.go.com/nfl/"))

  i = 0
  while i < 6
    espn_headline = self.new
    espn_headline.title = doc.search("div.headlines ul li a")[i].text
    espn_headline.url = main_url +  doc.search("div.headlines ul li a")[i].attributes["href"].value
    @headlines << espn_headline
    i += 1
  end
end

.scrape_foxObject

——————- Fox Sports Headlines ——————- ##



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nfl_top_stories/headline.rb', line 53

def self.scrape_fox
  main_url = "http://www.foxsports.com"
  doc = Nokogiri::HTML(open("http://www.foxsports.com/nfl"))

  i = 0
  while i < 6
    fox_headline = self.new
    fox_headline.title = doc.search("h3.buzzer-title")[i].text
    fox_headline.url = doc.search("div.buzzer-header a")[i].attributes["href"].value
    @headlines << fox_headline
    i += 1
  end
end

.scrape_nflObject

——————- NFL.com Headlines ——————- ##



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/nfl_top_stories/headline.rb', line 23

def self.scrape_nfl
  main_url = "http://www.nfl.com"
  doc = Nokogiri::HTML(open("http://www.nfl.com/news"))

  i = 0
  while i < 6
    nfl_headline = self.new
    nfl_headline.title = doc.search("div#headlines-latest li a")[i].text
    nfl_headline.url = main_url +  doc.search("div#headlines-latest li a")[i].attributes["href"].value
    @headlines << nfl_headline
    i += 1
  end
end

.scrape_usaObject

——————- USA Today Headlines ——————- ##



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/nfl_top_stories/headline.rb', line 68

def self.scrape_usa
  main_url = "http://www.usatoday.com"
  doc = Nokogiri::HTML(open("http://www.usatoday.com/sports/nfl"))

  i = 0
  while i < 6
    usa_headline = self.new
    usa_headline.title = doc.search("li span.js-asset-headline")[i].text
    usa_headline.url = main_url + doc.search("li a.js-asset-link")[i].attributes["href"].value
    @headlines << usa_headline
    i += 1
  end
end