Class: EspnScrape

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

Overview

EspnScrape main class

Constant Summary collapse

VERSION =

Gem Version

'0.6.5'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ EspnScrape

initialize



8
9
10
# File 'lib/espnscrape.rb', line 8

def initialize(config = {})
  @format = defaultFormat(config[:format])
end

Class Method Details

.boxscore(game_id, f_mat = nil) ⇒ NbaBoxScore

Returns an NbaBoxScore object

Examples:

EspnScrape.boxscore(493848273)

Parameters:

  • game_id (Integer)

    Boxscore ID

Returns:



17
18
19
20
# File 'lib/espnscrape.rb', line 17

def self.boxscore(game_id, f_mat = nil)
  NbaBoxScore.new(game_id: game_id,
                  format: defaultFormat(f_mat))
end

.player(espn_id) ⇒ NbaPlayer

Return new NbaPlayer object

Examples:

EspnScrape.player(2991473)

Parameters:

  • espn_id (String)

    ESPN Player ID

Returns:



101
102
103
# File 'lib/espnscrape.rb', line 101

def self.player(espn_id)
  NbaPlayer.new espn_id
end

.roster(team_id, options = {}) ⇒ NbaRoster

Returns an NbaRoster object

Examples:

EspnScrape.roster('UTA')

Parameters:

  • team_id (String)

    Team ID

Returns:



36
37
38
39
# File 'lib/espnscrape.rb', line 36

def self.roster(team_id, options = {})
  NbaRoster.new(team_id: team_id,
                format: defaultFormat(options.fetch(:format, nil)))
end

.schedule(team_id, options = {}) ⇒ NbaSchedule

Return an NbaSchedule object

Examples:

EspnScrape.schedule('UTA')            # Schedule for Latest Season Type
EspnScrape.schedule('TOR', s_type: 3) # Playoff Schedule

Parameters:

  • team_id (String)

    Team ID

  • options (:season) (defaults to: {})
    Int

    Season Type

  • options (:year) (defaults to: {})
    Int

    Ending Year of Season (i.e. 2016 for 2015-16)

  • options (:format) (defaults to: {})
    Sym

    Table Format (:to_structs/:to_hashes)

Returns:



76
77
78
79
80
81
# File 'lib/espnscrape.rb', line 76

def self.schedule(team_id, options = {})
  NbaSchedule.new team_id: team_id,
                  season_type: options[:season],
                  format: defaultFormat(options[:format]),
                  year: options[:year]
end

.teamList(f_mat = nil) ⇒ [[String]]

Return Array of Team Data

Examples:

EspnScrape.teamList(:to_structs)

Returns:

  • ([[String]])

    NBA Team Data



55
56
57
# File 'lib/espnscrape.rb', line 55

def self.teamList(f_mat = nil)
  NbaTeamList.new(format: defaultFormat(f_mat)).teamList
end

Instance Method Details

#boxscore(game_id, f_mat = nil) ⇒ NbaBoxScore

Returns an NbaBoxScore object

Examples:

es.boxscore(493848273)

Parameters:

  • game_id (Integer)

    Boxscore ID

Returns:



27
28
29
# File 'lib/espnscrape.rb', line 27

def boxscore(game_id, f_mat = nil)
  EspnScrape.boxscore game_id, (f_mat || @format)
end

#player(espn_id) ⇒ NbaPlayer

Return new NbaPlayer object

Examples:

es.player(2991473)

Parameters:

  • espn_id (String)

    ESPN Player ID

Returns:



110
111
112
# File 'lib/espnscrape.rb', line 110

def player(espn_id)
  EspnScrape.player espn_id
end

#roster(team_id, options = {}) ⇒ NbaRoster

Returns an NbaRoster object

Examples:

es.roster('UTA')
es.roster('UTA', format: :to_structs)

Parameters:

  • team_id (String)

    Team ID

Returns:



47
48
49
# File 'lib/espnscrape.rb', line 47

def roster(team_id, options = {})
  EspnScrape.roster team_id, format: (options.fetch(:format, nil) || @format)
end

#schedule(team_id, options = {}) ⇒ NbaSchedule

Return an NbaSchedule object

Examples:

es.schedule('MIA')     # Schedule for Latest Season Type
es.schedule('DET', season: 1, year: 2016)  # Preseason Schedule

Parameters:

  • team_id (String)

    Team ID

  • options (:season) (defaults to: {})
    Int

    Season Type

  • options (:year) (defaults to: {})
    Int

    Ending Year of Season (i.e. 2016 for 2015-16)

  • options (:format) (defaults to: {})
    Sym

    Table Format (:to_structs/:to_hashes)

Returns:



89
90
91
92
93
94
# File 'lib/espnscrape.rb', line 89

def schedule(team_id, options = {})
  EspnScrape.schedule team_id,
                      season: options[:season],
                      format: (options[:format] || @format),
                      year: options[:year]
end

#teamList(f_mat = nil) ⇒ [[String]]

Return Array of Team Data

Examples:

es.teamList(:to_structs)

Returns:

  • ([[String]])

    NBA Team Data



63
64
65
# File 'lib/espnscrape.rb', line 63

def teamList(f_mat = nil)
  EspnScrape.teamList(f_mat || @format)
end