Created
October 2, 2020 20:34
-
-
Save kspurgin/f14d334c9d52ba2a961e64a39465fcec to your computer and use it in GitHub Desktop.
Exploring Ruby CSV standard library default handling of empty cell values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2.6.3 :001 > require 'csv' | |
=> true | |
2.6.3 :002 > csv = CSV.parse(File.read('required_field_empty.csv'), headers: true) | |
=> #<CSV::Table mode:col_or_row row_count:4> | |
2.6.3 :003 > rows = [] | |
=> [] | |
2.6.3 :004 > csv.each{ |r| rows << r.to_h } | |
=> #<CSV::Table mode:col_or_row row_count:4> | |
2.6.3 :024 > rows[1]['objectNumber'] | |
=> nil | |
-=-=-=-=-=-=- | |
2.6.3 :030 > rows = [] | |
=> [] | |
2.6.3 :031 > csv = CSV.parse(File.read('required_field_empty.csv'), headers: true, nil_value: '') | |
=> #<CSV::Table mode:col_or_row row_count:4> | |
2.6.3 :032 > csv.each{ |r| rows << r.to_h } | |
=> #<CSV::Table mode:col_or_row row_count:4> | |
2.6.3 :033 > rows[1]['objectNumber'] | |
=> "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment