kor 0.0.1 → 0.0.2
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/lib/kor/input/csv.rb +11 -2
- data/lib/kor/input/csv_test.rb +21 -6
- data/lib/kor/output/csv.rb +2 -2
- data/lib/kor/output/csv_test.rb +8 -6
- data/lib/kor/output/markdown_test.rb +1 -1
- data/lib/kor/output/tsv_test.rb +8 -6
- data/lib/kor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51199de55957675466e9c245d132e9dce9aa7cbf
|
4
|
+
data.tar.gz: 751abcb7c42a7c87f548ab81b99d692419431690
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0919829c9f6a662b4177452978e880ec626db3a1c2bf1453e1e975ca896a8ea508306acf48226d451f5b8a51e495a920e364183e5650fdb4c6d9c918b7060c57
|
7
|
+
data.tar.gz: f1cf7f676811c2d3e4e7b941d3fe9b1ab78c6ef3327d2212ea793b4077d5350e932582deacc5e52ceecd655ae7a6a4be4a11021ffc8c89ad5ec29df3cd081c50
|
data/lib/kor/input/csv.rb
CHANGED
@@ -1,15 +1,24 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
1
3
|
module Kor
|
2
4
|
module Input
|
3
5
|
class Csv < Base
|
6
|
+
class ReadError < StandardError
|
7
|
+
end
|
8
|
+
|
4
9
|
DELIM = ","
|
5
10
|
|
6
11
|
def head
|
7
|
-
io.gets
|
12
|
+
if line = io.gets
|
13
|
+
::CSV.new(line.strip, col_sep: self.class::DELIM).gets
|
14
|
+
else
|
15
|
+
raise ReadError, "cannot get csv header"
|
16
|
+
end
|
8
17
|
end
|
9
18
|
|
10
19
|
def gets
|
11
20
|
if line = io.gets
|
12
|
-
line.
|
21
|
+
::CSV.new(line.strip, col_sep: self.class::DELIM).gets
|
13
22
|
else
|
14
23
|
nil
|
15
24
|
end
|
data/lib/kor/input/csv_test.rb
CHANGED
@@ -4,8 +4,8 @@ require 'kor/input/csv'
|
|
4
4
|
module KorInputCsvTest
|
5
5
|
def test_main(m)
|
6
6
|
@io = StringIO.new(<<-CSV)
|
7
|
-
foo,bar,baz
|
8
|
-
1,2,3
|
7
|
+
foo,bar,"baz,qux"
|
8
|
+
1,"2,3,4",5
|
9
9
|
a,b,c
|
10
10
|
CSV
|
11
11
|
exit m.run
|
@@ -15,8 +15,15 @@ CSV
|
|
15
15
|
@io.rewind
|
16
16
|
csv = Kor::Input::Csv.new(@io)
|
17
17
|
head = csv.head
|
18
|
-
if head != %w(foo bar baz)
|
19
|
-
t.error("expect #{%w(foo bar baz)} got #{head}")
|
18
|
+
if head != %w(foo bar baz,qux)
|
19
|
+
t.error("expect #{%w(foo bar baz,qux)} got #{head}")
|
20
|
+
end
|
21
|
+
|
22
|
+
io2 = StringIO.new("")
|
23
|
+
csv = Kor::Input::Csv.new(io2)
|
24
|
+
head, err = go { csv.head }
|
25
|
+
unless Kor::Input::Csv::ReadError === err
|
26
|
+
t.error("expect Kor::Input::Csv::ReadError got #{err.class}:#{err}")
|
20
27
|
end
|
21
28
|
end
|
22
29
|
|
@@ -26,8 +33,8 @@ CSV
|
|
26
33
|
csv.head
|
27
34
|
|
28
35
|
value = csv.gets
|
29
|
-
if value != %w(1 2
|
30
|
-
t.error("expect #{%w(1 2
|
36
|
+
if value != %w(1 2,3,4 5)
|
37
|
+
t.error("expect #{%w(1 2,3,4 5)} got #{value}")
|
31
38
|
end
|
32
39
|
value = csv.gets
|
33
40
|
if value != %w(a b c)
|
@@ -40,4 +47,12 @@ CSV
|
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def go
|
54
|
+
[yield, nil]
|
55
|
+
rescue Exception => err
|
56
|
+
[nil, err]
|
57
|
+
end
|
43
58
|
end
|
data/lib/kor/output/csv.rb
CHANGED
@@ -4,11 +4,11 @@ module Kor
|
|
4
4
|
DELIM = ","
|
5
5
|
|
6
6
|
def head(keys)
|
7
|
-
io.puts keys.join(self.class::DELIM)
|
7
|
+
io.puts keys.map{|k| "\"#{k}\""}.join(self.class::DELIM)
|
8
8
|
end
|
9
9
|
|
10
10
|
def puts(values)
|
11
|
-
io.puts values.join(self.class::DELIM)
|
11
|
+
io.puts values.map{|k| "\"#{k}\""}.join(self.class::DELIM)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/kor/output/csv_test.rb
CHANGED
@@ -5,18 +5,20 @@ module KorOutputCsvTest
|
|
5
5
|
def test_head(t)
|
6
6
|
io = StringIO.new
|
7
7
|
csv = Kor::Output::Csv.new(io)
|
8
|
-
csv.head(%w(foo bar baz))
|
9
|
-
|
10
|
-
|
8
|
+
csv.head(%w(foo bar baz,qux))
|
9
|
+
expect = %Q{"foo","bar","baz,qux"\n}
|
10
|
+
if io.string != expect
|
11
|
+
t.error("expect output #{expect} got #{io.string.inspect}")
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
15
|
def test_puts(t)
|
15
16
|
io = StringIO.new
|
16
17
|
csv = Kor::Output::Csv.new(io)
|
17
|
-
csv.puts(%w(aaa bbb
|
18
|
-
|
19
|
-
|
18
|
+
csv.puts(%w(aaa bbb,ccc ddd))
|
19
|
+
expect = %Q{"aaa","bbb,ccc","ddd"\n}
|
20
|
+
if io.string != expect
|
21
|
+
t.error("expect output #{expect} got #{io.string.inspect}")
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/kor/output/tsv_test.rb
CHANGED
@@ -5,18 +5,20 @@ module KorOutputTsvTest
|
|
5
5
|
def test_head(t)
|
6
6
|
io = StringIO.new
|
7
7
|
tsv = Kor::Output::Tsv.new(io)
|
8
|
-
tsv.head(
|
9
|
-
|
10
|
-
|
8
|
+
tsv.head(["foo", "bar", "baz\tqux"])
|
9
|
+
expect = %Q{"foo"\t"bar"\t"baz\tqux"\n}
|
10
|
+
if io.string != expect
|
11
|
+
t.error("expect output #{expect.inspect} got #{io.string.inspect}")
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
15
|
def test_puts(t)
|
15
16
|
io = StringIO.new
|
16
17
|
tsv = Kor::Output::Tsv.new(io)
|
17
|
-
tsv.puts(
|
18
|
-
|
19
|
-
|
18
|
+
tsv.puts(["aaa", "bbb\tccc", "ddd"])
|
19
|
+
expect = %Q{"aaa"\t"bbb\tccc"\t"ddd"\n}
|
20
|
+
if io.string != expect
|
21
|
+
t.error("expect output #{expect.inspect} got #{io.string.inspect}")
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/kor/version.rb
CHANGED