Skip to content

Commit

Permalink
Pass variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannakok committed Sep 11, 2024
1 parent b2b4cac commit fed1bf9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions sport/app/cricket/feed/cricketPaDeserialisation.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package conf.cricketPa

import common.Chronos
import cricket.feed.PlayerNames

import xml.{NodeSeq, XML}
import scala.language.postfixOps
Expand All @@ -17,10 +18,11 @@ object Parser {
val matchDetail = parseMatchDetail(matchData)
val lineupData = XML.loadString(lineups)
val scorecardData = XML.loadString(scorecard)
val teams = parseTeams(lineupData \ "match" \ "team")

Match(
parseTeams(lineupData \ "match" \ "team"),
parseInnings(scorecardData \ "match" \ "innings"),
teams,
parseInnings(scorecardData \ "match" \ "innings", teams),
matchDetail.competitionName,
matchDetail.venueName,
matchDetail.result,
Expand Down Expand Up @@ -83,11 +85,14 @@ object Parser {
private def getStatistic(statistics: NodeSeq, statistic: String): String =
(statistics \ "statistic").find(node => (node \ "@type").text == statistic).map(_.text).getOrElse("")

private def parseInnings(innings: NodeSeq): List[Innings] =
private def parseInnings(innings: NodeSeq, teams: List[Team]): List[Innings] =
innings
.map { singleInnings =>
val inningsOrder = (singleInnings \ "@order").text.toInt
val battingTeam = (singleInnings \ "batting" \ "team" \ "name").text

val bowlingTeam = teams.find(_.name == (singleInnings \ "bowling" \ "team" \ "name)").text)

Innings(
inningsOrder,
battingTeam,
Expand All @@ -96,7 +101,7 @@ object Parser {
getStatistic(singleInnings, "declared") == "true",
getStatistic(singleInnings, "forefeited") == "true",
inningsDescription(inningsOrder, battingTeam),
parseInningsBatters(singleInnings \ "batting" \ "batter"),
parseInningsBatters(singleInnings \ "batting" \ "batter", bowlingTeam),
parseInningsBowlers(singleInnings \ "bowling" \ "bowler"),
parseInningsWickets(singleInnings \ "fallenWicket"),
getStatistic(singleInnings, "extra-byes").toInt,
Expand All @@ -110,7 +115,7 @@ object Parser {
.toList
.sortBy(_.order)

private def parseInningsBatters(batters: NodeSeq): List[InningsBatter] =
private def parseInningsBatters(batters: NodeSeq, bowlingTeam: Option[Team]): List[InningsBatter] =
batters
.map { batter =>
InningsBatter(
Expand Down

0 comments on commit fed1bf9

Please sign in to comment.