Sha256: c433ee705d8541e7d1ff46ff6ef035b0185c4c1cd8e3a2d2d0c45f5f1aafcbe4

Contents?: true

Size: 591 Bytes

Versions: 18

Compression:

Stored size: 591 Bytes

Contents

#!/usr/local/bin/ruby -w

# csv_converters.rb
#
#  Created by James Edward Gray II on 2006-11-05.
#  Copyright 2006 Gray Productions. All rights reserved.

require "faster_csv"

# convert a specific column
options = {
  :headers           => true,
  :header_converters => :symbol,
  :converters        => [
    lambda { |f, info| info.index.zero?       ? f.to_i : f },
    lambda { |f, info| info.header == :floats ? f.to_f : f }
  ]
}
table = FCSV(DATA, options) { |csv| csv.read }

table[:ints]    # => [1, 2, 3]
table[:floats]  # => [1.0, 2.0, 3.0]

__END__
ints,floats
1,1.000
2,2
3,3.0

Version data entries

18 entries across 18 versions & 6 rubygems

Version Path
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/fastercsv-1.5.5/examples/csv_converters.rb
StephanZ-fastercsv-1.4.1 examples/csv_converters.rb
b2b2dot0-fastercsv-1.4.1 examples/csv_converters.rb
fastercsv-1.5.5 examples/csv_converters.rb
glennfu-faster_csv-1.5.5.1 examples/csv_converters.rb
fastercsv-1.5.4 examples/csv_converters.rb
rw_fastercsv-1.5.7 examples/csv_converters.rb
rw_fastercsv-1.5.6 examples/csv_converters.rb
fastercsv-1.5.3 examples/csv_converters.rb
fastercsv-1.5.1 examples/csv_converters.rb
fastercsv-1.1.0 examples/csv_converters.rb
fastercsv-1.1.1 examples/csv_converters.rb
fastercsv-1.2.0 examples/csv_converters.rb
fastercsv-1.5.0 examples/csv_converters.rb
fastercsv-1.4.0 examples/csv_converters.rb
fastercsv-1.2.3 examples/csv_converters.rb
fastercsv-1.2.1 examples/csv_converters.rb
fastercsv-1.2.2 examples/csv_converters.rb