From 2c05551565dd244891292e5248c69893f85afd15 Mon Sep 17 00:00:00 2001 From: Drowze Date: Tue, 21 Jul 2020 23:04:43 +0100 Subject: [PATCH] Modify Worksheet#rows accept a block Add Worksheet#rows_with_numerics and #rows_with_inputs --- lib/google_drive/worksheet.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/google_drive/worksheet.rb b/lib/google_drive/worksheet.rb index b461630f..c62319bf 100644 --- a/lib/google_drive/worksheet.rb +++ b/lib/google_drive/worksheet.rb @@ -321,11 +321,31 @@ def cells def rows(skip = 0) nc = num_cols result = ((1 + skip)..num_rows).map do |row| - (1..nc).map { |col| self[row, col] }.freeze + (1..nc).map do |col| + block_given? ? yield(row, col) : self[row, col] + end.freeze end result.freeze end + # Same as +#rows+, but replacing cells with numeric values where they exist. + # Please note that this will NOT replace dirty cells with their numeric + # value. + # + # @see #rows + # @see #numeric_value + def rows_with_numerics(skip = 0) + rows(skip) { |row, col| numeric_value(row, col) || self[row, col] } + end + + # Same as +#rows+, but with input values instead + # + # @see #rows + # @see #input_value + def rows_with_inputs(skip = 0) + rows(skip) { |row, col| input_value(row, col) } + end + # Inserts rows. # # e.g.