Class: FootballCli::Handler

Inherits:
Object
  • Object
show all
Includes:
Mapper
Defined in:
lib/football_cli/handler.rb

Instance Method Summary collapse

Methods included from Mapper

#get_league_id, #get_qualification, #get_team_id

Constructor Details

#initialize(options = {}) ⇒ Handler

Returns a new instance of Handler.



12
13
14
15
16
17
18
19
20
# File 'lib/football_cli/handler.rb', line 12

def initialize(options={})
  @league = options[:league]
  @match_day = options[:match_day]
  @players = options[:players]
  @fixtures = options[:fixtures]
  @team = options[:team]
  @file = options[:file]
  @format = options.fetch(:format, 'table')
end

Instance Method Details

#league_tableObject



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

def league_table
  response = client.league_table(league_id, match_day: match_day)

  output(
    title: response[:leagueCaption],
    response: response[:standing],
    columns: %i(position teamName playedGames goalDifference points),
    qualification: qualification
  )
end

#live_scoresObject



69
70
71
72
73
74
75
76
77
# File 'lib/football_cli/handler.rb', line 69

def live_scores
  response = client.live_scores

  output(
    title: 'Live scores',
    response: response[:games],
    columns: %i(league homeTeamName goalsHomeTeam goalsAwayTeam awayTeamName time)
  )
end

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/football_cli/handler.rb', line 22

def run
  check_for_api_token

  if league
    league_table
  elsif team
    if players
      team_players
    elsif fixtures
      team_fixtures
    end
  end
end

#team_fixturesObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/football_cli/handler.rb', line 58

def team_fixtures
  response = client.team_fixtures(team_id)
  team_response = client.team(team_id)

  output(
    title: "#{team_response[:name]} fixtures. Total #{response[:count]}",
    response: response[:fixtures],
    columns: %i(matchday homeTeamName goalsHomeTeam goalsAwayTeam awayTeamName status date)
  )
end

#team_playersObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/football_cli/handler.rb', line 47

def team_players
  response = client.team_players(team_id)
  team_response = client.team(team_id)

  output(
    title: "#{team_response[:name]} players. Total #{response[:count]}",
    response: response[:players],
    columns: %i(jerseyNumber name position nationality dateOfBirth)
  )
end