Class: Gameday

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

Constant Summary collapse

GD2_MLB_BASE =

Change this to point to the server you are reading Gameday data from

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

Instance Method Summary collapse

Constructor Details

#initializeGameday

Returns a new instance of Gameday.



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

def initialize
  super
end

Instance Method Details

#convert_to_two_digit_str(number) ⇒ Object

Converts numbers to two character strings by prepending a ‘0’ if number is less than 10.



47
48
49
50
51
52
53
# File 'lib/gameday.rb', line 47

def convert_to_two_digit_str(number)
  if number < 10
    return '0'+number.to_s
  else
    return number.to_s
  end
end

#get_all_gids_for_date(year, month, day) ⇒ Object

Returns an array of game id’s for the given date



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gameday.rb', line 22

def get_all_gids_for_date(year, month, day)
  begin 
    gids = []
    url = GamedayUtil.build_day_url(year, month, date)
    connection = GamedayUtil.get_connection(url)
    if connection
      @hp = Hpricot(connection) 
      a = @hp.at('ul')  
      (a/"a").each do |link|
        if link.inner_html.include?('gid')
          str = link.inner_html
          gids.push str[5..str.length-2]
        end
      end
    end
    connection.close
    return gids
  rescue
    puts "No games data found for #{year}, #{month}, #{day}."
  end
end