ncaa_scrape 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ncaa_scrape.rb +28 -32
  3. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc6527d556841a81b7e59c2b6c684d925c8c55ec
4
- data.tar.gz: 765932a9b7d434ffcd333131b5e9ecf72404b059
3
+ metadata.gz: 960216b48fc4b052115ae15446f45c4c0a4f1f15
4
+ data.tar.gz: 894514ada6e1226787af61771457705b8f198b66
5
5
  SHA512:
6
- metadata.gz: deac7e8f54a1fd7fcb8b13780d6905573485c13d38f68537207465d1635e3a1169526f90f13cc64363bd2ec4629a72f42db086dc63570561a55ea687b10905f6
7
- data.tar.gz: a35ea545330145e95dce6a48d081026de5b1be456e0f0a6b795b6309e13961f12b659afa5362a5cdaa7716dd2ba4f3f1d271868a80318393dc13b5ee6253cfd6
6
+ metadata.gz: 6b4c2cf8a0f47ee696406dd8fd2b73b04bd3d4928e04e6e20ee4394d372082d75bc3b7d63fd4f46a00fcb46251146e3ffa1184abb6da4558e5966f9e8c4b8785
7
+ data.tar.gz: f7cabcc5a5a56a51f1369bb2ac8747c14e768410a5228853df00be1fb328870e1d07b6048d0ff2c2ba00c0fdb7b4121e5ec4d977cfc423806aeb87e96c199c27
@@ -5,54 +5,50 @@ class NCAABasketball
5
5
  attr_reader :division_one_data
6
6
 
7
7
  def initialize
8
- @rankings_page = Nokogiri::HTML(open('http://www.ncaa.com/rankings/basketball-men/d1/ncaa-mens-basketball-rpi'))
9
- @division_one_data = team_names.zip(team_conferences, team_records)
10
- end
11
-
12
- def css_attribute(column)
13
- ".ncaa-rankings-table > tbody > tr > td[#{column}]"
8
+ @standings_page = Nokogiri::HTML(open('http://www.ncaa.com/standings/basketball-men/d1'))
9
+ @division_one_data = team_names.zip(wins).to_h
14
10
  end
15
11
 
16
12
  def team_names
17
13
  names = []
18
- @rankings_page.css(css_attribute(3)).each { |row| names << row.content }
14
+ raw_data.each { |row| names << row[0] }
19
15
  names
20
16
  end
21
17
 
22
- def team_conferences
23
- conferences = []
24
- @rankings_page.css(css_attribute(4)).each { |row| conferences << row.content }
25
- conferences
18
+ def team_wins(team_name)
19
+ @division_one_data.include?(team_name) ? @division_one_data[team_name] : 0
20
+ end
21
+
22
+ def pick_five_total(*teams)
23
+ teams.inject(0) { |total, team| total + team_wins(team) }
26
24
  end
27
25
 
28
- def team_records
29
- records = []
30
- @rankings_page.css(css_attribute(5)).each { |row| records << row.content }
31
- records
26
+ private
27
+
28
+ def even_rows
29
+ @standings_page.css('.even')
32
30
  end
33
31
 
34
- def team_rankings
35
- rankings = {}
36
- @division_one_data.each_with_index { |team, index| rankings[index + 1] = team }
37
- rankings
32
+ def odd_rows
33
+ @standings_page.css('.odd')
38
34
  end
39
35
 
40
- def team_record(team_name)
41
- selected_team = @division_one_data.select { |team| team.include?(team_name) }
42
- selected_team.flatten.last
36
+ def rows
37
+ even_rows + odd_rows
43
38
  end
44
39
 
45
- def team_wins(team_name)
46
- if team_record(team_name)
47
- team_record(team_name).partition('-').first.to_i
48
- else
49
- 0
50
- end
40
+ def raw_data
41
+ data = []
42
+ rows.each { |row| data << row.text }
43
+ data.delete_if { |row| row.include?('WLPCT') }
44
+ data.map { |row| row.partition(/\d/) }
51
45
  end
52
46
 
53
- def pick_five_total(*teams)
54
- teams.inject(0) do |total, team|
55
- total + team_wins(team)
56
- end
47
+ def wins
48
+ data = []
49
+ rows.each { |row| data << row.css('.conference-boundary').text }
50
+ data.reject { |item| item == 'W' }
51
+ data.map { |item| item.to_i}
57
52
  end
53
+
58
54
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncaa_scrape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jen Trudell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-06 00:00:00.000000000 Z
11
+ date: 2016-11-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: As of January 2016, ncaa_scrape lets you scrape RPI rankings for Division
14
- I Men's college basketball from the NCAA website. This gem uses nokogiri to scrape
15
- data from ncaa.com; if the NCAA website changes, this gem may fail. For more information,
16
- see readme at https://github.com/jtrudell/NCAA-Basketball-Scraper
13
+ description: As of November 2016, ncaa_scrape lets you scrape team names and team
14
+ wins for Division I Men's college basketball from the NCAA website. This gem uses
15
+ nokogiri to scrape data from ncaa.com; if the NCAA website changes, this gem may
16
+ fail. For more information, see readme at https://github.com/jtrudell/NCAA-Basketball-Scraper
17
17
  email: jtrudell@gmail.com
18
18
  executables: []
19
19
  extensions: []
@@ -40,8 +40,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  version: '0'
41
41
  requirements: []
42
42
  rubyforge_project:
43
- rubygems_version: 2.4.6
43
+ rubygems_version: 2.5.1
44
44
  signing_key:
45
45
  specification_version: 4
46
- summary: Scrapes NCAA Men's Div I Basketball RPI Rankings from NCAA.com
46
+ summary: Scrapes NCAA Men's Div I Basketball STandings from NCAA.com
47
47
  test_files: []