/// <summary>Combines metric value with specified one.</summary> /// <param name="other">The metric value to merge.</param> /// <param name="forceMetricUnitUpdate"> /// If set to <c>true</c> existing <see cref="DisplayMetricUnit"/> is updated even if it is not empty. /// </param> /// <returns><c>true</c> if was updated.</returns> public bool UnionWith([NotNull] CompetitionMetricValue other, bool forceMetricUnitUpdate) { if (other.Metric != Metric) { throw CodeExceptions.Argument( nameof(other), $"Passed value metric {other.Metric} does not match to this one {Metric}."); } if (other.ValuesRange.IsEmpty) { return(false); } var result = false; var newValues = ValuesRange.Union(other.ValuesRange); if (newValues != ValuesRange) { ValuesRange = newValues; HasUnsavedChanges = true; result = true; } if (DisplayMetricUnit.IsEmpty || forceMetricUnitUpdate) { var metricUnit = other.DisplayMetricUnit; if (metricUnit.IsEmpty) { metricUnit = Metric.MetricUnits[ValuesRange]; } if (DisplayMetricUnit != metricUnit) { DisplayMetricUnit = metricUnit; HasUnsavedChanges = true; result = true; } } return(result); }
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 async Task <ValuesRange> GetAsync(string sheetId, SpreadsheetGetRequest getRequest, CancellationToken cancellationToken) { (CellCoordinate cellCoordinate, _) = CellCoordinate.ParseRange(getRequest.CellsRange); SpreadsheetsResource.ValuesResource.GetRequest request = _clientService.Spreadsheets.Values.Get(sheetId, $"{getRequest.Sheet}!{getRequest.CellsRange}"); request.ValueRenderOption = SpreadsheetsResource.ValuesResource.GetRequest.ValueRenderOptionEnum.UNFORMATTEDVALUE; ValueRange response = await request.ExecuteAsync(cancellationToken); IList <IList <object> > values = response.Values; IEnumerable <Cell> cells = values.Select((x, row) => x.Select((y, coll) => new Cell { Coordinate = new CellCoordinate { Row = row + cellCoordinate.Row, Column = Column.FromNumber(coll) + cellCoordinate.Column, }, Value = y as string })).SelectMany(x => x); var result = new ValuesRange(cells); return(result); }
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 });
/// <summary>Returns a <see cref="string"/> that represents this instance.</summary> /// <returns>A <see cref="string"/> that represents this instance.</returns> public override string ToString() => ValuesRange.ToString(DisplayMetricUnit);
public SpreadsheetUpdateRequest(string sheet, ValuesRange requestData) { Sheet = sheet; RequestData = requestData; }
public virtual bool Visit(ValuesRange valuesRange) { return(true); }