summaryrefslogtreecommitdiff
path: root/lib/csv
diff options
context:
space:
mode:
authorBurdette Lamar <[email protected]>2020-09-05 17:03:37 -0500
committerSutou Kouhei <[email protected]>2020-11-24 09:33:55 +0900
commite8954fa13b3d2cf11f425897f9d12397fc4a9ecb ()
tree8d47dc056f375592c06dd7da8ecbccc274116d9e /lib/csv
parent31ccc233b1789f97dbf741c9e84b674af4a452d5 (diff)
[ruby/csv] Enhanced RDoc for CSV::Row (#171)
https://.com/ruby/csv/commit/cced8d8de9
Notes: Merged: https://.com/ruby/ruby/pull/3804
-rw-r--r--lib/csv/.editorconfig0
-rw-r--r--lib/csv/row.rb150
2 files changed, 119 insertions, 31 deletions
@@ -279,17 +279,34 @@ class CSV
#
# :call-seq:
- # <<( field )
- # <<( header_and_field_array )
- # <<( header_and_field_hash )
#
- # If a two-element Array is provided, it is assumed to be a header and field
- # and the pair is appended. A Hash works the same way with the key being
- # the header and the value being the field. Anything else is assumed to be
- # a lone field which is appended with a +nil+ header.
#
- # This method returns the row for chaining.
#
def <<(arg)
if arg.is_a?(Array) and arg.size == 2 # appending a header and name
@row << arg
@@ -302,13 +319,15 @@ class CSV
self # for chaining
end
#
- # A shortcut for appending multiple fields. Equivalent to:
- #
- # args.each { |arg| csv_row << arg }
- #
- # This method returns the row for chaining.
- #
def push(*args)
args.each { |arg| self << arg }
@@ -317,14 +336,39 @@ class CSV
#
# :call-seq:
- # delete( header )
- # delete( header, offset )
- # delete( index )
#
- # Removes a pair from the row by +header+ or +index+. The pair is
- # located as described in CSV::Row.field(). The deleted pair is returned,
- # or +nil+ if a pair could not be found.
#
def delete(header_or_index, minimum_index = 0)
if header_or_index.is_a? Integer # by index
@row.delete_at(header_or_index)
@@ -335,15 +379,21 @@ class CSV
end
end
#
- # The provided +block+ is passed a header and field for each pair in the row
- # and expected to return +true+ or +false+, depending on whether the pair
- # should be deleted.
- #
- # This method returns the row for chaining.
#
- # If no block is given, an Enumerator is returned.
#
def delete_if(&block)
return enum_for(__method__) { size } unless block_given?
@@ -352,14 +402,52 @@ class CSV
self # for chaining
end
#
- # This method accepts any number of arguments which can be headers, indices,
- # Ranges of either, or two-element Arrays containing a header and offset.
- # Each argument will be replaced with a field lookup as described in
- # CSV::Row.field().
#
- # If called with no arguments, all fields are returned.
#
def fields(*headers_and_or_indices)
if headers_and_or_indices.empty? # return all fields--no arguments
@row.map(&:last)