public static List <DataObjects.Goal> GetGoalsFromString(string s)
        {
            var toReturn = new List <DataObjects.Goal>();
            //Olivier Giroud (5, 78, 80)
            //Mark Bunn (90 + 2 OG)
            //Wayne Rooney (43)

            var name = s.Split('(').First().Trim();
            var contentWithinParentheses = Helper.GetContentWithinParenthesis(s).ToLower();
            var isOwnGoals = contentWithinParentheses.EndsWith("og");
            var minutes    = contentWithinParentheses.Replace("og", "").Trim().Split(',').ToList();

            foreach (var minute in minutes)
            {
                var g = new DataObjects.Goal();
                g.IsOwnGoal = isOwnGoals;
                g.Scorer    = name;

                var min = minute.ToLower().Replace("pen", "").Replace("minutes", "").Replace("'", "").Trim();
                if (minute.Contains("+"))
                {
                    min = minute.Split('+').First().Trim().Replace("'", "");
                }


                g.Minute = int.Parse(min);

                toReturn.Add(g);
            }


            return(toReturn);
        }
Beispiel #2
0
        public static List <DataObjects.Goal> NormalizeGoalDetails(string details)
        {
            var toReturn    = new List <DataObjects.Goal>();
            var detailsList = details.Replace("ET", "").Trim().Split().ToList().Where(x => !string.IsNullOrEmpty(x)).ToList();
            var isOwnGoal   = detailsList.Last() == "og";

            int minute            = 0;
            var minutes           = new List <int>();
            var minutePlaces      = 0;
            var addedFirstALready = false;

            for (var i = 0; i < detailsList.Count; i++)
            {
                var val = detailsList[i].Trim(',');
                if (val.Contains("+"))
                {
                    val = val.Split('+').First();
                }

                if (int.TryParse(val, out minute))
                {
                    minutes.Add(minute);
                    if (!addedFirstALready)
                    {
                        minutePlaces      = i;
                        addedFirstALready = true;
                    }
                }
            }

            var scorer = string.Join(" ", detailsList.GetRange(0, minutePlaces));

            foreach (var min in minutes)
            {
                var newGoal = new DataObjects.Goal();
                newGoal.Scorer    = scorer;
                newGoal.Minute    = min;
                newGoal.IsOwnGoal = isOwnGoal;
                toReturn.Add(newGoal);
            }

            return(toReturn);
        }