Module: Helpers

Included in:
Batter, Game, Gameday, Pitcher, Team
Defined in:
lib/mlb_gd2/helpers.rb

Constant Summary collapse

GD2_MLB_BASE =
"http://gd2.mlb.com/components/game/mlb"

Instance Method Summary collapse

Instance Method Details

#boxscore(url) ⇒ Object



24
25
26
# File 'lib/mlb_gd2/helpers.rb', line 24

def boxscore(url)
  generate_nokogiri_xml(url + 'boxscore.xml').xpath("//boxscore").first
end

#build_base_url(date) ⇒ Object



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

def build_base_url(date)
  GD2_MLB_BASE + date.strftime("/year_%Y/month_%m/day_%d/")
end

#generate_nokogiri_html(url) ⇒ Object



12
13
14
# File 'lib/mlb_gd2/helpers.rb', line 12

def generate_nokogiri_html(url)
  Nokogiri::HTML(Net::HTTP.get(URI(url)))
end

#generate_nokogiri_xml(url) ⇒ Object



16
17
18
# File 'lib/mlb_gd2/helpers.rb', line 16

def generate_nokogiri_xml(url)
  Nokogiri::XML(Net::HTTP.get(URI(url)))
end

#valid_game?(url) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/mlb_gd2/helpers.rb', line 20

def valid_game?(url)
  generate_nokogiri_xml(url).xpath('//a').map { |link| link.attribute('href').value }.include? "boxscore.xml"
end