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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f945e02d461ae630c93756a59d37a1adbc2c3783
4
- data.tar.gz: 6eb078d973ea6ea8e185461501518639951949f5
3
+ metadata.gz: 213bc92a1e8a6d511e108a2787c0f367e4ee2479
4
+ data.tar.gz: e6a3ed24eaec50fc2ed402ba3e3281e417cb00a9
5
5
  SHA512:
6
- metadata.gz: bccf7c8361ee7937e60d8740b98b906e2ae10444298fb386a231f12a3280614ba99b166923ce92c21bdcfc5bc6d1c9d81420a1c75cd2fc30048a3f152fa7cd1c
7
- data.tar.gz: fffda929139840318ea989547d663675124bd5022c42cb14cea70be5a8f42f5c76a599702167f1b2e7c51b717b28f8faccc978213c05e98bbebb5f915d66c425
6
+ metadata.gz: 999684aa144d469eac4c7e03a642a38d494395d87b5344c941dd53ef68699cd824f09fb1b90f4140f532c4dde0d0fb3058e558776eda58ab0b5bc2ace2ad6097
7
+ data.tar.gz: 27f9c02f6423fe31e33f241a66e8d57db64e98ec51740e219f2bf8dee7c578156f39027cbf7500c32c212fee8b6b3532b56312404ecca314cf672be1541e5cba
data/lib/kor.rb CHANGED
@@ -1,5 +1,12 @@
1
1
  module Kor
2
2
  class NotKeyError < StandardError
3
+ def initialize(*)
4
+ super
5
+ warn "[DEPRECATED] #{self.class} was deprecated"
6
+ end
7
+ end
8
+
9
+ class ReadError < StandardError
3
10
  end
4
11
 
5
12
  require "kor/cli"
@@ -3,9 +3,6 @@ require 'csv'
3
3
  module Kor
4
4
  module Input
5
5
  class Csv < Base
6
- class ReadError < StandardError
7
- end
8
-
9
6
  DELIM = ","
10
7
 
11
8
  def head
@@ -22,7 +22,7 @@ CSV
22
22
  io2 = StringIO.new("")
23
23
  csv = Kor::Input::Csv.new(io2)
24
24
  head, err = go { csv.head }
25
- unless Kor::Input::Csv::ReadError === err
25
+ unless Kor::ReadError === err
26
26
  t.error("expect Kor::Input::Csv::ReadError got #{err.class}:#{err}")
27
27
  end
28
28
  end
@@ -8,20 +8,22 @@ module Kor
8
8
  end
9
9
 
10
10
  def head
11
- line = io.gets.strip
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
- # skip separate line
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
- @filter_key = @filter_key.split(",").map do |key|
18
- if index = keys.index(key)
19
- index
20
- else
21
- raise NotKeyError, "`#{key}' is a not key of this table"
22
- end
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 foo)
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 1),
59
- %w(b a),
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
@@ -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) or raise NotKeyError, "`#{key}' is not a key of this table"
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 #{head}")
24
+ t.error("expect bar,foo header got #{io.string}")
30
25
  end
31
26
  end
32
27
 
@@ -1,3 +1,3 @@
1
1
  module Kor
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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.5
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-10 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler