csv_piper 0.1.4 → 0.1.5

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: 8769722439ae9b640dedf199eb2a16a23d8b8be7
4
- data.tar.gz: 1d4b35a6277fec01080e61831913dac7bce9b499
3
+ metadata.gz: 78f4de44ae17599fe675a8309f1fe6a5509e7573
4
+ data.tar.gz: 457ea3be103e375d63f1381d9fd313edee9b5f62
5
5
  SHA512:
6
- metadata.gz: 1a5c885a3513e441075c0de6e99b46f1be3eb63d9408a894566290ca262c3b6313a04527ce24cc89ac7cf231b72542418df232c785e7448cb3a7c567be07128f
7
- data.tar.gz: 608d031277fb6b598d9da0b295b80e7347e4668ab7d1891d080cdaed870a55b58dbeb0917333bfaa6030bc4af0b1d5a8da9fcfe74787643e30e41fd8e87a9571
6
+ metadata.gz: bcaf281ec4903d7b2f8858d42208679f146fd3bb1d65e75a406d87a8f60bea8c0f69416b3b4a8944ec2c65057c95c673a1dced66f58fa9e608a5a672b290ca3a
7
+ data.tar.gz: dde6626276fc85fc710c90706b1eb0ed015420fd0ef3d4a5121040361166cf18e1d00d01cea7aa9032c5e2f6f1b44953c1230f76f9c9e43e4fbaa5f9d2e80819
data/README.md CHANGED
@@ -170,6 +170,10 @@ Require them explicitly if you want to use them.
170
170
 
171
171
  Eg. `require 'csv_piper/processors/collect_output'`
172
172
 
173
+ ## Test Support
174
+
175
+ There is a CsvMockFile object that you can use to mock up an io csv source rather than working with on disk files for your tests. Just `require 'csv_piper/test_support/csv_mock_file'`.
176
+
173
177
  ## Inspiration
174
178
 
175
179
  Initial inspiration crystalised upon seeing [Kiba](https://github.com/thbar/kiba). If you need to do extensive ETL (particularly if you don't have csv's) then strongly recommend you check it out.
@@ -0,0 +1,38 @@
1
+ module CsvPiper
2
+ module TestSupport
3
+ class CsvMockFile
4
+ extend Forwardable
5
+
6
+ def self.create(headers, separator = ',')
7
+ csv = new(headers, separator)
8
+ yield csv if block_given?
9
+ csv.rewind
10
+ csv
11
+ end
12
+
13
+ attr_reader :headers, :io, :seperator
14
+ delegate [:readline, :readlines, :rewind, :gets] => :io
15
+
16
+ # Using a StringIO object instead of reading/writing files from disk
17
+ def initialize(headers, seperator = ',')
18
+ raise "Must have atleast one header" if headers.empty?
19
+ @headers = headers.sort
20
+ @seperator = seperator
21
+ @io = StringIO.new("w+")
22
+ io.puts(@headers.join(seperator))
23
+ end
24
+
25
+ def add(row_hash)
26
+ raise "Headers don't match #{row_hash.keys - headers}" unless (row_hash.keys - headers).empty?
27
+ row = headers.map { |key| row_hash[key] || '' }.join(seperator)
28
+ io.puts(row)
29
+ end
30
+
31
+ def write_to_file(path)
32
+ File.open(path, 'w+') do |f|
33
+ f.write(io.read)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module CsvPiper
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/csv_piper.rb CHANGED
@@ -1,6 +1,5 @@
1
- require "csv_piper/version"
2
- require "csv_piper/piper"
3
- require "csv_piper/builder"
4
- require "csv_piper/errors/row"
5
- require "csv_piper/pre_processors/remove_extra_columns"
6
- require "csv"
1
+ require 'csv_piper/version'
2
+ require 'csv_piper/piper'
3
+ require 'csv_piper/builder'
4
+ require 'csv_piper/errors/row'
5
+ require 'csv'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_piper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarrod Sibbison
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-17 00:00:00.000000000 Z
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -118,6 +118,7 @@ files:
118
118
  - lib/csv_piper/processors/collect_output.rb
119
119
  - lib/csv_piper/processors/copy.rb
120
120
  - lib/csv_piper/processors/create_active_model.rb
121
+ - lib/csv_piper/test_support/csv_mock_file.rb
121
122
  - lib/csv_piper/version.rb
122
123
  homepage: https://github.com/jazzarati/csv_piper
123
124
  licenses: