public IEnumerable <ParsingResult> ExtractFood(ValuesRange valuesRange) { string lastCategory = string.Empty; foreach (var row in valuesRange.AsEnumerable()) { lastCategory = string.IsNullOrEmpty(row.First().Value) ? lastCategory : row.First().Value; foreach (var cell in row.Skip(1).Where(x => !string.IsNullOrEmpty(x.Value)) .Select((x, index) => new { x, index = index + 1 })) { yield return(new ParsingResult { Category = lastCategory, Name = cell.x.Value, Price = 0, Day = (Week)cell.index }); } } }
public IEnumerable <ParsingResult> ExtractFood(ValuesRange valuesRange) { string lastCategory = string.Empty; Regex rx = new Regex("^(.*?)(?<price>\\d{1,3})$"); foreach (var row in valuesRange.AsEnumerable()) { foreach (var cell in row.Where(x => !string.IsNullOrEmpty(x.Value)) .Select((x, index) => new { x, index = index + 1 })) { if (cell.x.Value.StartsWith("__")) { lastCategory = cell.x.Value.Trim('_'); } else { yield return(new ParsingResult { Category = lastCategory, Name = cell.x.Value, Price = decimal.TryParse(rx.Match(cell.x.Value).Groups["price"].Value, out decimal price) ? price : 0, Day = (Week)cell.index });