Class: Footballdata::League

Inherits:
Object
  • Object
show all
Defined in:
lib/models/league.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:) ⇒ League

Returns a new instance of League.



5
6
7
8
# File 'lib/models/league.rb', line 5

def initialize(id:, name:)
  @id = id
  @name = name
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/models/league.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/models/league.rb', line 3

def name
  @name
end

Instance Method Details

#fixturesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/models/league.rb', line 22

def fixtures
  open("#{BASE_URL}/soccerseasons/#{id}/fixtures", "X-Auth-Token" => api_key) do |response|
    JSON.parse(response.read)["fixtures"].map do |team|
      Footballdata::Fixture.new(
        id:              team["id"],
        soccerseason_id: team["soccerseasonId"],
        date:            team["date"],
        matchday:        team["matchday"],
        home_team_name:  team["homeTeamName"],
        home_team_id:    team["homeTeamId"],
        away_team_name:  team["awayTeamName"],
        away_team_id:    team["awayTeamId"],
        goals_home_team: team["result"]["goalsHomeTeam"],
        goals_away_team: team["result"]["goalsAwayTeam"]
      )
    end
  end
end

#teamsObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/models/league.rb', line 10

def teams
  open("#{BASE_URL}/soccerseasons/#{id}/teams", "X-Auth-Token" => api_key) do |response|
    JSON.parse(response.read)["teams"].map do |team|
      id = team["_links"]["fixtures"]["href"].split("/")[-2]
      Footballdata::Team.new(
        id: id,
        name: team["name"]
      )
    end
  end
end