embulk-parser-script_ruby 0.1.0

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: 99efd9ecb9b0ffef55907992fa1c2729e4812685
4
+ data.tar.gz: ad3d00f7dd8ec2a84dcec5963357141a0e4c0aac
5
+ SHA512:
6
+ metadata.gz: 9eb5a26cbbc2a00ccdfa790376b913a3092222902c83c1484133883a029d2ab8707cb5401d869022f63ac87f60b265e886936bf70fc361eeb4fa4f7147beb260
7
+ data.tar.gz: 40fec4892ac6fd573be7604004d025855b229583a7ed6e9d6b7c83e6c35c4714e5463eb7f00d0e5e8639edab303866b2ee32a3020b8b4276092b014e6104ab48
@@ -0,0 +1,5 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ /.bundle/
5
+ /Gemfile.lock
@@ -0,0 +1 @@
1
+ jruby-9.0.4.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
@@ -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.
@@ -0,0 +1,63 @@
1
+ # Script Ruby parser plugin for Embulk
2
+
3
+ TODO: Write short description here and embulk-parser-script_ruby.gemspec file.
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: parser
8
+ * **Guess supported**: no
9
+
10
+ ## Configuration
11
+
12
+ - **script**: script (string, required)
13
+ - **class**: class name (string, required)
14
+ - **columns**: Array of columns name & type (Array, required)
15
+
16
+ ## Example
17
+
18
+ config.yaml
19
+
20
+ ```yaml
21
+ in:
22
+ type: any file input plugin type
23
+ parser:
24
+ type: script_ruby
25
+ script: parser_hoge
26
+ class: ParserHoge
27
+ columns:
28
+ - name: id
29
+ type: string
30
+ - name: url
31
+ type: string
32
+ ```
33
+
34
+ lib/parser_hoge.rb
35
+
36
+ ```ruby
37
+ require 'json'
38
+
39
+ class ParserHoge
40
+ def initialize
41
+ end
42
+
43
+ def parser(io)
44
+ json = io.read
45
+ obj = JSON.parse(json)
46
+ obj.each do | row |
47
+ yield row
48
+ end
49
+ end
50
+ end
51
+ ```
52
+
53
+ run
54
+
55
+ ```
56
+ embulk run config.yaml -I lib
57
+ ```
58
+
59
+ ## Build
60
+
61
+ ```
62
+ $ rake
63
+ ```
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :build
@@ -0,0 +1,20 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-parser-script_ruby"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["shinjiikeda"]
6
+ spec.summary = "Script Ruby parser plugin for Embulk"
7
+ spec.description = "Parses Script Ruby files read by other file input plugins."
8
+ spec.email = ["gm.ikeda@gmail.com"]
9
+ spec.licenses = ["MIT"]
10
+ # TODO set this: spec.homepage = "https://github.com/gm.ikeda/embulk-parser-script_ruby"
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_dependency 'YOUR_GEM_DEPENDENCY', ['~> YOUR_GEM_DEPENDENCY_VERSION']
17
+ spec.add_development_dependency 'embulk', ['>= 0.8.9']
18
+ spec.add_development_dependency 'bundler', ['>= 1.10.6']
19
+ spec.add_development_dependency 'rake', ['>= 10.0']
20
+ end
@@ -0,0 +1,63 @@
1
+ module Embulk
2
+ module Guess
3
+
4
+ # TODO implement guess plugin to make this command work:
5
+ # $ embulk guess -g "script_ruby" partial-config.yml
6
+ #
7
+ # Depending on the file format the plugin uses, you can use choose
8
+ # one of binary guess (GuessPlugin), text guess (TextGuessPlugin),
9
+ # or line guess (LineGuessPlugin).
10
+
11
+ #require "embulk/parser/script_ruby.rb"
12
+
13
+ #class ScriptRuby < GuessPlugin
14
+ # Plugin.register_guess("script_ruby", self)
15
+ #
16
+ # def guess(config, sample_buffer)
17
+ # if sample_buffer[0,2] == GZIP_HEADER
18
+ # guessed = {}
19
+ # guessed["type"] = "script_ruby"
20
+ # guessed["property1"] = "guessed-value"
21
+ # return {"parser" => guessed}
22
+ # else
23
+ # return {}
24
+ # end
25
+ # end
26
+ #end
27
+
28
+ #class ScriptRuby < TextGuessPlugin
29
+ # Plugin.register_guess("script_ruby", self)
30
+ #
31
+ # def guess_text(config, sample_text)
32
+ # js = JSON.parse(sample_text) rescue nil
33
+ # if js && js["mykeyword"] == "keyword"
34
+ # guessed = {}
35
+ # guessed["type"] = "script_ruby"
36
+ # guessed["property1"] = "guessed-value"
37
+ # return {"parser" => guessed}
38
+ # else
39
+ # return {}
40
+ # end
41
+ # end
42
+ #end
43
+
44
+ #class ScriptRuby < LineGuessPlugin
45
+ # Plugin.register_guess("script_ruby", self)
46
+ #
47
+ # def guess_lines(config, sample_lines)
48
+ # all_line_matched = sample_lines.all? do |line|
49
+ # line =~ /mypattern/
50
+ # end
51
+ # if all_line_matched
52
+ # guessed = {}
53
+ # guessed["type"] = "script_ruby"
54
+ # guessed["property1"] = "guessed-value"
55
+ # return {"parser" => guessed}
56
+ # else
57
+ # return {}
58
+ # end
59
+ # end
60
+ #end
61
+
62
+ end
63
+ end
@@ -0,0 +1,49 @@
1
+ module Embulk
2
+ module Parser
3
+
4
+ class ScriptRuby < ParserPlugin
5
+ Plugin.register_parser("script_ruby", self)
6
+
7
+ def self.transaction(config, &control)
8
+ # configuration code:
9
+ task = {
10
+ "script" => config.param("script", :string),
11
+ "class" => config.param("class", :string),
12
+ "columns" => config.param("columns", :array),
13
+ }
14
+
15
+ c = 0
16
+ columns = task['columns'].map do | e |
17
+ col = Column.new(c, e['name'], e['type'].to_sym)
18
+ c+=1
19
+ col
20
+ end
21
+
22
+ yield(task, columns)
23
+ end
24
+
25
+ def init
26
+ # initialization code:
27
+ @script = task['script']
28
+ @columns = task['columns']
29
+
30
+ require @script
31
+ @parser_class = Object.const_get(task['class']).new()
32
+ end
33
+
34
+ def run(file_input)
35
+ while file = file_input.next_file
36
+ @parser_class.parser(file) do |record|
37
+ out_record = []
38
+ @columns.each do | e |
39
+ out_record << record[e['name']] if record.has_key?(e['name'])
40
+ end
41
+ page_builder.add(out_record) if out_record.size > 0
42
+ end
43
+ end
44
+ page_builder.finish
45
+ end
46
+ end
47
+
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-parser-script_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shinjiikeda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 0.8.9
19
+ name: embulk
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.9
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.10.6
33
+ name: bundler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.10.6
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ name: rake
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Parses Script Ruby files read by other file input plugins.
56
+ email:
57
+ - gm.ikeda@gmail.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-parser-script_ruby.gemspec
69
+ - lib/embulk/guess/script_ruby.rb
70
+ - lib/embulk/parser/script_ruby.rb
71
+ homepage:
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.8
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Script Ruby parser plugin for Embulk
95
+ test_files: []