Skip to content

Commit

Permalink
add spec for matchups
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Hoffman <[email protected]>
  • Loading branch information
Fustrate committed Jun 9, 2024
1 parent 1ceaf61 commit c1adadc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/baseballbot/templates/game_threads/components/matchups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Components
class Matchups
include MarkdownHelpers

BASE_URL = 'https://bdfed.stitch.mlbinfra.com/bdfed/matchup/%<game_pk>s?statList=avg&statList=atBats' \
'&statList=homeRuns&statList=rbi&statList=ops&statList=strikeOuts'
BASE_URL = 'https://bdfed.stitch.mlbinfra.com/bdfed/matchup/%<game_pk>s' \
'?statList=avg,atBats,homeRuns,rbi,ops,strikeOuts'

HEADERS = %w[AVG OPS AB HR RBI K].freeze

Expand Down Expand Up @@ -40,10 +40,10 @@ def away_table
)
end

def player_row(player)
def player_stats(player)
return ['-'] * 6 unless player['stats']

player['stats'].values_at('avg', 'ops', 'atBats', 'homeRuns', 'rbi', 'strikeOuts')
player['stats'].values_at('avg', 'ops', 'atBats', 'homeRuns', 'rbi', 'strikeOuts').map { _1 || '-' }
end

def data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

RSpec.describe Baseballbot::Templates::GameThreads::Components::Matchups do
before do
stub_requests! with_response: true
end

describe '#box_score_section' do
it 'generates a box score' do
expect(described_class.new(game_thread_template(:preview)).to_s).to eq <<~MARKDOWN.strip
|LAD vs. Gray|AVG|OPS|AB|HR|RBI|K|
|-|-|-|-|-|-|-|
|Alberto|-|-|-|-|-|-|
|Barnes, A|-|-|-|-|-|-|
|Bellinger|.500|2.500|2|1|1|1|
|Betts|.400|2.000|5|2|4|0|
|Freeman, F|.000|.111|7|0|1|1|
|Lamb|.000|.250|3|0|0|1|
|Lux|.000|.500|2|0|0|0|
|McKinstry|.167|.611|6|0|0|1|
|Muncy|.000|.250|3|0|0|3|
|Smith, W.D.|.200|.400|5|0|0|1|
|Thompson, T|.500|1.167|2|0|0|1|
|Turner|.500|1.429|14|1|3|4|
|Turner, J|.000|.250|3|0|0|1|
|WSH vs. White|AVG|OPS|AB|HR|RBI|K|
|-|-|-|-|-|-|-|
|Adrianza|.000|.000|1|0|0|1|
|Barrera|-|-|-|-|-|-|
|Bell|.750|1.750|4|0|2|0|
|Cruz, N|-|-|-|-|-|-|
|Escobar, A|-|-|-|-|-|-|
|Franco|.000|.000|3|0|0|1|
|García Jr., L|.667|2.000|3|0|0|0|
|Hernandez, Y|.333|.666|3|0|1|1|
|Hernández, C|.333|.666|3|0|0|1|
|Robles|.667|1.334|3|0|0|0|
|Ruiz, K|.000|.000|3|0|0|0|
|Soto, J|.000|.200|4|0|0|0|
|Thomas, L|.500|1.000|2|0|0|1|
MARKDOWN
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"probables":{"gameType":"R","season":"2022","homeSport":1,"homeLeague":104,"awayLeague":104,"gameDate":"2022-07-26","homeId":119,"awayId":120,"homeAbbreviation":"LAD","awayAbbreviation":"WSH","homeProbable":669952,"awayProbable":680686,"homeProbableLastName":"White","awayProbableLastName":"Gray"},"home":[{"id":593643,"boxscoreName":"Alberto","primaryPosition":"3B"},{"id":605131,"boxscoreName":"Barnes, A","primaryPosition":"C"},{"id":641355,"boxscoreName":"Bellinger","primaryPosition":"CF","stats":{"homeRuns":1,"strikeOuts":1,"avg":".500","atBats":2,"ops":"2.500","rbi":1}},{"id":605141,"boxscoreName":"Betts","primaryPosition":"SS","stats":{"homeRuns":2,"strikeOuts":0,"avg":".400","atBats":5,"ops":"2.000","rbi":4}},{"id":518692,"boxscoreName":"Freeman, F","primaryPosition":"1B","stats":{"homeRuns":0,"strikeOuts":1,"avg":".000","atBats":7,"ops":".111","rbi":1}},{"id":571875,"boxscoreName":"Lamb","primaryPosition":"1B","stats":{"homeRuns":0,"strikeOuts":1,"avg":".000","atBats":3,"ops":".250","rbi":0}},{"id":666158,"boxscoreName":"Lux","primaryPosition":"2B","stats":{"homeRuns":0,"strikeOuts":0,"avg":".000","atBats":2,"ops":".500","rbi":0}},{"id":656716,"boxscoreName":"McKinstry","primaryPosition":"SS","stats":{"homeRuns":0,"strikeOuts":1,"avg":".167","atBats":6,"ops":".611","rbi":0}},{"id":571970,"boxscoreName":"Muncy","primaryPosition":"3B","stats":{"homeRuns":0,"strikeOuts":3,"avg":".000","atBats":3,"ops":".250","rbi":0}},{"id":669257,"boxscoreName":"Smith, W.D.","primaryPosition":"C","stats":{"homeRuns":0,"strikeOuts":1,"avg":".200","atBats":5,"ops":".400","rbi":0}},{"id":572204,"boxscoreName":"Thompson, T","primaryPosition":"RF","stats":{"homeRuns":0,"strikeOuts":1,"avg":".500","atBats":2,"ops":"1.167","rbi":0}},{"id":607208,"boxscoreName":"Turner","primaryPosition":"SS","stats":{"homeRuns":1,"strikeOuts":4,"avg":".500","atBats":14,"ops":"1.429","rbi":3}},{"id":457759,"boxscoreName":"Turner, J","primaryPosition":"1B","stats":{"homeRuns":0,"strikeOuts":1,"avg":".000","atBats":3,"ops":".250","rbi":0}}],"away":[{"id":501303,"boxscoreName":"Adrianza","primaryPosition":"3B","stats":{"homeRuns":0,"strikeOuts":1,"avg":".000","atBats":1,"ops":".000","rbi":0}},{"id":668663,"boxscoreName":"Barrera","primaryPosition":"C"},{"id":605137,"boxscoreName":"Bell","primaryPosition":"1B","stats":{"homeRuns":0,"strikeOuts":0,"avg":".750","atBats":4,"ops":"1.750","rbi":2}},{"id":443558,"boxscoreName":"Cruz, N","primaryPosition":"DH"},{"id":444876,"boxscoreName":"Escobar, A","primaryPosition":"SS"},{"id":596748,"boxscoreName":"Franco","primaryPosition":"3B","stats":{"homeRuns":0,"strikeOuts":1,"avg":".000","atBats":3,"ops":".000","rbi":0}},{"id":671277,"boxscoreName":"García Jr., L","primaryPosition":"2B","stats":{"homeRuns":0,"strikeOuts":0,"avg":".667","atBats":3,"ops":"2.000","rbi":0}},{"id":628450,"boxscoreName":"Hernandez, Y","primaryPosition":"LF","stats":{"homeRuns":0,"strikeOuts":1,"avg":".333","atBats":3,"ops":".666","rbi":1}},{"id":514917,"boxscoreName":"Hernández, C","primaryPosition":"2B","stats":{"homeRuns":0,"strikeOuts":1,"avg":".333","atBats":3,"ops":".666","rbi":0}},{"id":645302,"boxscoreName":"Robles","primaryPosition":"RF","stats":{"homeRuns":0,"strikeOuts":0,"avg":".667","atBats":3,"ops":"1.334","rbi":0}},{"id":660688,"boxscoreName":"Ruiz, K","primaryPosition":"C","stats":{"homeRuns":0,"strikeOuts":0,"avg":".000","atBats":3,"ops":".000","rbi":0}},{"id":665742,"boxscoreName":"Soto, J","primaryPosition":"RF","stats":{"homeRuns":0,"strikeOuts":0,"avg":".000","atBats":4,"ops":".200","rbi":0}},{"id":657041,"boxscoreName":"Thomas, L","primaryPosition":"RF","stats":{"homeRuns":0,"strikeOuts":1,"avg":".500","atBats":2,"ops":"1.000","rbi":0}}]}

0 comments on commit c1adadc

Please sign in to comment.