kor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c58658c4082c827571e029a7851e4827ab0b75a3
4
+ data.tar.gz: 56ecb7a4bbc4ae99c2f6a95f32e2cebfcdf7f75f
5
+ SHA512:
6
+ metadata.gz: 470b0b4d6420f96372afd6aece408e0c889a9081d075a4d1852c4f5cfbd356e30c9f29aaf2f032791743bf55ab27814b513649e8cf148e18a1e3b07e60397804
7
+ data.tar.gz: 97952a281731440dd46875791159eb6a890da919a088f319992f2b00928b01567a7abf8379709f6022784278afa1613247f132d3bd3b4e8a675383b753654c1d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.7
5
+ - 2.2.3
6
+ before_install: gem install bundler -v 1.10.6
7
+ notifications:
8
+ email: false
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kor.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 ksss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,205 @@
1
+ Kor
2
+ ===
3
+
4
+ [![Build Status](https://travis-ci.org/ksss/kor.svg)](https://travis-ci.org/ksss/kor)
5
+
6
+ **Kor** is a pluggable table data converter.
7
+
8
+ ```
9
+ +----------+ +-----+ +----------+
10
+ | csv | => | | => | csv |
11
+ +----------+ | | +----------+
12
+ +----------+ | | +----------+
13
+ | tsv | => | kor | => | tsv |
14
+ +----------+ | | +----------+
15
+ +----------+ | | +----------+
16
+ | markdown | => | | => | markdown |
17
+ +----------+ +-----+ +----------+
18
+ ```
19
+
20
+ ```
21
+ $ cat table.csv
22
+ from \ to,markdown,csv,tsv
23
+ markdown,ok,ok,ok
24
+ csv,ok,ok,ok
25
+ tsv,ok,ok,ok
26
+
27
+ $ kor csv markdown < table.csv
28
+ | from \ to | markdown | csv | tsv |
29
+ | --- | --- | --- | --- |
30
+ | markdown | ok | ok | ok |
31
+ | csv | ok | ok | ok |
32
+ | tsv | ok | ok | ok |
33
+ ```
34
+
35
+ # Cli
36
+
37
+ Kor have command line interface.
38
+
39
+ Input from stdin and output to stdout.
40
+
41
+ ## Option
42
+
43
+ ```
44
+ $ kor
45
+ kor [input-plugin] [input-option] [output-plugin] [output-option]
46
+ example:
47
+ $ kor csv markdown
48
+ ```
49
+
50
+ ### input-plugin
51
+
52
+ Input plugin name.
53
+ If you set `name` that `require "kor/input/name"` And call `Kor::Input::Name.new`
54
+ By default, you can use csv,tsv,markdown.
55
+
56
+ ### input-option
57
+
58
+ input-plugin have distinctive option.
59
+ Should be start `-` and join key and value with `=` like `--key=value`.
60
+
61
+ ### output-plugin
62
+
63
+ Output plugin name.
64
+ If you set `name` that `require "kor/output/name"` And call `Kor::Output::Name.new`
65
+ By default, you can use csv,tsv,markdown.
66
+
67
+ ### output-option
68
+
69
+ output-plugin have distinctive option.
70
+ Should be start `-` and join key and value with `=` like `--key=value`.
71
+
72
+ # Plugin
73
+
74
+ Kor have plugin system.
75
+
76
+ You can extend input and output support format.
77
+
78
+ Embed format is that input **csv**,**tsv**,**markdown** and output **csv**,**tsv**,**markdown**
79
+
80
+ Plugin just only write class of Ruby.
81
+
82
+ And input and output run sequential processing like this.
83
+
84
+ ```ruby
85
+ out_obj.head(in_obj.head)
86
+ while body = in_obj.gets
87
+ out_obj.puts(body)
88
+ end
89
+ out_obj.finish
90
+ ```
91
+
92
+ ## Input
93
+
94
+ Input plugin read data by I/O and make data of keys and values.
95
+
96
+ keys read by `head` method.
97
+
98
+ values read by `gets` method.
99
+
100
+ `gets` method should be designed to read only one line.
101
+
102
+ This is an example for **Coron separated values** table.
103
+
104
+ ```ruby
105
+ module Kor
106
+ module Input
107
+ class Coronsv < Base
108
+ # head method should be return Array of key name
109
+ def head
110
+ # io is input IO object (default $stdin)
111
+ io.gets.split(':').map(&:strip)
112
+ end
113
+
114
+ # gets method should be return Array of values or nil
115
+ # Stop read loop when return nil
116
+ def gets
117
+ if line = io.gets
118
+ line.chomp.split(':').map(&:strip)
119
+ else
120
+ nil
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ ```
127
+
128
+ ## Output
129
+
130
+ Output plugin write data to I/O from input keys and values.
131
+
132
+ keys write by `head` method.
133
+
134
+ values write by `puts` method.
135
+
136
+ `puts` method should be designed to write only one line.
137
+
138
+ This is and example for **Coron separated values** table.
139
+
140
+ ```ruby
141
+ module Kor
142
+ module Output
143
+ class Coronsv < Base
144
+ # You can set cli option.
145
+ # $ kor [input-plugin] coronsv --hello=world
146
+ # Hello, world
147
+ def parse(opt)
148
+ opt.on("--hello") do |arg|
149
+ io.puts "Hello, #{arg}"
150
+ end
151
+ end
152
+
153
+ # At first, run `head` method with `keys`
154
+ # keys is object of returned by input-plugin `head` method.
155
+ # `head` should be print output string to I/O.
156
+ def head(keys)
157
+ # `io` is output I/O object (default $stdout)
158
+ io.puts keys.join(':')
159
+ end
160
+
161
+ # `puts` method each call by input-plugin `gets`.
162
+ # values is object of returned by input-plugin `gets` method.
163
+ # `puts` should be print output string to I/O
164
+ def puts(values)
165
+ io.puts values.join(':')
166
+ end
167
+ end
168
+ end
169
+ end
170
+ ```
171
+
172
+ But in most cases separated values table can make from `sed` command like this
173
+
174
+ ```shell
175
+ $ kor markdown csv < table.md | sed 's/,/:/g'
176
+ from \ to:markdown:csv:tsv
177
+ markdown:ok:ok:ok
178
+ csv:ok:ok:ok
179
+ tsv:ok:ok:ok
180
+ ```
181
+
182
+ ## Installation
183
+
184
+ Add this line to your application's Gemfile:
185
+
186
+ ```ruby
187
+ gem 'kor'
188
+ ```
189
+
190
+ And then execute:
191
+
192
+ $ bundle
193
+
194
+ Or install it yourself as:
195
+
196
+ $ gem install kor
197
+
198
+ ## Contributing
199
+
200
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ksss/kor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
201
+
202
+
203
+ ## License
204
+
205
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :test do
4
+ sh "rgot -v #{Dir.glob("lib/**/*_test.rb").join(' ')}"
5
+ end
6
+
7
+ task :default => [:test]
data/bin/kor ADDED
@@ -0,0 +1,4 @@
1
+ #! /usr/bin/env ruby
2
+ require 'kor'
3
+
4
+ Kor::Cli.new.run
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kor"
8
+ spec.version = Kor::VERSION
9
+ spec.authors = ["ksss"]
10
+ spec.email = ["co000ri@gmail.com"]
11
+
12
+ spec.summary = %q{Plaggable table data converter.}
13
+ spec.description = %q{Plaggable table data converter.}
14
+ spec.homepage = "https://github.com/ksss/kor"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rgot"
25
+ end
@@ -0,0 +1,2 @@
1
+ require "kor/cli"
2
+ require "kor/version"
@@ -0,0 +1,58 @@
1
+ require 'optparse'
2
+ require 'thread'
3
+ require "kor/input/base"
4
+ require "kor/output/base"
5
+
6
+ module Kor
7
+ class Cli
8
+ def initialize(argv = ARGV, input_io = $stdin, output_io = $stdout)
9
+ @argv = argv
10
+ @input_io = input_io
11
+ @output_io = output_io
12
+
13
+ @input_plugin = argv.shift
14
+ @input_args = []
15
+ while argv.first && argv.first[0] == "-"
16
+ @input_args << argv.shift
17
+ end
18
+
19
+ @output_plugin = argv.shift
20
+ @output_args = []
21
+ while argv.first && argv.first[0] == "-"
22
+ @output_args << argv.shift
23
+ end
24
+ end
25
+
26
+ def run
27
+ unless @input_plugin && @output_plugin
28
+ @output_io.puts <<-USAGE
29
+ kor [input-plugin] [input-option] [output-plugin] [output-option]
30
+ example:
31
+ $ kor csv markdown
32
+ USAGE
33
+ exit 0
34
+ end
35
+
36
+ require "kor/input/#{@input_plugin}"
37
+ require "kor/output/#{@output_plugin}"
38
+
39
+ in_class = Kor::Input.const_get(@input_plugin.capitalize)
40
+ out_class = Kor::Output.const_get(@output_plugin.capitalize)
41
+ in_obj = in_class.new(@input_io)
42
+ out_obj = out_class.new(@output_io)
43
+
44
+ in_opt = OptionParser.new
45
+ out_opt = OptionParser.new
46
+ in_obj.parse(in_opt)
47
+ out_obj.parse(out_opt)
48
+ in_opt.parse(@input_args)
49
+ out_opt.parse(@output_args)
50
+
51
+ out_obj.head(in_obj.head)
52
+ while body = in_obj.gets
53
+ out_obj.puts(body)
54
+ end
55
+ out_obj.finish
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ require 'kor'
2
+
3
+ module KorCliTest
4
+ def test_new(t)
5
+ cli = Kor::Cli.new
6
+ unless cli.kind_of?(Kor::Cli)
7
+ t.error("expect instance of Kor::Cli got #{cli}")
8
+ end
9
+ end
10
+
11
+ def test_run(t)
12
+ input_io = StringIO.new
13
+ output_io = StringIO.new
14
+ cli = Kor::Cli.new(["base"], input_io, output_io)
15
+ ret, err = go { cli.run }
16
+ unless SystemExit === err
17
+ t.error("expect raise SystemExit got #{err.class}:#{err.to_s}")
18
+ end
19
+
20
+ input = StringIO.new("input")
21
+ output = StringIO.new("output")
22
+ cli = Kor::Cli.new(["base", "base"], input, output)
23
+ cli.run
24
+ if input.string != "input"
25
+ t.error("expect base input plugin string \"input\" got #{input.string}")
26
+ end
27
+ if output.string != "output"
28
+ t.error("expect base output plugin string \"output\" got #{output.string}")
29
+ end
30
+ end
31
+
32
+ def test_e2e(t)
33
+ actual = `#{<<-COMMAND}`
34
+ cat << CSV | kor csv markdown
35
+ foo,bar,baz
36
+ 100,200,300
37
+ 400,500,600
38
+ CSV
39
+ COMMAND
40
+ expect = <<-MARKDOWN
41
+ | foo | bar | baz |
42
+ | --- | --- | --- |
43
+ | 100 | 200 | 300 |
44
+ | 400 | 500 | 600 |
45
+ MARKDOWN
46
+ if actual != expect
47
+ t.error("actual output not match to expect output.")
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def go
54
+ [yield, nil]
55
+ rescue Exception => err
56
+ [nil, err]
57
+ end
58
+ end
@@ -0,0 +1,22 @@
1
+ module Kor
2
+ module Input
3
+ class Base
4
+ def initialize(io)
5
+ @io = io
6
+ end
7
+
8
+ def io
9
+ @io
10
+ end
11
+
12
+ def parse(opt)
13
+ end
14
+
15
+ def head
16
+ end
17
+
18
+ def gets
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Kor
2
+ module Input
3
+ class Csv < Base
4
+ DELIM = ","
5
+
6
+ def head
7
+ io.gets.chomp.split(self.class::DELIM).map(&:strip)
8
+ end
9
+
10
+ def gets
11
+ if line = io.gets
12
+ line.chomp.split(self.class::DELIM).map(&:strip)
13
+ else
14
+ nil
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ require 'kor'
2
+ require 'kor/input/csv'
3
+
4
+ module KorInputCsvTest
5
+ def test_main(m)
6
+ @io = StringIO.new(<<-CSV)
7
+ foo,bar,baz
8
+ 1,2,3
9
+ a,b,c
10
+ CSV
11
+ exit m.run
12
+ end
13
+
14
+ def test_head(t)
15
+ @io.rewind
16
+ csv = Kor::Input::Csv.new(@io)
17
+ head = csv.head
18
+ if head != %w(foo bar baz)
19
+ t.error("expect #{%w(foo bar baz)} got #{head}")
20
+ end
21
+ end
22
+
23
+ def test_gets(t)
24
+ @io.rewind
25
+ csv = Kor::Input::Csv.new(@io)
26
+ csv.head
27
+
28
+ value = csv.gets
29
+ if value != %w(1 2 3)
30
+ t.error("expect #{%w(1 2 3)} got #{value}")
31
+ end
32
+ value = csv.gets
33
+ if value != %w(a b c)
34
+ t.error("expect #{%w(a b c)} got #{value}")
35
+ end
36
+ 2.times do
37
+ value = csv.gets
38
+ if value != nil
39
+ t.error("expect nil got #{value}")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ module Kor
2
+ module Input
3
+ class Markdown < Base
4
+ def head
5
+ line = io.gets.strip
6
+ first_index = line[0] == '|' ? 1 : 0
7
+ h = line.split('|')[first_index..-1].map(&:strip)
8
+ # skip separate line
9
+ io.gets
10
+ h
11
+ end
12
+
13
+ def gets
14
+ if line = io.gets
15
+ first_index = line[0] == '|' ? 1 : 0
16
+ line.strip.split('|')[first_index..-1].map(&:strip)
17
+ else
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,76 @@
1
+ require 'kor'
2
+ require 'kor/input/markdown'
3
+
4
+ module KorInputMarkdownTest
5
+ def test_main(m)
6
+ @io = StringIO.new(<<-MARKDOWN)
7
+ | foo | bar | baz |
8
+ | --- | --- | --- |
9
+ | 1 | 2 | 3 |
10
+ | a | b | c |
11
+ MARKDOWN
12
+ @io2 = StringIO.new(<<-MARKDOWN)
13
+ foo | bar | baz |
14
+ --- | --- | ---
15
+ | 1 | 2 | 3
16
+ a | b | c |
17
+ MARKDOWN
18
+ exit m.run
19
+ end
20
+
21
+ def test_head(t)
22
+ @io.rewind
23
+ md = Kor::Input::Markdown.new(@io)
24
+ head = md.head
25
+ if head != %w(foo bar baz)
26
+ t.error("expect #{%w(foo bar baz)} got #{head}")
27
+ end
28
+
29
+ @io2.rewind
30
+ md = Kor::Input::Markdown.new(@io2)
31
+ head = md.head
32
+ if head != %w(foo bar baz)
33
+ t.error("expect #{%w(foo bar baz)} got #{head}")
34
+ end
35
+ end
36
+
37
+ def test_gets(t)
38
+ @io.rewind
39
+ md = Kor::Input::Markdown.new(@io)
40
+ md.head
41
+
42
+ value = md.gets
43
+ if value != %w(1 2 3)
44
+ t.error("expect #{%w(1 2 3)} got #{value}")
45
+ end
46
+ value = md.gets
47
+ if value != %w(a b c)
48
+ t.error("expect #{%w(a b c)} got #{value}")
49
+ end
50
+ 2.times do
51
+ value = md.gets
52
+ if value != nil
53
+ t.error("expect nil got #{value}")
54
+ end
55
+ end
56
+
57
+ @io2.rewind
58
+ md = Kor::Input::Markdown.new(@io2)
59
+ md.head
60
+
61
+ value = md.gets
62
+ if value != %w(1 2 3)
63
+ t.error("expect #{%w(1 2 3)} got #{value}")
64
+ end
65
+ value = md.gets
66
+ if value != %w(a b c)
67
+ t.error("expect #{%w(a b c)} got #{value}")
68
+ end
69
+ 2.times do
70
+ value = md.gets
71
+ if value != nil
72
+ t.error("expect nil got #{value}")
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,7 @@
1
+ module Kor
2
+ module Input
3
+ class Tsv < Csv
4
+ DELIM = "\t"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,43 @@
1
+ require 'kor'
2
+ require 'kor/input/tsv'
3
+
4
+ module KorInputTsvTest
5
+ def test_main(m)
6
+ @io = StringIO.new(<<-TSV)
7
+ foo\tbar\tbaz
8
+ 1\t2\t3
9
+ a\tb\tc
10
+ TSV
11
+ exit m.run
12
+ end
13
+
14
+ def test_head(t)
15
+ @io.rewind
16
+ tsv = Kor::Input::Tsv.new(@io)
17
+ head = tsv.head
18
+ if head != %w(foo bar baz)
19
+ t.error("expect #{%w(foo bar baz)} got #{head}")
20
+ end
21
+ end
22
+
23
+ def test_gets(t)
24
+ @io.rewind
25
+ tsv = Kor::Input::Tsv.new(@io)
26
+ tsv.head
27
+
28
+ value = tsv.gets
29
+ if value != %w(1 2 3)
30
+ t.error("expect #{%w(1 2 3)} got #{value}")
31
+ end
32
+ value = tsv.gets
33
+ if value != %w(a b c)
34
+ t.error("expect #{%w(a b c)} got #{value}")
35
+ end
36
+ 2.times do
37
+ value = tsv.gets
38
+ if value != nil
39
+ t.error("expect nil got #{value}")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ module Kor
2
+ module Output
3
+ class Base
4
+ def initialize(io)
5
+ @io = io
6
+ end
7
+
8
+ def io
9
+ @io
10
+ end
11
+
12
+ def parse(opt)
13
+ end
14
+
15
+ def head(keys)
16
+ end
17
+
18
+ def puts(values)
19
+ end
20
+
21
+ def finish
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module Kor
2
+ module Output
3
+ class Csv < Base
4
+ DELIM = ","
5
+
6
+ def head(keys)
7
+ io.puts keys.join(self.class::DELIM)
8
+ end
9
+
10
+ def puts(values)
11
+ io.puts values.join(self.class::DELIM)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ require 'kor'
2
+ require 'kor/output/csv'
3
+
4
+ module KorOutputCsvTest
5
+ def test_head(t)
6
+ io = StringIO.new
7
+ csv = Kor::Output::Csv.new(io)
8
+ csv.head(%w(foo bar baz))
9
+ if io.string != "foo,bar,baz\n"
10
+ t.error("expect output 'foo,bar,baz\\n' got #{io.string.inspect}")
11
+ end
12
+ end
13
+
14
+ def test_puts(t)
15
+ io = StringIO.new
16
+ csv = Kor::Output::Csv.new(io)
17
+ csv.puts(%w(aaa bbb ccc))
18
+ if io.string != "aaa,bbb,ccc\n"
19
+ t.error("expect output 'aaa,bbb,ccc\\n' got #{io.string.inspect}")
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ module Kor
2
+ module Output
3
+ class Markdown < Base
4
+ def parse(opt)
5
+ @space = " "
6
+ opt.on("--strip", "strip space") do |arg|
7
+ @space = ""
8
+ end
9
+ end
10
+
11
+ def head(keys)
12
+ s = @space || " "
13
+ io.puts "|#{s}#{keys.join("#{s}|#{s}")}#{s}|"
14
+ io.puts "|#{s}#{(["---"] * keys.length).join("#{s}|#{s}")}#{s}|"
15
+ end
16
+
17
+ def puts(values)
18
+ s = @space || " "
19
+ io.puts "|#{s}#{values.join("#{s}|#{s}")}#{s}|"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'kor'
2
+ require 'kor/output/markdown'
3
+
4
+ module KorOutputCsvTest
5
+ def test_head(t)
6
+ io = StringIO.new
7
+ csv = Kor::Output::Markdown.new(io)
8
+ csv.head(%w(foo bar baz))
9
+ if io.string != "| foo | bar | baz |\n| --- | --- | --- |\n"
10
+ t.error("expect output '| foo | bar | baz |\\n| --- | --- | --- |\\n' got #{io.string.inspect}")
11
+ end
12
+ end
13
+
14
+ def test_puts(t)
15
+ io = StringIO.new
16
+ csv = Kor::Output::Markdown.new(io)
17
+ csv.puts(%w(aaa bbb ccc))
18
+ if io.string != "| aaa | bbb | ccc |\n"
19
+ t.error("expect output '| aaa | bbb | ccc |\\n' got #{io.string.inspect}")
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ module Kor
2
+ module Output
3
+ class Tsv < Csv
4
+ DELIM = "\t"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ require 'kor'
2
+ require 'kor/output/tsv'
3
+
4
+ module KorOutputTsvTest
5
+ def test_head(t)
6
+ io = StringIO.new
7
+ tsv = Kor::Output::Tsv.new(io)
8
+ tsv.head(%w(foo bar baz))
9
+ if io.string != "foo\tbar\tbaz\n"
10
+ t.error("expect output 'foo\\tbar\\tbaz\\n' got #{io.string.inspect}")
11
+ end
12
+ end
13
+
14
+ def test_puts(t)
15
+ io = StringIO.new
16
+ tsv = Kor::Output::Tsv.new(io)
17
+ tsv.puts(%w(aaa bbb ccc))
18
+ if io.string != "aaa\tbbb\tccc\n"
19
+ t.error("expect output 'aaa\\tbbb\\tccc\\n' got #{io.string.inspect}")
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Kor
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ksss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rgot
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Plaggable table data converter.
56
+ email:
57
+ - co000ri@gmail.com
58
+ executables:
59
+ - kor
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/kor
71
+ - kor.gemspec
72
+ - lib/kor.rb
73
+ - lib/kor/cli.rb
74
+ - lib/kor/cli_test.rb
75
+ - lib/kor/input/base.rb
76
+ - lib/kor/input/csv.rb
77
+ - lib/kor/input/csv_test.rb
78
+ - lib/kor/input/markdown.rb
79
+ - lib/kor/input/markdown_test.rb
80
+ - lib/kor/input/tsv.rb
81
+ - lib/kor/input/tsv_test.rb
82
+ - lib/kor/output/base.rb
83
+ - lib/kor/output/csv.rb
84
+ - lib/kor/output/csv_test.rb
85
+ - lib/kor/output/markdown.rb
86
+ - lib/kor/output/markdown_test.rb
87
+ - lib/kor/output/tsv.rb
88
+ - lib/kor/output/tsv_test.rb
89
+ - lib/kor/version.rb
90
+ homepage: https://github.com/ksss/kor
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Plaggable table data converter.
114
+ test_files: []