Skip to content

Commit

Permalink
Refactor player stats
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBaugues committed Sep 13, 2014
1 parent 7b87673 commit 9235b73
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/fantasy_football_nerd/commercial_feeds.rb
Expand Up @@ -7,20 +7,23 @@ def player_info(id)
end

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 do |week, stats|
stats.change_keys(new_keys)
stats.add_snakecase_keys
stats.change_string_values_to_floats
weeks[week] = OpenStruct.new(stats)
end
weeks.each { |week, stats| weeks[week] = create_stats_ostruct(stats) }
end
data
end

def create_stats_ostruct(stats)
stats.change_string_values_to_floats
stats.change_keys(new_keys)
stats.add_snakecase_keys
OpenStruct.new(stats)
end

def new_keys
{
'passAttempts' => 'passAtt',
Expand Down

0 comments on commit 9235b73

Please sign in to comment.