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 +4 -4
- data/README.md +4 -0
- data/lib/csv_piper/test_support/csv_mock_file.rb +38 -0
- data/lib/csv_piper/version.rb +1 -1
- data/lib/csv_piper.rb +5 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78f4de44ae17599fe675a8309f1fe6a5509e7573
|
4
|
+
data.tar.gz: 457ea3be103e375d63f1381d9fd313edee9b5f62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/csv_piper/version.rb
CHANGED
data/lib/csv_piper.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
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
|
+
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-
|
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:
|