csv_piper 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65ef899a794a33e576b88a581d6fda1ed60117a8
4
- data.tar.gz: 8b8dad00b3d9f1695a18c35797ab16ce94f31021
3
+ metadata.gz: 29eef903242a17d82a0a17dd906578c12beca220
4
+ data.tar.gz: ea961aa7ed1a1e8d060b3014dc0a224439778fa9
5
5
  SHA512:
6
- metadata.gz: cae8257fbb868ecfc14fe1fd924c34fad5e603d2cc166c32da1943c4f19416223601bba7cf19315945d4271220498955f18f2b49f6424a1af0e733155a03dbdd
7
- data.tar.gz: 61422f90efa60206c57dd4e3d26c072fabf62231059a64d4cd1e130392b3598edee1fc2f2d330f58bb08268cb6507d40e5d318e72bbabc251cbdb957b90b3321
6
+ metadata.gz: c903d63cf41ff9027f9e0d20b6c1f6a057b4d9d969a27e0566c4c34b56a8eef73eddb0d24fd541600b240326500c75780fea479d88a90740bd1f15f248001963
7
+ data.tar.gz: 69b059aadd6a20b73326b94ec449fb4d81f3ab9e076f2a4b8702baa3f4f474e63eb121cfe0225882d837e94bd2ce000ae0122ce2a1116cc6dc3efa38605abefa
data/README.md CHANGED
@@ -45,6 +45,9 @@ output_collector = CollectProcessedEquations.new
45
45
  error_collector = CsvPiper::Processors::CollectErrors.new
46
46
 
47
47
  # Open the csv file to get our io source
48
+ # Csv Data:
49
+ # Input 1,Process,Input 2,Result
50
+ # 1,+,1,2
48
51
  File.open(File.join(File.dirname(__FILE__),"/data/csv_1.csv")) do |file|
49
52
 
50
53
  # Build piper
@@ -154,8 +157,9 @@ Eg. `CsvPiper::Builder.new.from(io).with_processors(processors).build.process`
154
157
  ## Pre-made Processors
155
158
  Over time we will collect a bunch of general purpose processors that anyone can use. They can be found in the `lib/processors` folder but here are a couple:
156
159
 
157
- * `CollectOutput`: Collects the transformed object of every row that is passed through it
158
- * `CollectErrors`: Collects the `RowError` object of every row that is passed through it
160
+ * `Copy`: Copies or maps key-values from the source row into the transformed object.
161
+ * `CollectOutput`: Collects the transformed object of every row that is passed through it.
162
+ * `CollectErrors`: Collects the `RowError` object of every row that is passed through it.
159
163
  * `CreateActiveModel`: Uses the transformed object as attributes and creates using it (Works with ActiveRecord models). Merges errors from model into row errors (Assumes ActiveModel::Errors interface).
160
164
 
161
165
  By using `CollectOutput` and to a lesser extent `CollectErrors` you will start to build up objects in memory. For very large csv files you might not want to use these convenience processors and rather create a new processor that does whatever you need with the row (Ie. log, write to db) which will then be discarded rather than collected.
data/csv_piper.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/jazzarati/csv_piper"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.required_ruby_version = '>= 2'
17
+ spec.required_ruby_version = '>= 2.0.0'
18
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  spec.bindir = "exe"
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -0,0 +1,21 @@
1
+ module CsvPiper
2
+ module Processors
3
+ class Copy
4
+ def initialize(mapping = nil)
5
+ mapping = Hash[ mapping.map { |val| [val, val] } ] if mapping.is_a?(Array)
6
+ @mapping = mapping
7
+ end
8
+
9
+ def process(source, transformed, errors)
10
+ if @mapping.is_a?(Hash)
11
+ transformed = @mapping.each_with_object(transformed) do |(key, new_key), memo|
12
+ memo[new_key] = source[key]
13
+ end
14
+ else
15
+ transformed = transformed.merge(source)
16
+ end
17
+ [transformed, errors]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module CsvPiper
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_piper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarrod Sibbison
@@ -115,6 +115,7 @@ files:
115
115
  - lib/csv_piper/pre_processors/remove_extra_columns.rb
116
116
  - lib/csv_piper/processors/collect_errors.rb
117
117
  - lib/csv_piper/processors/collect_output.rb
118
+ - lib/csv_piper/processors/copy.rb
118
119
  - lib/csv_piper/processors/create_active_model.rb
119
120
  - lib/csv_piper/version.rb
120
121
  homepage: https://github.com/jazzarati/csv_piper
@@ -129,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
130
  requirements:
130
131
  - - ">="
131
132
  - !ruby/object:Gem::Version
132
- version: '2'
133
+ version: 2.0.0
133
134
  required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  requirements:
135
136
  - - ">="