fantasy-football 0.1.9 → 0.2.0

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: c5a59bd1cc3884b50de0f7fe08b14a0477000cae4d74b12e1fc26a8c806a598a
4
- data.tar.gz: c2208dc6a42677c479d58f65ead6ff7a01a041d7349e456019c4a52bee4567ff
3
+ metadata.gz: 5bbf6659d9889db6ad0064054b7cac10c58876f5ca71762882d76fc189cd37f7
4
+ data.tar.gz: 98d2cba1d007c6e2698154bc910fc8647031cd8ce996fba8be3529a008332013
5
5
  SHA512:
6
- metadata.gz: fd9c8efb194ab0cf4e5332997d4e90d7723275e994f5e1ef5db6202be9503bf52b6d4d8b5c9fb325beb3c7aa3f4d95f7c0ba922ff7b97d8d443e586e9dbf4d8c
7
- data.tar.gz: 272c79fa3c56869d9cdc808d1a96d842afdd171876634ade6ae3d01dfc169dfa7eb8662ce010126daba2c5a4b844a74b86d1fe2456ea7b80cfabf4a3e8ac49b8
6
+ metadata.gz: 14ee8a4219df44ec57d426e49adbcaf5d0be1c37c76dd2c18a50193b923519d510abe35be1e3fd3e960b29deb0607c6b0ecd367c5c68607d20f875e47d930275
7
+ data.tar.gz: 5a39dbd9ea69a765d80cd0324e44282e6153850d217df7c21b3c843ed4a02bdf689f2b3e9b43d8dc364f5b18db75a8c4e393b468c035cdf2f834e0a30598fa26
@@ -2,24 +2,38 @@ class FantasyFootball::CLI
2
2
 
3
3
  POSITIONS = ["qb", "rb", "te", "wr", "k"]
4
4
 
5
- attr_accessor :position # Stores current state of position choice
5
+ attr_accessor :position, :size # Stores current state of position choice
6
6
 
7
7
  def welcome
8
+ puts " "
8
9
  puts "Welcome to the NFL Fantasy Football Rankings and Players!"
10
+ puts " "
11
+ end
12
+
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
20
+ puts "Invalid entry - please enter a valid input:"
21
+ choose_list_size
22
+ end
9
23
  end
10
24
 
11
- def choose_rankings
25
+ def choose_position
12
26
  # Asks for position and lists top players ranked by Fantasypros
13
27
  puts "What position would you like to see rankings for?"
14
28
  puts "Please enter QB, RB, TE, WR, or K:"
15
29
  self.position = gets.strip.downcase
16
30
  if POSITIONS.include?(position)
17
- FantasyFootball::Scraper.scrape_rankings(position) if FantasyFootball::Player.find_by_position(position) == []
31
+ FantasyFootball::Scraper.scrape_rankings(position, size) if FantasyFootball::Player.find_by_position(position) == []
18
32
  print_rankings
19
33
  choose_player
20
34
  else
21
35
  puts "Invalid entry - please enter a valid input:"
22
- choose_rankings
36
+ choose_position
23
37
  end
24
38
  end
25
39
 
@@ -27,7 +41,7 @@ class FantasyFootball::CLI
27
41
  # Iterates through Player.all to print player name and rankings by position
28
42
  puts " "
29
43
  FantasyFootball::Player.find_by_position(position).sort {|a,b| a.rank.to_i <=> b.rank.to_i}.each_with_index {| p, i|
30
- puts "-- Top #{FantasyFootball::Scraper.size} #{position.upcase}s for Week #{p.week} of #{Time.new.year} --" if i == 0
44
+ puts "-- Top #{size} #{position.upcase}s for Week #{p.week} of #{Time.new.year} --" if i == 0
31
45
  puts "#{p.rank}. #{p.name}"}
32
46
  puts " "
33
47
  end
@@ -36,7 +50,7 @@ class FantasyFootball::CLI
36
50
  # Prompts for player rank #, outputs player details
37
51
  puts "If you would like to see details about a player, enter their rank number. If not, enter N:"
38
52
  rank = gets.strip
39
- if rank.to_i.between?(1,FantasyFootball::Scraper.size)
53
+ if rank.to_i.between?(1,size)
40
54
  print_player(rank)
41
55
  elsif rank.downcase == "n"
42
56
  return
@@ -48,7 +62,7 @@ class FantasyFootball::CLI
48
62
 
49
63
  def print_player(rank)
50
64
  # Prints specific player using a custom class finder
51
- blank = " "
65
+ blank = " "
52
66
  p = FantasyFootball::Player.find_by_rank_and_position(rank, position)
53
67
  FantasyFootball::Scraper.add_attr(p)
54
68
  puts blank
@@ -75,7 +89,7 @@ class FantasyFootball::CLI
75
89
  print_rankings
76
90
  choose_player
77
91
  elsif input == "2"
78
- choose_rankings
92
+ choose_position
79
93
  elsif input == "quit"
80
94
  exit
81
95
  else
@@ -87,7 +101,8 @@ class FantasyFootball::CLI
87
101
 
88
102
  def run
89
103
  welcome
90
- choose_rankings
104
+ choose_list_size
105
+ choose_position
91
106
  again?
92
107
  end
93
108
 
@@ -1,8 +1,5 @@
1
1
  class FantasyFootball::Player
2
2
 
3
- extend Findable::ClassMethods
4
- include Memorable::InstanceMethods
5
-
6
3
  attr_accessor :name, :position, :projection, :team, :height, :weight, :age, :college, :rank, :url, :week
7
4
 
8
5
  @@all = []
@@ -15,4 +12,16 @@ class FantasyFootball::Player
15
12
  @@all
16
13
  end
17
14
 
15
+ def save
16
+ @@all << self
17
+ end
18
+
19
+ def self.find_by_position(position)
20
+ all.select {|i| i.position == position.upcase}
21
+ end
22
+
23
+ def self.find_by_rank_and_position(rank, position)
24
+ all.find {|i| i.rank == rank && i.position == position.upcase}
25
+ end
26
+
18
27
  end
@@ -1,18 +1,13 @@
1
1
  class FantasyFootball::Scraper
2
2
 
3
- def self.size #Determines how many players to scrape per position
4
- 20
5
- end
6
-
7
- def self.scrape_rankings(position)
3
+ def self.scrape_rankings(position, size)
8
4
  doc = Nokogiri::HTML(open("https://www.fantasypros.com/nfl/rankings/#{position}.php"))
9
- # binding.pry
10
5
  week = doc.css('h1').text.split[5]
11
6
  table = doc.css('tbody tr') # Selects the HTML table with player rankings
12
- build_players(table, position, week)
7
+ build_players(table, position, week, size)
13
8
  end
14
9
 
15
- def self.build_players(table, position, week)
10
+ def self.build_players(table, position, week, size)
16
11
  # Input is HTML table of player rankings, instantiates Players, assigns name, rank, and url
17
12
  table.each_with_index do |t, i|
18
13
  if i < size
@@ -1,3 +1,3 @@
1
1
  module FantasyFootball
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fantasy-football
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Mike Dilley'"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-19 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -188,8 +188,6 @@ files:
188
188
  - fantasy-football.gemspec
189
189
  - lib/fantasy-football.rb
190
190
  - lib/fantasy_football/CLI.rb
191
- - lib/fantasy_football/concerns/findable.rb
192
- - lib/fantasy_football/concerns/memorable.rb
193
191
  - lib/fantasy_football/player.rb
194
192
  - lib/fantasy_football/scraper.rb
195
193
  - lib/fantasy_football/version.rb
@@ -1,19 +0,0 @@
1
- module Findable
2
-
3
- module ClassMethods
4
-
5
- def find_by_position(position)
6
- self.all.select {|i| i.position == position.upcase}
7
- end
8
-
9
- def find_by_rank_and_position(rank, position)
10
- self.all.find {|i| i.rank == rank && i.position == position.upcase}
11
- end
12
-
13
- # def find_by_name(name)
14
- # self.all.find {|i| i.name == name}
15
- # end
16
-
17
- end
18
-
19
- end
@@ -1,11 +0,0 @@
1
- module Memorable
2
-
3
- module InstanceMethods
4
-
5
- def save
6
- self.class.all << self
7
- end
8
-
9
- end
10
-
11
- end