smarter_csv 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -4
- data/lib/smarter_csv/smarter_csv.rb +2 -1
- data/lib/smarter_csv/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -127,7 +127,7 @@ The options and the block are optional.
|
|
127
127
|
`SmarterCSV.process` supports the following options:
|
128
128
|
|
129
129
|
Option | Default | Explanation
|
130
|
-
|
130
|
+
--------------------------------+-----------+--------------------------------------------------------------
|
131
131
|
:col_sep | ',' | column separator
|
132
132
|
:row_sep | $/ ,"\n" | row separator or record separator , defaults to system's $/ , which defaults to "\n"
|
133
133
|
:quote_char | '"' | quotation character
|
@@ -136,14 +136,16 @@ The options and the block are optional.
|
|
136
136
|
:key_mapping | nil | a hash which maps headers from the CSV file to keys in the result hash
|
137
137
|
:downcase_header | true | downcase all column headers
|
138
138
|
:strings_as_keys | false | use strings instead of symbols as the keys in the result hashes
|
139
|
+
:strip_whitepace_from_values| true | remove whitespace before/after values
|
139
140
|
:remove_empty_values | true | remove values which have nil or empty strings as values
|
140
141
|
:remove_zero_values | true | remove values which have a numeric value equal to zero / 0
|
141
142
|
:remove_values_matching | nil | removes key/value pairs if value matches given regular expressions. e.g.:
|
142
143
|
| | /^\$0\.0+$/ to match $0.00 , or /^#VALUE!$/ to match errors in Excel spreadsheets
|
143
144
|
:convert_values_to_numeric | true | converts strings containing Integers or Floats to the appropriate class
|
144
145
|
:remove_empty_hashes | true | remove / ignore any hashes which don't have any key/value pairs
|
145
|
-
:user_provided_headers | nil |
|
146
|
-
| |
|
146
|
+
:user_provided_headers | nil | *careful with that axe!*
|
147
|
+
| | user provided Array of header strings or symbols, to define
|
148
|
+
| | what headers should be used, overriding any in-file headers.
|
147
149
|
| | You can not combine the :user_provided_headers and :key_mapping options
|
148
150
|
:headers_in_file | true | Whether or not the file contains headers as the first line.
|
149
151
|
| | Important if the file does not contain headers,
|
@@ -194,7 +196,12 @@ Or install it yourself as:
|
|
194
196
|
|
195
197
|
## Changes
|
196
198
|
|
197
|
-
#### 1.0.
|
199
|
+
#### 1.0.3 (2012-08-02)
|
200
|
+
|
201
|
+
* added the following options:
|
202
|
+
* strip_whitepace_from_values
|
203
|
+
|
204
|
+
#### 1.0.2 (2012-08-02)
|
198
205
|
|
199
206
|
* added more options for dealing with headers:
|
200
207
|
* :user_provided_headers ,user provided Array with header strings or symbols, to precisely define what the headers should be, overriding any in-file headers (default: nil)
|
@@ -5,7 +5,7 @@ module SmarterCSV
|
|
5
5
|
|
6
6
|
def SmarterCSV.process(filename, options={}, &block)
|
7
7
|
default_options = {:col_sep => ',' , :row_sep => $/ , :quote_char => '"',
|
8
|
-
:remove_empty_values => true, :remove_zero_values => false , :remove_values_matching => nil , :remove_empty_hashes => true ,
|
8
|
+
:remove_empty_values => true, :remove_zero_values => false , :remove_values_matching => nil , :remove_empty_hashes => true , :strip_whitespace_from_values => true,
|
9
9
|
:convert_values_to_numeric => true, :strip_chars_from_headers => nil , :user_provided_headers => nil , :headers_in_file => true,
|
10
10
|
:comment_regexp => /^#/, :chunk_size => nil , :key_mapping_hash => nil , :downcase_header => true, :strings_as_keys => false
|
11
11
|
}
|
@@ -68,6 +68,7 @@ module SmarterCSV
|
|
68
68
|
line.chomp! # will use $/ which is set to options[:col_sep]
|
69
69
|
|
70
70
|
dataA = line.split(options[:col_sep])
|
71
|
+
dataA.map!{|x| x.strip} if options[:strip_whitespace_from_values]
|
71
72
|
hash = Hash.zip(headerA,dataA) # from Facets of Ruby library
|
72
73
|
# make sure we delete any key/value pairs from the hash, which the user wanted to delete:
|
73
74
|
hash.delete(nil); hash.delete(''); hash.delete(:"") # delete any hash keys which were mapped to be deleted
|
data/lib/smarter_csv/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smarter_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-08-
|
14
|
+
date: 2012-08-17 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: Ruby Gem for smarter importing of CSV Files as Array(s) of Hashes, with
|
17
17
|
optional features for processing large files in parallel, embedded comments, unusual
|