private Spreadsheet(Dictionary <int, ISpreadsheetRow> rows, ISpreadsheetHeader spreadsheetHeader) { ColumnCount = spreadsheetHeader.ColumnCount; RowCount = rows.Keys.Max() + 1; _spreadsheetHeader = spreadsheetHeader; _emptyRow = new SpreadsheetRow(_spreadsheetHeader, Enumerable.Empty <KeyValuePair <int, string> >()); _rowsByIndex = rows; }
public static bool HasTruthyValue(this ISpreadsheetRow row, Products productList) { foreach (var key in productList.ProductNames) { var value = row[key]; if (IsTruthy(value)) { return(true); } } return(false); }
public Spreadsheet(IEnumerable <Cell> cells, IEnumerable <KeyValuePair <int, string> > columnHeaders = null) { columnHeaders = columnHeaders ?? Enumerable.Empty <KeyValuePair <int, string> >(); //TODO: improve performance here RowCount = cells.Max(x => x.Row) + 1; ColumnCount = cells.Select(x => x.Column).Union(columnHeaders.Select(x => x.Key)).Max() + 1; _spreadsheetHeader = new SpreadsheetHeader(ColumnCount, columnHeaders); _emptyRow = new SpreadsheetRow(_spreadsheetHeader, Enumerable.Empty <KeyValuePair <int, string> >()); _rowsByIndex = cells.GroupBy(x => x.Row) .ToDictionary( x => x.Key, x => (ISpreadsheetRow) new SpreadsheetRow(_spreadsheetHeader, x.Select(y => new KeyValuePair <int, string>(y.Column, y.Value)))); }