Class: MLBScoreboard::Matchups

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

#hitsObject

Returns the value of attribute hits.



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

def hits
  @hits
end

#runsObject

Returns the value of attribute runs.



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

def runs
  @runs
end

#teamsObject

Returns the value of attribute teams.



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

def teams
  @teams
end

#timeObject

Returns the value of attribute time.



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

def time
  @time
end

Class Method Details

.scrape_errors(i) ⇒ Object



63
64
65
66
67
68
# File 'lib/matchups.rb', line 63

def self.scrape_errors(i)
  errors = []
  errors << @each_game[i.to_i - 1]["linescore"]["e"]["home"]
  errors << @each_game[i.to_i - 1]["linescore"]["e"]["away"]
  errors
end

.scrape_hits(i) ⇒ Object



56
57
58
59
60
61
# File 'lib/matchups.rb', line 56

def self.scrape_hits(i)
  hits = []
  hits << @each_game[i]["linescore"]["h"]["home"]
  hits << @each_game[i]["linescore"]["h"]["away"]
  hits
end

.scrape_matchupsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/matchups.rb', line 9

def self.scrape_matchups
  teams = []
  
  #clock to get previous day so that we get those day's scores
  time = DateTime.now - 1
  day = time.strftime("%d")
  month = time.strftime("%m")
  year = time.strftime("%Y")
  
  #scrape of all matchups
  url = "http://m.mlb.com/gdcross/components/game/mlb/year_#{year}/month_#{month}/day_#{day}/master_scoreboard.json"
  doc = Nokogiri::HTML(open(url))
  
  #parsing the data down to the specific key values we need
  data_hash = JSON.parse(doc)
  @each_game = data_hash["data"]["games"]["game"]
  
  #loop through games, shovel teams into array, format array into quality string for user display
  i = 0
  while i < @each_game.length
    home_team = @each_game[i]["home_team_name"]
    away_team = @each_game[i]["away_team_name"]
    teams << "#{home_team} vs #{away_team}"
    i += 1
  end

  teams
end

.scrape_runs(i) ⇒ Object



49
50
51
52
53
54
# File 'lib/matchups.rb', line 49

def self.scrape_runs(i)
  runs = []
  runs << @each_game[i]["linescore"]["r"]["home"]
  runs << @each_game[i]["linescore"]["r"]["away"]
  runs
end

.scrape_teams(i) ⇒ Object



38
39
40
41
42
# File 'lib/matchups.rb', line 38

def self.scrape_teams(i)
  team = []
  team << @each_game[i]["home_team_name"]
  team << @each_game[i]["away_team_name"]
end

.scrape_time(i) ⇒ Object



44
45
46
47
# File 'lib/matchups.rb', line 44

def self.scrape_time(i)
  time = @each_game[i]["time"]
  "#{time}"
end

.todayObject



5
6
7
# File 'lib/matchups.rb', line 5

def self.today
  self.scrape_matchups
end