Class: PgaLeaderboard::Tournament

Inherits:
Object
  • Object
show all
Defined in:
lib/pga_leaderboard/tournament.rb

Instance Method Summary collapse

Constructor Details

#initializeTournament

Returns a new instance of Tournament.



6
7
8
# File 'lib/pga_leaderboard/tournament.rb', line 6

def initialize
  @response = HTTParty.get(ENDPOINT).parsed_response
end

Instance Method Details

#bodyObject



32
33
34
35
36
37
38
39
40
# File 'lib/pga_leaderboard/tournament.rb', line 32

def body
  if clean_response.length > 5
    clean_response[2..clean_response.length].each do |item|
      puts item.gsub(/-\d/) { |score| score.colorize(:red) }
    end
  else
    puts "Sorry, not tournament data at this time."
  end
end

#clean_responseObject



17
18
19
20
21
22
23
24
# File 'lib/pga_leaderboard/tournament.rb', line 17

def clean_response
  clean_array = []
  parsed_array.each do |item|
    stripped_item = item.gsub(/^[^=]*=/, "")
    clean_array << URI.decode(stripped_item)
  end
  clean_array
end

#headingObject



26
27
28
29
30
# File 'lib/pga_leaderboard/tournament.rb', line 26

def heading
  clean_response[0..1].each do |item|
    puts item.rjust(35)
  end
end

#parsed_arrayObject



10
11
12
13
14
15
# File 'lib/pga_leaderboard/tournament.rb', line 10

def parsed_array
  resp = @response.split("&")
  resp.shift(4)
  resp.pop(3)
  resp
end