Skip to content

Commit

Permalink
Modify Worksheet#rows accept a block
Browse files Browse the repository at this point in the history
Add Worksheet#rows_with_numerics and #rows_with_inputs
  • Loading branch information
Drowze committed Jul 21, 2020
1 parent 264a000 commit 3cd41ea
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/google_drive/worksheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,29 @@ 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
#
# @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.
Expand Down

0 comments on commit 3cd41ea

Please sign in to comment.