Class: NBAStat
- Inherits:
-
Object
- Object
- NBAStat
- Defined in:
- lib/nbascores/nba_stat.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#away ⇒ Object
Returns the value of attribute away.
-
#away_score ⇒ Object
Returns the value of attribute away_score.
-
#date ⇒ Object
Returns the value of attribute date.
-
#home ⇒ Object
Returns the value of attribute home.
-
#home_score ⇒ Object
Returns the value of attribute home_score.
-
#period ⇒ Object
Returns the value of attribute period.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .clear ⇒ Object
- .find_by_date(date) ⇒ Object
- .find_by_url(url) ⇒ Object
- .game_exists(url) ⇒ Object
Instance Method Summary collapse
-
#initialize(properties = {}) ⇒ NBAStat
constructor
A new instance of NBAStat.
- #summary_scrape ⇒ Object
Constructor Details
#initialize(properties = {}) ⇒ NBAStat
Returns a new instance of NBAStat.
6 7 8 9 10 11 |
# File 'lib/nbascores/nba_stat.rb', line 6 def initialize(properties = {}) properties.each do |property, value| send("#{property}=", value) end @@all << self end |
Instance Attribute Details
#away ⇒ Object
Returns the value of attribute away.
3 4 5 |
# File 'lib/nbascores/nba_stat.rb', line 3 def away @away end |
#away_score ⇒ Object
Returns the value of attribute away_score.
3 4 5 |
# File 'lib/nbascores/nba_stat.rb', line 3 def away_score @away_score end |
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/nbascores/nba_stat.rb', line 3 def date @date end |
#home ⇒ Object
Returns the value of attribute home.
3 4 5 |
# File 'lib/nbascores/nba_stat.rb', line 3 def home @home end |
#home_score ⇒ Object
Returns the value of attribute home_score.
3 4 5 |
# File 'lib/nbascores/nba_stat.rb', line 3 def home_score @home_score end |
#period ⇒ Object
Returns the value of attribute period.
3 4 5 |
# File 'lib/nbascores/nba_stat.rb', line 3 def period @period end |
#summary ⇒ Object
Returns the value of attribute summary.
3 4 5 |
# File 'lib/nbascores/nba_stat.rb', line 3 def summary @summary end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/nbascores/nba_stat.rb', line 3 def url @url end |
Class Method Details
.all ⇒ Object
13 14 15 |
# File 'lib/nbascores/nba_stat.rb', line 13 def self.all @@all end |
.clear ⇒ Object
17 18 19 |
# File 'lib/nbascores/nba_stat.rb', line 17 def self.clear all.clear end |
.find_by_date(date) ⇒ Object
25 26 27 |
# File 'lib/nbascores/nba_stat.rb', line 25 def self.find_by_date(date) all.select { |game| game.date == date } end |
.find_by_url(url) ⇒ Object
29 30 31 |
# File 'lib/nbascores/nba_stat.rb', line 29 def self.find_by_url(url) all.find { |game| game.url == url } end |
.game_exists(url) ⇒ Object
21 22 23 |
# File 'lib/nbascores/nba_stat.rb', line 21 def self.game_exists(url) all.collect { |game| game.url == url }.include?(true) end |
Instance Method Details
#summary_scrape ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nbascores/nba_stat.rb', line 33 def summary_scrape begin doc = Nokogiri::HTML(open("http://www.nba.com/games/#{url}/gameinfo.html?ls=iref:nba:scoreboard")) rescue OpenURI::HTTPError @summary = 'No recap available' else if doc.css('#nbaGIRecap2 p').text == '' @summary = doc.css('#nbaGIPreview p').text else @summary = doc.css('#nbaGIRecap2 p').text end end end |