Class: NFLFantasyScraper
- Inherits:
-
Object
- Object
- NFLFantasyScraper
- Defined in:
- lib/nfl_fantasy_scraper.rb
Instance Method Summary collapse
- #available_players ⇒ Object
-
#initialize ⇒ NFLFantasyScraper
constructor
A new instance of NFLFantasyScraper.
- #login ⇒ Object
- #my_team ⇒ Object
- #my_team_player_names ⇒ Object
- #print_table ⇒ Object
- #scrape_opponents ⇒ Object
- #scrape_points ⇒ Object
Constructor Details
#initialize ⇒ NFLFantasyScraper
Returns a new instance of NFLFantasyScraper.
11 12 13 |
# File 'lib/nfl_fantasy_scraper.rb', line 11 def initialize @mechanize = Mechanize.new end |
Instance Method Details
#available_players ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nfl_fantasy_scraper.rb', line 65 def available_players players = [] players << add_available_players next_page players << add_available_players next_page players << add_available_players players.flatten - [" ", nil] end |
#login ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nfl_fantasy_scraper.rb', line 15 def login login_page = @mechanize.get(NFL_URL) form = @mechanize.page.forms.first form.field_with(:name => "username").value = NFL_LOGIN form.field_with(:name => "password").value = NFL_PWD page = form.submit form..first @page = @mechanize.get(NFL_PP) end |
#my_team ⇒ Object
34 35 36 |
# File 'lib/nfl_fantasy_scraper.rb', line 34 def my_team Hash[my_team_player_names.zip(join_stats)] end |
#my_team_player_names ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/nfl_fantasy_scraper.rb', line 38 def my_team_player_names team_page = @mechanize.get(NFL_URL) players = team_page.search('.tableType-player .playerNameAndInfo').map do |td| td.text.split(' ')[0..1].join(' ') end players - [" ", nil, "Offense", "Defense Team", "Kicker"] end |
#print_table ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/nfl_fantasy_scraper.rb', line 26 def print_table rows = [] my_team.each do |player| rows << [player[0], player[1][0], player[1][1]] end table = Terminal::Table.new :headings => ['Player', 'Opponent', 'Current Points'], :rows => rows end |
#scrape_opponents ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/nfl_fantasy_scraper.rb', line 47 def scrape_opponents team_page = @mechanize.get(NFL_URL) opponents = team_page.search('.tableType-player .playerOpponent').map do |td| td.text end opponents - [" ", nil, "Opp"] end |
#scrape_points ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/nfl_fantasy_scraper.rb', line 56 def scrape_points team_page = @mechanize.get(NFL_URL) points = team_page.search('.tableType-player .statTotal').map do |td| td.text end points - [" ", nil, "Points"] end |