smarter_csv 1.0.0.pre1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,7 +23,7 @@ As the existing CSV libraries didn't fit my needs, I was writing my own CSV proc
23
23
  #### Example 1: Reading a CSV-File in one Chunk, returning one Array of Hashes:
24
24
 
25
25
  filename = '/tmp/input_file.txt' # TAB delimited file, each row ending with Control-M
26
- recordsA = SmarterCSV.process_csv(filename, {:col_sep => "\t", :row_sep => "\cM"}
26
+ recordsA = SmarterCSV.process(filename, {:col_sep => "\t", :row_sep => "\cM"}
27
27
 
28
28
  => returns an array of hashes
29
29
 
@@ -31,7 +31,7 @@ As the existing CSV libraries didn't fit my needs, I was writing my own CSV proc
31
31
 
32
32
  # without using chunks:
33
33
  filename = '/tmp/some.csv'
34
- n = SmarterCSV.process_csv(filename, {:key_mapping => {:unwanted_row => nil, :old_row_name => :new_name}}) do |array|
34
+ n = SmarterCSV.process(filename, {:key_mapping => {:unwanted_row => nil, :old_row_name => :new_name}}) do |array|
35
35
  # we're passing a block in, to process each resulting hash / =row (the block takes array of hashes)
36
36
  # when chunking is not enabled, there is only one hash in each array
37
37
  MyModel.create( array.first )
@@ -44,7 +44,7 @@ As the existing CSV libraries didn't fit my needs, I was writing my own CSV proc
44
44
 
45
45
  # using chunks:
46
46
  filename = '/tmp/some.csv'
47
- n = SmarterCSV.process_csv(filename, {:key_mapping => {:unwanted_row => nil, :old_row_name => :new_name}, :chunk_size => 100}) do |array|
47
+ n = SmarterCSV.process(filename, {:key_mapping => {:unwanted_row => nil, :old_row_name => :new_name}, :chunk_size => 100}) do |array|
48
48
  # we're passing a block in, to process each resulting hash / row (block takes array of hashes)
49
49
  # when chunking is enabled, there are up to :chunk_size hashes in each array
50
50
  MyModel.collection.insert( array ) # insert up to 100 records at a time
@@ -56,13 +56,19 @@ As the existing CSV libraries didn't fit my needs, I was writing my own CSV proc
56
56
  #### Example 4: Reading a CSV-like File, and Processing it with Resque:
57
57
 
58
58
  filename = '/tmp/strange_db_dump' # a file with CRTL-A as col_separator, and with CTRL-B\n as record_separator (hello iTunes)
59
- n = SmarterCSV.process_csv(filename, {:col_sep => "\cA", :row_sep => "\cB\n", :comment_regexp => /^#/,
59
+ n = SmarterCSV.process(filename, {:col_sep => "\cA", :row_sep => "\cB\n", :comment_regexp => /^#/,
60
60
  :chunk_size => '5' , :key_mapping => {:export_date => nil, :name => :genre}}) do |x|
61
61
  puts "Resque.enque( ResqueWorkerClass, #{x.size}, #{x.inspect} )" # simulate processing each chunk
62
62
  end
63
63
  => returns number of chunks
64
64
 
65
65
 
66
+ ## See also:
67
+
68
+ http://www.unixgods.org/~tilo/Ruby/process_csv_as_hashes.html
69
+
70
+
71
+
66
72
  ## Installation
67
73
 
68
74
  Add this line to your application's Gemfile:
@@ -89,10 +95,3 @@ TODO: Write usage instructions here
89
95
  4. Push to the branch (`git push origin my-new-feature`)
90
96
  5. Create new Pull Request
91
97
 
92
-
93
- ## See also:
94
-
95
- http://www.unixgods.org/~tilo/Ruby/process_csv_as_hashes.html
96
-
97
- https://gist.github.com/3101950
98
-
@@ -29,7 +29,7 @@ module SmarterCSV
29
29
  # This can be very useful when passing chunked data to a post-processing step, e.g. through Resque
30
30
  #
31
31
 
32
- def SmarterCSV.process_csv(filename, options={}, &block)
32
+ def SmarterCSV.process(filename, options={}, &block)
33
33
  default_options = {:col_sep => ',' , :row_sep => $/ , :quote_char => '"', :remove_empty_fields => true,
34
34
  :comment_regexp => /^#/, :chunk_size => nil , :key_mapping_hash => nil
35
35
  }
@@ -107,5 +107,9 @@ module SmarterCSV
107
107
  end
108
108
  end
109
109
 
110
+ def SmarterCSV.process_csv(*args)
111
+ warn "[DEPRECATION] `process_csv` is deprecated. Please use `process` instead."
112
+ SmarterCSV.process(*args)
113
+ end
110
114
  end
111
115
 
@@ -1,3 +1,3 @@
1
1
  module SmarterCSV
2
- VERSION = "1.0.0.pre1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smarter_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre1
5
- prerelease: 6
4
+ version: 1.0.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - ! 'Tilo Sloboda
@@ -50,9 +50,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
50
  required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
- - - ! '>'
53
+ - - ! '>='
54
54
  - !ruby/object:Gem::Version
55
- version: 1.3.1
55
+ version: '0'
56
56
  requirements: []
57
57
  rubyforge_project:
58
58
  rubygems_version: 1.8.15