* lib/csv.rb: Cleaned up some code with Ruby 1.9 idioms.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0c48720b46
commit
d8ad1e28e9
@ -1,3 +1,7 @@
|
|||||||
|
Wed Dec 26 13:55:02 2007 James Edward Gray II <jeg2@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/csv.rb: Cleaned up some code with Ruby 1.9 idioms.
|
||||||
|
|
||||||
Wed Dec 26 13:29:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Dec 26 13:29:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* array.c (tmpbuf): use rb_str_tmp_new().
|
* array.c (tmpbuf): use rb_str_tmp_new().
|
||||||
|
16
lib/csv.rb
16
lib/csv.rb
@ -187,12 +187,10 @@ class CSV
|
|||||||
@header_row = header_row
|
@header_row = header_row
|
||||||
|
|
||||||
# handle extra headers or fields
|
# handle extra headers or fields
|
||||||
larger, smaller, transform = headers.size > fields.size ?
|
@row = if headers.size > fields.size
|
||||||
[headers, fields, :to_a] :
|
headers.each_with_index.map { |header, i| [header, fields[i]] }
|
||||||
[fields, headers, :reverse]
|
else
|
||||||
@row = Array.new
|
fields.each_with_index.map { |field, i| [headers[i], field] }
|
||||||
larger.each_with_index do |e, i|
|
|
||||||
@row << [e, smaller[i]].send(transform)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1814,8 +1812,7 @@ class CSV
|
|||||||
# see if we are converting headers or fields
|
# see if we are converting headers or fields
|
||||||
converters = headers ? @header_converters : @converters
|
converters = headers ? @header_converters : @converters
|
||||||
|
|
||||||
converted = Array.new
|
fields.each_with_index.map do |field, index| # map_with_index
|
||||||
fields.each_with_index do |field, index|
|
|
||||||
converters.each do |converter|
|
converters.each do |converter|
|
||||||
field = if converter.arity == 1 # straight field converter
|
field = if converter.arity == 1 # straight field converter
|
||||||
converter[field]
|
converter[field]
|
||||||
@ -1825,9 +1822,8 @@ class CSV
|
|||||||
end
|
end
|
||||||
break unless field.is_a? String # short-curcuit pipeline for speed
|
break unless field.is_a? String # short-curcuit pipeline for speed
|
||||||
end
|
end
|
||||||
converted << field # final state of each field, converted or original
|
field # final state of each field, converted or original
|
||||||
end
|
end
|
||||||
converted
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user