class Player
Attributes
country[RW]
name[RW]
points[RW]
rank[RW]
tour[RW]
url[RW]
Public Class Methods
all()
click to toggle source
# File lib/player.rb, line 31 def self.all @@all.dup.freeze end
create_from_hash(hash)
click to toggle source
# File lib/player.rb, line 41 def self.create_from_hash(hash) self.new_from_hash(hash).save end
find_by_name(name)
click to toggle source
# File lib/player.rb, line 45 def self.find_by_name(name) @@all.detect { |player| player.name.downcase == name.downcase } end
find_by_rank_and_tour(rank, tour)
click to toggle source
# File lib/player.rb, line 49 def self.find_by_rank_and_tour(rank, tour) self.find_by_tour(tour).detect { |player| player.rank == rank } end
find_by_tour(tour)
click to toggle source
# File lib/player.rb, line 53 def self.find_by_tour(tour) @@all.select { |player| player.tour == tour } end
new_from_hash(hash)
click to toggle source
# File lib/player.rb, line 35 def self.new_from_hash(hash) Player.new.tap do |player| hash.each { |key, value| player.send("#{key}=", value) } end end
Public Instance Methods
player_bio()
click to toggle source
# File lib/player.rb, line 6 def player_bio doc = Nokogiri::HTML(open(url)) metadata = doc.css('.player-bio .player-metadata li') birth_date = metadata[1].text.gsub('Birth Date', '') hometown = metadata[2].text.gsub('Hometown', '') height = metadata[3] ? metadata[3].text.gsub('Height', '') : "N/A" weight = metadata[4] ? metadata[4].text.gsub('Weight', '') : "N/A" puts "=" * 40 puts "Rank: #{rank}" puts "Name: #{name}" puts "Birth Date: #{birth_date}" puts "Hometown: #{hometown}" puts "Country: #{country}" puts "Height: #{height}" puts "Weight: #{weight}" puts "=" * 40 end
save()
click to toggle source
# File lib/player.rb, line 26 def save @@all << self self end