Skip to content

Commit

Permalink
updated doc; minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tilo committed Nov 26, 2016
1 parent 834ed51 commit 306dbce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ One `smarter_csv` user wrote:
* able to ignore "columns" in the input (delete columns)
* able to eliminate nil or empty fields from the result hashes (default)

NOTE; This Gem is only for importing CSV files - writing of CSV files is not supported.
NOTE; This Gem is only for importing CSV files - writing of CSV files is not supported at this time.

### Why?

Expand Down Expand Up @@ -130,6 +130,8 @@ and how the `process` method returns the number of chunks when called with a blo

#### Example 6: Using Value Converters

NOTE: If you use `key_mappings` and `value_converters`, make sure that the value converters has references the keys based on the final mapped name, not the original name in the CSV file.

$ cat spec/fixtures/with_dates.csv
first,last,date,price
Ben,Miller,10/30/1998,$44.50
Expand Down Expand Up @@ -273,9 +275,19 @@ Or install it yourself as:

$ gem install smarter_csv

## Upcoming

Planned in the next releases:
* programmatic header transformations
* CSV command line

## Changes

#### 1.1.1 (2016-11-26)
* bugfix if no headers in input data (thanks to esBeee)
* ensure input file is closed (thanks to waldyr)
* improved documentation

#### 1.1.0 (2015-07-26)
* added feature :value_converters, which allows parsing of dates, money, and other things (thanks to Raphaël Bleuse, Lucas Camargo de Almeida, Alejandro)
* added error if :headers_in_file is set to false, and no :user_provided_headers are given (thanks to innhyu)
Expand Down Expand Up @@ -406,6 +418,8 @@ And a special thanks to those who contributed pull requests:
* [Jordan Running](https://github.com/jrunning)
* [Dave Sanders](https://github.com/DaveSanders)
* [Hugo Lepetit](https://github.com/giglemad)
* [esBeee](https://github.com/esBeee)
* [Waldyr de Souza](https://github.com/waldyr)


## Contributing
Expand Down
9 changes: 2 additions & 7 deletions lib/smarter_csv/smarter_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def SmarterCSV.process(input, options={}, &block) # first parameter: filename
header = f.readline.sub(options[:comment_regexp],'').chomp(options[:row_sep])
line_count += 1
header = header.gsub(options[:strip_chars_from_headers], '') if options[:strip_chars_from_headers]
if (header =~ %r{#{options[:quote_char]}}) and (! options[:force_simple_split])
if (header =~ %r{#{options[:quote_char]}}) && (! options[:force_simple_split])
file_headerA = CSV.parse( header, csv_options ).flatten.collect!{|x| x.nil? ? '' : x} # to deal with nil values from CSV.parse
else
file_headerA = header.split(options[:col_sep])
Expand Down Expand Up @@ -102,7 +102,7 @@ def SmarterCSV.process(input, options={}, &block) # first parameter: filename

line.chomp! # will use $/ which is set to options[:col_sep]

if (line =~ %r{#{options[:quote_char]}}) and (! options[:force_simple_split])
if (line =~ %r{#{options[:quote_char]}}) && (! options[:force_simple_split])
dataA = CSV.parse( line, csv_options ).flatten.collect!{|x| x.nil? ? '' : x} # to deal with nil values from CSV.parse
else
dataA = line.split(options[:col_sep])
Expand Down Expand Up @@ -197,11 +197,6 @@ def SmarterCSV.process(input, options={}, &block) # first parameter: filename
end
end

# def SmarterCSV.process_csv(*args)
# warn "[DEPRECATION] `process_csv` is deprecated. Please use `process` instead."
# SmarterCSV.process(*args)
# end

private
# acts as a road-block to limit processing when iterating over all k/v pairs of a CSV-hash:

Expand Down

0 comments on commit 306dbce

Please sign in to comment.