sport_headlines 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72dad286df2f6d0b59bd5748e921c97fc578f109
4
- data.tar.gz: b32b3d3d95b27ea4aa1ff639dd58e3f24099605f
3
+ metadata.gz: c4570739b5730954331ea2da8dce7ea88f5773c6
4
+ data.tar.gz: 28b40ebd16b513ab529f23ff0a0f970014ebc875
5
5
  SHA512:
6
- metadata.gz: 2b12256526bcc632458d6ceaa68af3b4141ffe2f3363c7bfa67e48967484ab4d23fc9963b1cfe2335edb26feb4ff4a54adac32c863ec24ad2416335e3607e015
7
- data.tar.gz: 6a3b96c0f0621f9788a7a8d57b40d0e9ecc09e456e3b6a115311da1fe23e5c7fe06f938e1d0bd524cf40dce6b1cf1628c4a0de34f91547a75f4ef3a463a678f9
6
+ metadata.gz: 14948ea2982ce98a0ed03bf4da39da65b4ad3718c91d4d37f478b43307d70051417ad14db83b97922e3e480013d77cc2f288896c227f6397af5716b6e4ae1278
7
+ data.tar.gz: 0c76d614001d5c52bdc0214f7d31c5bb7d685440b2a222d3967738bc6c2177980d9307608572850a3f21f3da6fca7c1e48473841fd5e0d159bb6b95819e8aa95
@@ -7,7 +7,7 @@ class SportHeadlines::CLI
7
7
  end
8
8
 
9
9
  def start
10
- # sites = SportHeadlines::Site.all
10
+ sites = SportHeadlines::Site.all
11
11
  scraper = SportHeadlines::Scraper
12
12
  puts ""
13
13
  input = nil
@@ -18,19 +18,13 @@ class SportHeadlines::CLI
18
18
  puts ""
19
19
  input = gets.strip
20
20
  if input.to_i.between?(1,sites.size)
21
- site = SportHeadlines::Site.find(input)
22
- site.scrape_headlines!
23
- # scraper.scrape_site_headlines(sites[input.to_i-1])
24
-
21
+ scraper.scrape_site_headlines(sites[input.to_i-1])
25
22
  puts "Select an article to read its content."
26
23
  puts ""
27
- site.list_articles
24
+ sites[input.to_i-1].list_articles
28
25
  article_input = gets.strip
29
- article = site.scrape_article(article_input) # preps the article, and returns the instance of the article
30
- # scraper.scrape_article(sites[input.to_i-1].articles[article_input.to_i - 1])
31
- article.print_content
32
-
33
- # sites[input.to_i-1].articles[article_input.to_i - 1].print_content
26
+ scraper.scrape_article(sites[input.to_i-1].articles[article_input.to_i - 1])
27
+ sites[input.to_i-1].articles[article_input.to_i - 1].print_content
34
28
  end
35
29
  end
36
30
  end
@@ -1,7 +1,6 @@
1
1
  module SportHeadlines::Scraper
2
2
 
3
3
  def self.scrape_site_headlines(site)
4
- binding.pry
5
4
  doc = Nokogiri::HTML(open(site.site_url))
6
5
  site.clear_articles
7
6
  if site.site_name == "ESPN"
@@ -9,9 +8,8 @@ module SportHeadlines::Scraper
9
8
  new_article ||= SportHeadlines::Article.new
10
9
  new_article.title ||= headline.search("a").text
11
10
  new_article.article_url ||= site.site_url + headline.search("a").attribute("href").value
12
-
13
- # site.add_article(new_article)
14
- new_article.site = site # has two jobs, first, association the site with the article, then inform the site of the new article
11
+ site.add_article(new_article)
12
+ new_article.site = site
15
13
  end
16
14
  elsif site.site_name == "Bleacher Report"
17
15
  doc.search(".headlineArticles li").each do |headline|
@@ -6,7 +6,7 @@ class SportHeadlines::Site
6
6
  "Bleacher Report" => "http://bleacherreport.com/",
7
7
  "Pro Football Talk" => "http://profootballtalk.nbcsports.com/"
8
8
  }
9
- #
9
+
10
10
  @@all = []
11
11
 
12
12
  def initialize(site_name, site_url)
@@ -31,9 +31,7 @@ class SportHeadlines::Site
31
31
  end
32
32
 
33
33
  def add_article(article)
34
- # self is the site, article is the article
35
34
  self.articles << article
36
- article.site = self # reciprocal relationship - when we add ana rticle to a site, we also inform the article of it's relationship to this site
37
35
  end
38
36
 
39
37
  def list_articles
@@ -42,23 +40,4 @@ class SportHeadlines::Site
42
40
  end
43
41
  end
44
42
 
45
- def self.find(input)
46
- self.all[input.to_i-1]
47
- end
48
-
49
- def scrape_headlines!
50
- SportHeadlines::Scraper.scrape_site_headlines(self)
51
- end
52
-
53
- def find_article(input)
54
- self.articles[input.to_i - 1]
55
- end
56
-
57
- def scrape_article(input)
58
- # we want this method to both scrape the article and return it.
59
- article = self.find_article(input)
60
- SportHeadlines::Scraper.scrape_article(article)
61
- article
62
- end
63
-
64
43
  end
@@ -1,3 +1,3 @@
1
1
  module SportHeadlines
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sport_headlines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - cernanb