Class: FantasyCompare::NFLJSON

Inherits:
Object
  • Object
show all
Defined in:
lib/fantasyCompare/NFLJSON.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#detailObject

Returns the value of attribute detail.



6
7
8
# File 'lib/fantasyCompare/NFLJSON.rb', line 6

def detail
  @detail
end

#infoObject

Returns the value of attribute info.



6
7
8
# File 'lib/fantasyCompare/NFLJSON.rb', line 6

def info
  @info
end

#listObject

Returns the value of attribute list.



6
7
8
# File 'lib/fantasyCompare/NFLJSON.rb', line 6

def list
  @list
end

#playersObject

Returns the value of attribute players.



6
7
8
# File 'lib/fantasyCompare/NFLJSON.rb', line 6

def players
  @players
end

#players_hashObject

Returns the value of attribute players_hash.



6
7
8
# File 'lib/fantasyCompare/NFLJSON.rb', line 6

def players_hash
  @players_hash
end

#positionObject

Returns the value of attribute position.



6
7
8
# File 'lib/fantasyCompare/NFLJSON.rb', line 6

def position
  @position
end

#weekObject

Returns the value of attribute week.



6
7
8
# File 'lib/fantasyCompare/NFLJSON.rb', line 6

def week
  @week
end

Class Method Details

.detail_player_view(info) ⇒ Object

obtain detail veiw of player



55
56
57
58
59
60
# File 'lib/fantasyCompare/NFLJSON.rb', line 55

def self.detail_player_view(info)
  info -= 1
  @playerId = @top_ten[info][:playerId]
  @playerName = @top_ten[info][:name]
  @projectedPoints = @top_ten[info][:weekProjectedPts]
end

.detail_urlObject

modifies url to pull proper JSON data based on user inputs and returns a hashed result



16
17
18
19
20
# File 'lib/fantasyCompare/NFLJSON.rb', line 16

def self.detail_url
  detail_url = "http://api.fantasy.nfl.com/v1/players/details?playerId=#{@playerId}&statType=seasonStatsformat=json"
  response = HTTParty.get(detail_url)
  @detail_hash = response.parsed_response
end

.listObject

parses info into numbered list



48
49
50
51
52
# File 'lib/fantasyCompare/NFLJSON.rb', line 48

def self.list
  @list.each_with_index do |value, index|
    puts "#{index + 1}: #{value}"
  end
end

.next_noteObject

used to display addtional notes



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fantasyCompare/NFLJSON.rb', line 78

def self.next_note
  addtional_notes = "Y"
  note_number = 1

  while note_number < @note.length - 1  && addtional_notes[0].capitalize == "Y"
      puts @note[note_number]
      note_number += 1

      if note_number >= @note.length-1
        puts "\nThere are no more notes"
        puts "\nWould you like to see additional positions (Y/N)?"
        FantasyCompare::CLI.new.call if gets.chomp[0].capitalize == "Y"
        addtional_notes = "N"
      else
        puts "\nWould you like to see additional notes (Y/N)?"
        addtional_notes = gets.chomp

        if addtional_notes[0].capitalize == "N"
          puts "\nWould you like to see additional positions (Y/N)?"
          FantasyCompare::CLI.new.call if gets.chomp[0].capitalize == "Y"
        end
      end
  end

end

.playersObject

generates simplefied list of parsed down data from API



24
25
26
27
28
29
30
31
32
33
# File 'lib/fantasyCompare/NFLJSON.rb', line 24

def self.players
  @players = []
  @players_hash["players"].each do |key, value|
    weekProjectedPts = key["weekProjectedPts"]
    name = key["name"]
    playerId = key["id"]
    @players << {name: name, weekProjectedPts: weekProjectedPts, playerId: playerId}
  end
    self.top_ten_list(@players)
end

.show_detail_veiwObject

parses @detail_hash into readable info



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fantasyCompare/NFLJSON.rb', line 63

def self.show_detail_veiw
  @note = []
  status = ""
  injury = ""
  @detail_hash["players"].each do |key, value|
    status =  key["status"]
    injury = key["injuryGameStatus"] || "None"
    key["notes"].each do |key, value|
    @note << "Date: #{key["timestamp"]}\n #{key["body"] + key["analysis"]}"
    end
  end
  @detail = "Status: #{status} \nInjury Status: #{injury}\n"
end

.top_ten_list(players) ⇒ Object

take the parsed players hash array, sorts it and returns the top 10 projected players in text format



36
37
38
39
40
41
42
43
44
45
# File 'lib/fantasyCompare/NFLJSON.rb', line 36

def self.top_ten_list(players)
   @list = []
   @top_ten = players.sort_by {|key| key[:weekProjectedPts]}.reverse!.first(10)
   #parse into strings
   @top_ten.each do |key, value|
     name = key[:name]
     projected = key[:weekProjectedPts]
     @list <<  "Name: #{name} Projected Points: #{projected}"
   end
end

.url(position, week) ⇒ Object

modifies url to pull proper JSON data



9
10
11
12
13
# File 'lib/fantasyCompare/NFLJSON.rb', line 9

def self.url(position, week)
  url = "http://api.fantasy.nfl.com/v1/players/stats?statType=weekProjectedStats&season=2016&week=#{week}&position=#{position}&format=json&returnHTML=1"
  response = HTTParty.get(url)
  @players_hash = response.parsed_response
end