Skip to content

Commit 3cd41ea

Browse files
committed
Modify Worksheet#rows accept a block
Add Worksheet#rows_with_numerics and #rows_with_inputs
1 parent 264a000 commit 3cd41ea

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/google_drive/worksheet.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,29 @@ def cells
321321
def rows(skip = 0)
322322
nc = num_cols
323323
result = ((1 + skip)..num_rows).map do |row|
324-
(1..nc).map { |col| self[row, col] }.freeze
324+
(1..nc).map do |col|
325+
block_given? ? yield(row, col) : self[row, col]
326+
end.freeze
325327
end
326328
result.freeze
327329
end
328330

331+
# Same as +#rows+, but replacing cells with numeric values where they exist
332+
#
333+
# @see #rows
334+
# @see #numeric_value
335+
def rows_with_numerics(skip = 0)
336+
rows(skip) { |row, col| numeric_value(row, col) || self[row, col] }
337+
end
338+
339+
# Same as +#rows, but with input values instead
340+
#
341+
# @see #rows
342+
# @see #input_value
343+
def rows_with_inputs(skip = 0)
344+
rows(skip) { |row, col| input_value(row, col) }
345+
end
346+
329347
# Inserts rows.
330348
#
331349
# e.g.

0 commit comments

Comments
 (0)