Class: NBAStat

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#awayObject

Returns the value of attribute away.



3
4
5
# File 'lib/nbascores/nba_stat.rb', line 3

def away
  @away
end

#away_scoreObject

Returns the value of attribute away_score.



3
4
5
# File 'lib/nbascores/nba_stat.rb', line 3

def away_score
  @away_score
end

#dateObject

Returns the value of attribute date.



3
4
5
# File 'lib/nbascores/nba_stat.rb', line 3

def date
  @date
end

#homeObject

Returns the value of attribute home.



3
4
5
# File 'lib/nbascores/nba_stat.rb', line 3

def home
  @home
end

#home_scoreObject

Returns the value of attribute home_score.



3
4
5
# File 'lib/nbascores/nba_stat.rb', line 3

def home_score
  @home_score
end

#periodObject

Returns the value of attribute period.



3
4
5
# File 'lib/nbascores/nba_stat.rb', line 3

def period
  @period
end

#summaryObject

Returns the value of attribute summary.



3
4
5
# File 'lib/nbascores/nba_stat.rb', line 3

def summary
  @summary
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/nbascores/nba_stat.rb', line 3

def url
  @url
end

Class Method Details

.allObject



13
14
15
# File 'lib/nbascores/nba_stat.rb', line 13

def self.all
  @@all
end

.clearObject



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_scrapeObject



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