Module: CommercialFeeds
- Included in:
- FFNerd
- Defined in:
- lib/fantasy_football_nerd/commercial_feeds.rb
Instance Method Summary collapse
- #create_stats_ostruct(stats) ⇒ Object
- #is_float_stat?(stat_name) ⇒ Boolean
- #new_keys ⇒ Object
- #player_info(id) ⇒ Object
- #player_stats(id) ⇒ Object
Instance Method Details
#create_stats_ostruct(stats) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/fantasy_football_nerd/commercial_feeds.rb', line 20 def create_stats_ostruct(stats) stats.change_string_values_to_floats stats.change_keys(new_keys) stats.add_snakecase_keys OpenStruct.new(stats) end |
#is_float_stat?(stat_name) ⇒ Boolean
45 46 47 |
# File 'lib/fantasy_football_nerd/commercial_feeds.rb', line 45 def is_float_stat?(stat_name) !['final_score', 'opponent', 'date'].include?(stat_name) end |
#new_keys ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fantasy_football_nerd/commercial_feeds.rb', line 27 def new_keys { 'passAttempts' => 'passAtt', 'interceptions' => 'pass_int', 'passYards' => 'passYds', 'avgPassYards' => 'avgPassYds', 'passYards' => 'passYds', 'Sacks' => 'sacks', 'SackYards' => 'sackYds', 'QBRating' => 'qb_rating', 'rushAttempts' => 'rushAtt', 'rushYards' => 'rushYds', 'recYards' => 'recYds', 'fumble' => 'fumbles', 'fumbleLost' => 'fumblesLost' } end |
#player_info(id) ⇒ Object
3 4 5 6 7 |
# File 'lib/fantasy_football_nerd/commercial_feeds.rb', line 3 def player_info(id) raise 'You must pass along a player id' if id.nil? data = request_service('player', FFNerd.api_key, id) OpenStruct.new(data['Player'].add_snakecase_keys) end |
#player_stats(id) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fantasy_football_nerd/commercial_feeds.rb', line 9 def player_stats(id) raise 'You must pass along a player id' if id.nil? data = request_service('player', FFNerd.api_key, id) data = data['Stats'] data.change_keys_to_ints data.each do |year, weeks| weeks.each { |week, stats| weeks[week] = create_stats_ostruct(stats) } end data end |