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



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

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



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

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



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

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

.next_noteObject

used to display addtional notes



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

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



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

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



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

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



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

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
14
# 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