fantasy-football 0.1.5 → 0.1.6

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
  SHA256:
3
- metadata.gz: 048bd328aa5746b2d861d7fa4851bcb8848b9962159d39edf1f8c53223c58cde
4
- data.tar.gz: 308aeeee96e44b00c6922e96e6c1462b21be8eddfdbd4e81d6a8594421d5ded2
3
+ metadata.gz: b11fbd88cf3dfc178a6686a488e6aedd727ff6dce636c86913fd9e9429b3db0b
4
+ data.tar.gz: 6b6d3478c7e35b64ce53a9ca83676a6358b3b468e38e54257293db12f6880480
5
5
  SHA512:
6
- metadata.gz: 67c3098a2d3f097e76302aedb8b4a8cd70d7813671f39c615d6f9f2e4b6282ec42da37a0c7b1f51180f4f4e2043877c9d08149532dfa121f15e979e4ade105d5
7
- data.tar.gz: 67fb8e35b1343c8a634528871fc96f45e9bb622e7c858d0c2beabb1a7b5de3ba610a5b22d0f5a8058c32cf4b7250e3e1e3b26989c6692b8ca0f0d29da9a5241b
6
+ metadata.gz: 9f5443603c4e01c885773f05e0cf3d0dc5fee77941d8be3d6cd6eaa3be0610d88fafd8aef19e75335197b7f1810ae8f323329909ab159d16a82fead4842d15d5
7
+ data.tar.gz: dd8b855a019762ee120c9ad49400f2a46299561f059e930258b5c3b4c9fec14b5914833e5e0f9aa34c81f38953034edb8368d64e7ac049865e0b05353dcf24c4
data/bin/fantasyfootball CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative '../config/environment'
4
4
 
5
- CLI.new.run
5
+ FantasyFootball::CLI.new.run
@@ -5,7 +5,7 @@ require "fantasy_football/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "fantasy-football"
8
- spec.version = FF::VERSION
8
+ spec.version = FantasyFootball::VERSION
9
9
  spec.authors = ["'Mike Dilley'"]
10
10
  spec.email = ["'mike.dilley@gmail.com'"]
11
11
 
@@ -1,7 +1,7 @@
1
- class FantasyFootball
1
+ module FantasyFootball
2
2
 
3
3
  def self.hi
4
4
  puts "Hello world!"
5
- end
5
+ end
6
6
 
7
7
  end
@@ -1,4 +1,4 @@
1
- class CLI
1
+ class FantasyFootball::CLI
2
2
 
3
3
  POSITIONS = ["qb", "rb", "te", "wr", "k"]
4
4
 
@@ -12,10 +12,10 @@ class CLI
12
12
  # Asks for position and lists top players ranked by Fantasypros
13
13
  puts "What position would you like to see rankings for?"
14
14
  puts "Please enter QB, RB, TE, WR, or K:"
15
- @position = gets.strip.downcase
16
- if POSITIONS.include?(@position)
17
- Scraper.new_with_name(@position)
18
- print_rankings(@position)
15
+ self.position = gets.strip.downcase
16
+ if POSITIONS.include?(position)
17
+ FantasyFootball::Scraper.scrape_rankings(position) if FantasyFootball::Player.find_by_position(position) == []
18
+ print_rankings
19
19
  choose_player
20
20
  else
21
21
  puts "Invalid entry - please enter a valid input:"
@@ -23,10 +23,10 @@ class CLI
23
23
  end
24
24
  end
25
25
 
26
- def print_rankings(position)
26
+ def print_rankings
27
27
  # Iterates through Player.all to print player name and rankings by position
28
28
  puts " "
29
- puts "-- Top #{Scraper.size} #{@position.upcase}s for Week #{Scraper.find_by_name(@position).week} of #{Time.new.year} --"
29
+ puts "-- Top #{FantasyFootball::Scraper.size} #{position.upcase}s for Week #{11} of #{Time.new.year} --"
30
30
  Player.find_by_position(position).sort {|a,b| a.rank.to_i <=> b.rank.to_i}.each {|i| puts "#{i.rank}. #{i.name}"}
31
31
  puts " "
32
32
  end
@@ -35,7 +35,7 @@ class CLI
35
35
  # Prompts for player rank #, outputs player details
36
36
  puts "If you would like to see details about a player, enter their rank number. If not, enter N:"
37
37
  rank = gets.strip
38
- if rank.to_i.between?(1,Scraper.size)
38
+ if rank.to_i.between?(1,FantasyFootball::Scraper.size)
39
39
  print_player(rank)
40
40
  elsif rank.downcase == "n"
41
41
  return
@@ -45,11 +45,11 @@ class CLI
45
45
  end
46
46
  end
47
47
 
48
- def print_player(list_number)
48
+ def print_player(rank)
49
49
  # Prints specific player using a custom class finder
50
50
  blank = " "
51
- p = Player.find_by_rank_and_position(list_number, @position)
52
- Scraper.find_by_name(@position).add_attr(p)
51
+ p = FantasyFootball::Player.find_by_rank_and_position(rank, position)
52
+ FantasyFootball::Scraper.add_attr(p)
53
53
  puts blank
54
54
  puts " Player Stats "
55
55
  puts "------------------------------- "
@@ -71,7 +71,7 @@ class CLI
71
71
  puts "Please enter 1, 2, or quit."
72
72
  input = gets.strip.downcase
73
73
  if input == "1"
74
- print_rankings(@position)
74
+ print_rankings
75
75
  choose_player
76
76
  elsif input == "2"
77
77
  choose_rankings
@@ -1,9 +1,9 @@
1
- class Player
1
+ class FantasyFootball::Player
2
2
 
3
3
  extend Findable::ClassMethods
4
4
  include Memorable::InstanceMethods
5
5
 
6
- attr_accessor :name, :position, :projection, :team, :height, :weight, :age, :college, :rank, :url, :scraped
6
+ attr_accessor :name, :position, :projection, :team, :height, :weight, :age, :college, :rank, :url
7
7
 
8
8
  @@all = []
9
9
 
@@ -1,44 +1,22 @@
1
- class Scraper
2
-
3
- extend Findable::ClassMethods
4
- include Memorable::InstanceMethods
5
-
6
- attr_accessor :name, :week
7
-
8
- @@all = []
9
-
10
- def self.all # Class variable reader
11
- @@all
12
- end
1
+ class FantasyFootball::Scraper
13
2
 
14
3
  def self.size #Determines how many players to scrape per position
15
4
  20
16
5
  end
17
6
 
18
- def self.new_with_name(name) #Custom class constructor
19
- if !Scraper.find_by_name(name)
20
- s = Scraper.new
21
- s.name = name
22
- s.save
23
- s.scrape_rankings(name)
24
- else
25
- Scraper.find_by_name(name)
26
- end
27
- end
28
-
29
- def scrape_rankings(position)
7
+ def self.scrape_rankings(position)
30
8
  doc = Nokogiri::HTML(open("https://www.fantasypros.com/nfl/rankings/#{position}.php"))
31
9
  # binding.pry
32
10
  @week = doc.css('h1').text.split[5]
33
11
  table = doc.css('tbody tr') # Selects the HTML table with player rankings
34
- build_players(table, name)
12
+ build_players(table, position)
35
13
  end
36
14
 
37
- def build_players(table,position)
15
+ def self.build_players(table,position)
38
16
  # Input is HTML table of player rankings, instantiates Players, assigns name, rank, and url
39
17
  table.each_with_index do |t, i|
40
18
  if i < Scraper.size
41
- p = Player.new
19
+ p = FantasyFootball::Player.new
42
20
  p.name = [t.text.split[1], t.text.split[3]].join(" ")
43
21
  p.rank = t.text.split[0]
44
22
  p.url = "https://www.fantasypros.com" + t.css('a')[0]["href"]
@@ -47,9 +25,9 @@ class Scraper
47
25
  end
48
26
  end
49
27
 
50
- def add_attr(player)
28
+ def self.add_attr(player)
51
29
  # Scrapes player url stored in Player instance and assigns additional attributes
52
- if player.scraped == nil
30
+ if player.height == nil
53
31
  rescue_s = "n/a"
54
32
  doc = Nokogiri::HTML(open(player.url))
55
33
  player.projection = doc.css('.clearfix.detail span.pull-right')[2].text.split[0]
@@ -58,7 +36,6 @@ class Scraper
58
36
  player.weight = doc.css('span.bio-detail')[1].text[8,3]
59
37
  player.age = doc.css('span.bio-detail')[2].text[5,2]
60
38
  player.college = (doc.css('span.bio-detail')[3].text.split(": ")[1].to_s rescue rescue_s)
61
- player.scraped = "Y"
62
39
  end
63
40
  end
64
41
 
@@ -1,3 +1,3 @@
1
- module FF
2
- VERSION = "0.1.5"
1
+ module FantasyFootball
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fantasy-football
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Mike Dilley'"