fantasy-football 0.2.0 → 0.2.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
  SHA256:
3
- metadata.gz: 5bbf6659d9889db6ad0064054b7cac10c58876f5ca71762882d76fc189cd37f7
4
- data.tar.gz: 98d2cba1d007c6e2698154bc910fc8647031cd8ce996fba8be3529a008332013
3
+ metadata.gz: a4684cfcaed208aa4b48bb90c51a8aa6e7584de367ba55dea2811fb04146db62
4
+ data.tar.gz: 75ee2021047cef994803c356b80a6c0ae1ca55cd44692611348a3cfd8d82b3a1
5
5
  SHA512:
6
- metadata.gz: 14ee8a4219df44ec57d426e49adbcaf5d0be1c37c76dd2c18a50193b923519d510abe35be1e3fd3e960b29deb0607c6b0ecd367c5c68607d20f875e47d930275
7
- data.tar.gz: 5a39dbd9ea69a765d80cd0324e44282e6153850d217df7c21b3c843ed4a02bdf689f2b3e9b43d8dc364f5b18db75a8c4e393b468c035cdf2f834e0a30598fa26
6
+ metadata.gz: f5ee4562b6b71d9aea5d5345bb48a3be5ddf59222757a81e94c7cdb176c05adec1cde8b052ccef09537bf90b792129940174a6bc2cef528cebfd3b3d9e7c25ff
7
+ data.tar.gz: c2bcf01de92742473279e12c587a26ad190dce1e5bfd1d6e708a9ff4bb7d767ca0dafc91d7013bb333c5022ac4a9311cba9571e7c72d6bc1d8e753b83f308d11
@@ -2,23 +2,19 @@ class FantasyFootball::CLI
2
2
 
3
3
  POSITIONS = ["qb", "rb", "te", "wr", "k"]
4
4
 
5
- attr_accessor :position, :size # Stores current state of position choice
6
-
7
5
  def welcome
8
6
  puts " "
9
- puts "Welcome to the NFL Fantasy Football Rankings and Players!"
7
+ puts "Welcome to NFL Fantasy Football Rankings and Players!"
10
8
  puts " "
11
9
  end
12
10
 
13
- def choose_list_size
14
- puts "How many player rankings would you like see per position?"
15
- puts "Please enter a number between 1 and 25:"
16
- self.size = gets.strip.to_i
17
- if size.between?(1,25)
18
- return
19
- else
11
+ def choose_list_size(position)
12
+ puts "How many player rankings would you like see?"
13
+ puts "Please enter a number between 1 and #{FantasyFootball::Player.find_by_position(position).size}:"
14
+ @size = gets.strip.to_i
15
+ if !@size.between?(1,FantasyFootball::Player.find_by_position(position).size)
20
16
  puts "Invalid entry - please enter a valid input:"
21
- choose_list_size
17
+ choose_list_size(@position)
22
18
  end
23
19
  end
24
20
 
@@ -26,10 +22,11 @@ class FantasyFootball::CLI
26
22
  # Asks for position and lists top players ranked by Fantasypros
27
23
  puts "What position would you like to see rankings for?"
28
24
  puts "Please enter QB, RB, TE, WR, or K:"
29
- self.position = gets.strip.downcase
30
- if POSITIONS.include?(position)
31
- FantasyFootball::Scraper.scrape_rankings(position, size) if FantasyFootball::Player.find_by_position(position) == []
32
- print_rankings
25
+ @position = gets.strip.downcase
26
+ if POSITIONS.include?(@position)
27
+ FantasyFootball::Scraper.scrape_rankings(@position) if FantasyFootball::Player.find_by_position(@position) == []
28
+ choose_list_size(@position)
29
+ print_rankings(@size)
33
30
  choose_player
34
31
  else
35
32
  puts "Invalid entry - please enter a valid input:"
@@ -37,11 +34,11 @@ class FantasyFootball::CLI
37
34
  end
38
35
  end
39
36
 
40
- def print_rankings
41
- # Iterates through Player.all to print player name and rankings by position
37
+ def print_rankings(size)
38
+ # Iterates through Player instances to print player name and rankings by position
42
39
  puts " "
43
- FantasyFootball::Player.find_by_position(position).sort {|a,b| a.rank.to_i <=> b.rank.to_i}.each_with_index {| p, i|
44
- puts "-- Top #{size} #{position.upcase}s for Week #{p.week} of #{Time.new.year} --" if i == 0
40
+ FantasyFootball::Player.find_by_position(@position)[0..@size - 1].each_with_index {| p, i|
41
+ puts "-- Top #{size} #{@position.upcase}s for Week #{p.week} of #{Time.new.year} --" if i == 0
45
42
  puts "#{p.rank}. #{p.name}"}
46
43
  puts " "
47
44
  end
@@ -50,7 +47,7 @@ class FantasyFootball::CLI
50
47
  # Prompts for player rank #, outputs player details
51
48
  puts "If you would like to see details about a player, enter their rank number. If not, enter N:"
52
49
  rank = gets.strip
53
- if rank.to_i.between?(1,size)
50
+ if rank.to_i.between?(1,@size)
54
51
  print_player(rank)
55
52
  elsif rank.downcase == "n"
56
53
  return
@@ -63,7 +60,7 @@ class FantasyFootball::CLI
63
60
  def print_player(rank)
64
61
  # Prints specific player using a custom class finder
65
62
  blank = " "
66
- p = FantasyFootball::Player.find_by_rank_and_position(rank, position)
63
+ p = FantasyFootball::Player.find_by_rank_and_position(rank, @position)
67
64
  FantasyFootball::Scraper.add_attr(p)
68
65
  puts blank
69
66
  puts " Player Stats "
@@ -86,7 +83,7 @@ class FantasyFootball::CLI
86
83
  puts "Please enter 1, 2, or quit."
87
84
  input = gets.strip.downcase
88
85
  if input == "1"
89
- print_rankings
86
+ print_rankings(@size)
90
87
  choose_player
91
88
  elsif input == "2"
92
89
  choose_position
@@ -101,7 +98,6 @@ class FantasyFootball::CLI
101
98
 
102
99
  def run
103
100
  welcome
104
- choose_list_size
105
101
  choose_position
106
102
  again?
107
103
  end
@@ -17,7 +17,7 @@ class FantasyFootball::Player
17
17
  end
18
18
 
19
19
  def self.find_by_position(position)
20
- all.select {|i| i.position == position.upcase}
20
+ all.select {|i| i.position == position.upcase}.sort {|a,b| a.rank.to_i <=> b.rank.to_i}
21
21
  end
22
22
 
23
23
  def self.find_by_rank_and_position(rank, position)
@@ -1,22 +1,26 @@
1
1
  class FantasyFootball::Scraper
2
2
 
3
- def self.scrape_rankings(position, size)
3
+ def self.scrape_rankings(position)
4
4
  doc = Nokogiri::HTML(open("https://www.fantasypros.com/nfl/rankings/#{position}.php"))
5
5
  week = doc.css('h1').text.split[5]
6
6
  table = doc.css('tbody tr') # Selects the HTML table with player rankings
7
- build_players(table, position, week, size)
7
+ build_players(table, position, week)
8
8
  end
9
9
 
10
- def self.build_players(table, position, week, size)
10
+ def self.build_players(table, position, week)
11
11
  # Input is HTML table of player rankings, instantiates Players, assigns name, rank, and url
12
+
12
13
  table.each_with_index do |t, i|
13
- if i < size
14
- p = FantasyFootball::Player.new
15
- p.name = [t.text.split[1], t.text.split[3]].join(" ")
16
- p.rank = t.text.split[0]
17
- p.url = "https://www.fantasypros.com" + t.css('a')[0]["href"]
18
- p.week = week
19
- p.position = position.upcase
14
+ begin
15
+ if t.css('td')[0].text.to_i > 0
16
+ p = FantasyFootball::Player.new
17
+ p.name = t.css('span.full-name').text
18
+ p.rank = t.css('td')[0].text
19
+ p.url = "https://www.fantasypros.com" + t.css('a')[0]["href"]
20
+ p.week = week
21
+ p.position = position.upcase
22
+ end
23
+ rescue NoMethodError
20
24
  end
21
25
  end
22
26
  end
@@ -1,3 +1,3 @@
1
1
  module FantasyFootball
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Mike Dilley'"