kor 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kor.rb +7 -0
- data/lib/kor/input/csv.rb +0 -3
- data/lib/kor/input/csv_test.rb +1 -1
- data/lib/kor/input/markdown.rb +13 -11
- data/lib/kor/input/markdown_test.rb +16 -10
- data/lib/kor/output/markdown.rb +2 -1
- data/lib/kor/output/markdown_test.rb +2 -7
- data/lib/kor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 213bc92a1e8a6d511e108a2787c0f367e4ee2479
|
4
|
+
data.tar.gz: e6a3ed24eaec50fc2ed402ba3e3281e417cb00a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 999684aa144d469eac4c7e03a642a38d494395d87b5344c941dd53ef68699cd824f09fb1b90f4140f532c4dde0d0fb3058e558776eda58ab0b5bc2ace2ad6097
|
7
|
+
data.tar.gz: 27f9c02f6423fe31e33f241a66e8d57db64e98ec51740e219f2bf8dee7c578156f39027cbf7500c32c212fee8b6b3532b56312404ecca314cf672be1541e5cba
|
data/lib/kor.rb
CHANGED
data/lib/kor/input/csv.rb
CHANGED
data/lib/kor/input/csv_test.rb
CHANGED
data/lib/kor/input/markdown.rb
CHANGED
@@ -8,20 +8,22 @@ module Kor
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def head
|
11
|
-
line = io.gets
|
11
|
+
line = io.gets
|
12
|
+
raise ReadError, "cannot get markdown header" unless line
|
13
|
+
line.strip!
|
12
14
|
first_index = line[0] == '|' ? 1 : 0
|
13
15
|
keys = line.split('|')[first_index..-1].map(&:strip)
|
14
|
-
|
15
|
-
io.gets
|
16
|
+
|
17
|
+
separate_line = io.gets
|
18
|
+
raise ReadError, "cannot get markdown header" unless separate_line
|
19
|
+
|
16
20
|
if @filter_key
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
keys = @filter_key.map{ |index| keys[index] }
|
21
|
+
filter_keys = @filter_key.split(",")
|
22
|
+
filter_keys = keys.select { |key|
|
23
|
+
filter_keys.include?(key)
|
24
|
+
}
|
25
|
+
keys = filter_keys
|
26
|
+
@filter_key = filter_keys.map { |key| keys.index(key) }
|
25
27
|
end
|
26
28
|
keys
|
27
29
|
end
|
@@ -19,6 +19,18 @@ MARKDOWN
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_head(t)
|
22
|
+
md = Kor::Input::Markdown.new(StringIO.new)
|
23
|
+
_, err = go { md.head }
|
24
|
+
unless Kor::ReadError === err
|
25
|
+
t.error("expect raise an error Kor::ReadError got #{err.class}:#{err}")
|
26
|
+
end
|
27
|
+
|
28
|
+
md = Kor::Input::Markdown.new(StringIO.new("|foo|\n"))
|
29
|
+
_, err = go { md.head }
|
30
|
+
unless Kor::ReadError === err
|
31
|
+
t.error("expect raise an error Kor::ReadError got #{err.class}:#{err}")
|
32
|
+
end
|
33
|
+
|
22
34
|
@io.rewind
|
23
35
|
md = Kor::Input::Markdown.new(@io)
|
24
36
|
head = md.head
|
@@ -40,23 +52,17 @@ MARKDOWN
|
|
40
52
|
opt = OptionParser.new
|
41
53
|
md.parse(opt)
|
42
54
|
|
43
|
-
opt.parse ["--key=bar,nothing"]
|
44
|
-
_, err = go { md.head }
|
45
|
-
unless Kor::NotKeyError === err
|
46
|
-
t.error("expect raise an error Kor::NotKeyError got #{err.class}:#{err}")
|
47
|
-
end
|
48
|
-
|
49
55
|
@io.rewind
|
50
|
-
opt.parse ["--key=bar,foo"]
|
56
|
+
opt.parse ["--key=bar,foo,non"]
|
51
57
|
actual = md.head
|
52
|
-
expect = %w(bar
|
58
|
+
expect = %w(foo bar)
|
53
59
|
if actual != expect
|
54
60
|
t.error("expect #{expect} got #{actual}")
|
55
61
|
end
|
56
62
|
|
57
63
|
expects = [
|
58
|
-
%w(2
|
59
|
-
%w(b
|
64
|
+
%w(1 2),
|
65
|
+
%w(a b),
|
60
66
|
nil, nil, nil, nil, nil
|
61
67
|
].each do |expect|
|
62
68
|
actual = md.gets
|
data/lib/kor/output/markdown.rb
CHANGED
@@ -14,8 +14,9 @@ module Kor
|
|
14
14
|
def head(keys)
|
15
15
|
if @select_key
|
16
16
|
select_keys = @select_key.split(",")
|
17
|
+
select_keys.select!{ |key| keys.include?(key) }
|
17
18
|
@select_key = select_keys.map do |key|
|
18
|
-
keys.index(key)
|
19
|
+
keys.index(key)
|
19
20
|
end
|
20
21
|
keys = select_keys
|
21
22
|
end
|
@@ -16,17 +16,12 @@ module KorOutputMarkdownTest
|
|
16
16
|
md = Kor::Output::Markdown.new(io)
|
17
17
|
opt = OptionParser.new
|
18
18
|
md.parse(opt)
|
19
|
-
opt.parse ["--key=foo,nothing"]
|
20
|
-
_, err = go { md.head(["foo", "bar", "baz"]) }
|
21
|
-
unless Kor::NotKeyError === err
|
22
|
-
t.error("expect raise Kor::Output::Markdown::NotKeyError got #{err.class}:#{err}")
|
23
|
-
end
|
24
19
|
|
25
|
-
opt.parse ["--key=bar,foo"]
|
20
|
+
opt.parse ["--key=bar,foo,non"]
|
26
21
|
_, err = go { md.head(["foo", "bar", "baz"]) }
|
27
22
|
t.error("expect not raise got #{err.class}:#{err}") if err
|
28
23
|
if io.string != "| bar | foo |\n| --- | --- |\n"
|
29
|
-
t.error("expect bar,foo header got #{
|
24
|
+
t.error("expect bar,foo header got #{io.string}")
|
30
25
|
end
|
31
26
|
end
|
32
27
|
|
data/lib/kor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|