Class: FplGsheet::Databank

Inherits:
Object
  • Object
show all
Defined in:
lib/fpl_gsheet/databank.rb

Instance Method Summary collapse

Constructor Details

#initializeDatabank

Returns a new instance of Databank.



11
12
13
14
15
16
# File 'lib/fpl_gsheet/databank.rb', line 11

def initialize
  #some stuff outside the scope of this review
  #just assume the fixtures and teams methods work
  @all_data=JSON.load(open("https://fantasy.premierleague.com/api/bootstrap-static/", {ssl_verify_mode: 0}))
  @fixture_data=JSON.load(open("https://fantasy.premierleague.com/api/fixtures/", {ssl_verify_mode: 0}))
end

Instance Method Details

#fixturesObject



18
19
20
21
# File 'lib/fpl_gsheet/databank.rb', line 18

def fixtures
  #returns array of all Fixtures
  @fixtures ||= @fixture_data.map { |f| Fixture.new(f, self) }
end

#fixtures_for_team(id) ⇒ Object



38
39
40
41
42
# File 'lib/fpl_gsheet/databank.rb', line 38

def fixtures_for_team(id)
  fixtures.select do |f|
    id==f.data['team_h'] || id==f.data['team_a']
  end
end

#gameweeksObject



44
45
46
# File 'lib/fpl_gsheet/databank.rb', line 44

def gameweeks
  @gameweeks ||= @all_data['events']
end

#playersObject



31
32
33
34
35
36
# File 'lib/fpl_gsheet/databank.rb', line 31

def players
  return @players if defined? @players
  @players = @all_data['elements'].map do |t|
    Player.new(t, self)
  end
end

#teamsObject



23
24
25
26
27
28
29
# File 'lib/fpl_gsheet/databank.rb', line 23

def teams
  #returns array of all Teams
  return @teams if defined? @teams
  @teams = @all_data['teams'].map do |t|
    Team.new(t, self)
  end
end