embulk-formatter-markdown_table 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +3 -0
- data/embulk-formatter-markdown_table.gemspec +19 -0
- data/lib/embulk/formatter/markdown_table.rb +66 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af6efaa56e945189ba35b1a2a08c6a16c739b54d
|
4
|
+
data.tar.gz: de3bf9be0f4068fe2a8f24be0fd9173b15280b75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52d4ac074506290de55c5683b78ea5a26fe92a17ebcfdbc4ae8ddf35fd464f87842e9f8c26e28fa728c9bf76418de3a7867b0440e676c31806d5d64a6d2791dd
|
7
|
+
data.tar.gz: 722fbc856db7c20a384990c1e81c1832928c4b1915090d6acae8603b630387dd168e50a8042ecc65109f3d7fee80af191a2b74c0d944c34cd249b092bdb8b6a9
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-9.0.4.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Markdown Table formatter plugin for Embulk
|
2
|
+
|
3
|
+
This plugin is Markdown Table formatter for Embulk.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
* **Plugin type**: formatter
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
- **encoding**: output encoding. (string, default: `"UTF-8"`)
|
12
|
+
- **newline**: newline character. (string, default: `"LF"`)
|
13
|
+
- CRLF: use \r(0x0d) and \n(0x0a) as newline character
|
14
|
+
- LF: use \n(0x0a) as newline character
|
15
|
+
- CR: use \r(0x0d) as newline character
|
16
|
+
- NUL: use \0(0x00) instead of newline
|
17
|
+
|
18
|
+
## Example
|
19
|
+
|
20
|
+
### input
|
21
|
+
|
22
|
+
```
|
23
|
+
id,account,time,purchase,comment
|
24
|
+
1,32864,2015-01-27 19:23:49,20150127,embulk
|
25
|
+
2,14824,2015-01-27 19:01:23,20150127,embulk jruby
|
26
|
+
3,27559,2015-01-28 02:20:02,20150128,"Embulk ""csv"" parser plugin"
|
27
|
+
4,11270,2015-01-29 11:54:36,20150129,NULL
|
28
|
+
```
|
29
|
+
|
30
|
+
### config
|
31
|
+
|
32
|
+
```yaml
|
33
|
+
out:
|
34
|
+
type: markdown_table
|
35
|
+
formatter:
|
36
|
+
type: markdown_table
|
37
|
+
encoding: UTF-8 # optional
|
38
|
+
newline: LF # optional
|
39
|
+
```
|
40
|
+
|
41
|
+
### output
|
42
|
+
|
43
|
+
```
|
44
|
+
|id|account|time|purchase|comment|
|
45
|
+
|---|---|---|---|---|
|
46
|
+
|1|32864|2015-01-27 19:23:49 UTC|2015-01-27 00:00:00 UTC|embulk|
|
47
|
+
|2|14824|2015-01-27 19:01:23 UTC|2015-01-27 00:00:00 UTC|embulk jruby|
|
48
|
+
|3|27559|2015-01-28 02:20:02 UTC|2015-01-28 00:00:00 UTC|Embulk "csv" parser plugin|
|
49
|
+
|4|11270|2015-01-29 11:54:36 UTC|2015-01-29 00:00:00 UTC|NULL|
|
50
|
+
```
|
51
|
+
|
52
|
+
|
53
|
+
## Build
|
54
|
+
|
55
|
+
```
|
56
|
+
$ rake
|
57
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-formatter-markdown_table"
|
4
|
+
spec.version = "0.1.0"
|
5
|
+
spec.authors = ["yuemori"]
|
6
|
+
spec.summary = "Markdown Table formatter plugin for Embulk"
|
7
|
+
spec.description = "Formats Markdown Table files for other file output plugins."
|
8
|
+
spec.email = ["yuemori@aiming-inc.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/yuemori/embulk-formatter-markdown_table"
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_development_dependency 'embulk', ['>= 0.8.3']
|
17
|
+
spec.add_development_dependency 'bundler', ['>= 1.10.6']
|
18
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
19
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Embulk
|
2
|
+
module Formatter
|
3
|
+
class MarkdownTable < FormatterPlugin
|
4
|
+
Plugin.register_formatter("markdown_table", self)
|
5
|
+
NEWLINES = {
|
6
|
+
'CRLF' => "\r\n",
|
7
|
+
'LF' => "\n",
|
8
|
+
'CR' => "\r",
|
9
|
+
'NUL' => "\0"
|
10
|
+
}
|
11
|
+
|
12
|
+
def self.join_texts((*inits,last), opt = {})
|
13
|
+
delim = opt[:delimiter] || ', '
|
14
|
+
last_delim = opt[:last_delimiter] || ' or '
|
15
|
+
[inits.join(delim),last].join(last_delim)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.transaction(config, schema, &control)
|
19
|
+
task = {
|
20
|
+
'encoding' => config.param('encoding', :string, default: 'UTF-8'),
|
21
|
+
'newline' => config.param('newline', :string, default: 'LF')
|
22
|
+
}
|
23
|
+
|
24
|
+
newline = task['newline'].upcase
|
25
|
+
raise "newline must be one of #{join_texts(NEWLINES.keys)}" unless NEWLINES.has_key?(newline)
|
26
|
+
|
27
|
+
yield(task)
|
28
|
+
end
|
29
|
+
|
30
|
+
def init
|
31
|
+
@header_print = true
|
32
|
+
@encoding = task['encoding'].upcase
|
33
|
+
@newline = NEWLINES[task['newline'].upcase]
|
34
|
+
@current_file = nil
|
35
|
+
@current_file_size = 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def close
|
39
|
+
end
|
40
|
+
|
41
|
+
def add(page)
|
42
|
+
page.each do |record|
|
43
|
+
if @current_file == nil || @current_file_size > 32*1024
|
44
|
+
@current_file = file_output.next_file
|
45
|
+
@current_file_size = 0
|
46
|
+
@header_print = true
|
47
|
+
end
|
48
|
+
|
49
|
+
if @header_print
|
50
|
+
header = "|" + page.schema.map(&:name).join('|') + "|#{@newline}"
|
51
|
+
header += "|" + (["---"] * page.schema.size).join('|') + "|#{@newline}"
|
52
|
+
@current_file.write header.encode(@encoding)
|
53
|
+
@header_print = false
|
54
|
+
end
|
55
|
+
|
56
|
+
row = "|" + record.join('|') + "|#{@newline}"
|
57
|
+
@current_file.write row.encode(@encoding)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def finish
|
62
|
+
file_output.finish
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-formatter-markdown_table
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yuemori
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: embulk
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.3
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.8.3
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.10.6
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 1.10.6
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '10.0'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
description: Formats Markdown Table files for other file output plugins.
|
56
|
+
email:
|
57
|
+
- yuemori@aiming-inc.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- embulk-formatter-markdown_table.gemspec
|
69
|
+
- lib/embulk/formatter/markdown_table.rb
|
70
|
+
homepage: https://github.com/yuemori/embulk-formatter-markdown_table
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.4.8
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Markdown Table formatter plugin for Embulk
|
94
|
+
test_files: []
|