espn-fantasy-news 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{espn-fantasy-news}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Doug Petkanics"]
12
- s.date = %q{2010-09-17}
12
+ s.date = %q{2010-09-18}
13
13
  s.description = %q{ESPN fantasy football has a list of players in their Universe, and it provides news updates on said players. This is a utility library used to scrape the data for use in other applications}
14
14
  s.email = %q{petkanics@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "lib/espn_fantasy_news/news.rb",
26
26
  "lib/espn_fantasy_news/parser.rb",
27
27
  "lib/espn_fantasy_news/player.rb",
28
+ "lib/espn_fantasy_news/team.rb",
28
29
  "test/suite.rb",
29
30
  "test/test_parser.rb"
30
31
  ]
@@ -13,4 +13,5 @@ directory = File.expand_path(File.dirname(__FILE__))
13
13
 
14
14
  require File.join(directory, 'espn_fantasy_news', 'player')
15
15
  require File.join(directory, 'espn_fantasy_news', 'news')
16
+ require File.join(directory, 'espn_fantasy_news', 'team')
16
17
  require File.join(directory, 'espn_fantasy_news', 'parser')
@@ -4,6 +4,7 @@ module ESPNFantasyNews
4
4
 
5
5
  class Parser
6
6
 
7
+ # Load the entire universe of ESPN players
7
8
  def self.load_all_players
8
9
  offset = 0
9
10
  res = []
@@ -15,6 +16,7 @@ module ESPNFantasyNews
15
16
  res
16
17
  end
17
18
 
19
+ # Load all the players at the url
18
20
  def self.players_from_url(url)
19
21
  doc = Nokogiri::HTML(open(url))
20
22
  player_attributes = doc.css('.pncPlayerRow').collect do |x|
@@ -34,10 +36,12 @@ module ESPNFantasyNews
34
36
  player_attributes
35
37
  end
36
38
 
39
+ # Return all the latest news stories
37
40
  def self.load_all_news
38
41
  self.news_from_url(ESPNFantasyNews::NEWS_ENDPOINT)
39
42
  end
40
43
 
44
+ # Return all the news stories from the given url
41
45
  def self.news_from_url(url)
42
46
  doc = Nokogiri::HTML(open(url))
43
47
  news_attributes = doc.css('tr.tableBody').collect do |player_row|
@@ -49,6 +53,21 @@ module ESPNFantasyNews
49
53
  news_attributes
50
54
  end
51
55
 
56
+ # Return an array of espn player ids for the players on the team at URL
57
+ def self.load_team_player_ids(url)
58
+ ids = []
59
+ doc = Nokogiri::HTML(open(url))
60
+ player_row = doc.css('.pncPlayerRow').each do |row|
61
+ link = row.css('a')[0]
62
+ if link
63
+ player_id = link.get_attribute('playerid').to_i
64
+ ids << player_id
65
+ end
66
+ end
67
+ name = self.parse_team_name(doc.css('title').text)
68
+ Team.new(name, ids)
69
+ end
70
+
52
71
  private
53
72
 
54
73
  # It isn't a space that seperates the team and position, it's ascii char 194 for some reason?
@@ -77,7 +96,16 @@ module ESPNFantasyNews
77
96
  "D" => "D/ST"
78
97
  }
79
98
  end
80
-
99
+
100
+ def self.parse_team_name(long_name)
101
+ dash_pos = long_name =~ /-/
102
+ if dash_pos
103
+ long_name[0, dash_pos - 1]
104
+ else
105
+ long_name
106
+ end
107
+ end
108
+
81
109
  end
82
110
 
83
111
  end
@@ -0,0 +1,15 @@
1
+ module ESPNFantasyNews
2
+ class Team
3
+ attr_reader :name, :espn_player_ids
4
+
5
+ def initialize(name, espn_player_ids)
6
+ @name = name
7
+ @espn_player_ids = espn_player_ids
8
+ end
9
+
10
+ def to_s
11
+ self.name
12
+ end
13
+
14
+ end
15
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: espn-fantasy-news
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Doug Petkanics
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-17 00:00:00 -04:00
18
+ date: 2010-09-18 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,7 @@ files:
50
50
  - lib/espn_fantasy_news/news.rb
51
51
  - lib/espn_fantasy_news/parser.rb
52
52
  - lib/espn_fantasy_news/player.rb
53
+ - lib/espn_fantasy_news/team.rb
53
54
  - test/suite.rb
54
55
  - test/test_parser.rb
55
56
  has_rdoc: true