smarter_csv 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -136,7 +136,7 @@ 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
+ :strip_whitespace | true | remove whitespace before/after values and headers
140
140
  :remove_empty_values | true | remove values which have nil or empty strings as values
141
141
  :remove_zero_values | true | remove values which have a numeric value equal to zero / 0
142
142
  :remove_values_matching | nil | removes key/value pairs if value matches given regular expressions. e.g.:
@@ -196,10 +196,15 @@ Or install it yourself as:
196
196
 
197
197
  ## Changes
198
198
 
199
- #### 1.0.3 (2012-08-02)
199
+ #### 1.0.4 (2012-08-17)
200
+
201
+ * renamed the following options:
202
+ * :strip_whitepace_from_values => :strip_whitespace - removes leading/trailing whitespace from headers and values
203
+
204
+ #### 1.0.3 (2012-08-16)
200
205
 
201
206
  * added the following options:
202
- * strip_whitepace_from_values
207
+ * :strip_whitepace_from_values - removes leading/trailing whitespace from values
203
208
 
204
209
  #### 1.0.2 (2012-08-02)
205
210
 
@@ -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 , :strip_whitespace_from_values => true,
8
+ :remove_empty_values => true, :remove_zero_values => false , :remove_values_matching => nil , :remove_empty_hashes => true , :strip_whitespace => 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
  }
@@ -22,7 +22,9 @@ module SmarterCSV
22
22
  # the first line of a CSV file contains the header .. it might be commented out, so we need to read it anyhow
23
23
  header = f.readline.sub(options[:comment_regexp],'').chomp(options[:row_sep])
24
24
  header = header.gsub(options[:strip_chars_from_headers], '') if options[:strip_chars_from_headers]
25
- file_headerA = header.split(options[:col_sep]).map{|x| x.gsub(%r/options[:quote_char]/,'').gsub(/\s+/,'_')}
25
+ file_headerA = header.split(options[:col_sep]).map{|x| x.gsub(%r/options[:quote_char]/,'')}
26
+ file_headerA.map!{|x| x.strip} if options[:strip_whitespace]
27
+ file_headerA.map!{|x| x.gsub(/\s+/,'_')}
26
28
  file_headerA.map!{|x| x.downcase } if options[:downcase_header]
27
29
  file_header_size = file_headerA.size
28
30
  end
@@ -68,7 +70,7 @@ module SmarterCSV
68
70
  line.chomp! # will use $/ which is set to options[:col_sep]
69
71
 
70
72
  dataA = line.split(options[:col_sep])
71
- dataA.map!{|x| x.strip} if options[:strip_whitespace_from_values]
73
+ dataA.map!{|x| x.strip} if options[:strip_whitespace]
72
74
  hash = Hash.zip(headerA,dataA) # from Facets of Ruby library
73
75
  # make sure we delete any key/value pairs from the hash, which the user wanted to delete:
74
76
  hash.delete(nil); hash.delete(''); hash.delete(:"") # delete any hash keys which were mapped to be deleted
@@ -1,3 +1,3 @@
1
1
  module SmarterCSV
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
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.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: