Class: BStats::Player

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/bstats/player.rb

Class Method Summary collapse

Class Method Details

.import_csv(file) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/bstats/player.rb', line 11

def self.import_csv(file)
  CSV.foreach(file, headers: true) do |row|
    player = Player.new()
    player.external_id = row['playerID'].to_s
    player.birth_year = row['birthYear'].to_i
    player.first_name = row['nameFirst'].to_s
    player.last_name = row['nameLast'].to_s
    player.save
  end
end