embulk-parser-xml 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da39918e4e87ef06f5a8a3f1c321062ef00f10b4
4
+ data.tar.gz: e440ca6333be465a791abeb0b0998e02f7251440
5
+ SHA512:
6
+ metadata.gz: 010d16da3d32201b038fe0f219eae33ae19115bf2d465e904c30035b5d1b093197b8067b9dc11593c4e8ab6bfed8360ff640342e7626c508c74a9d14ce746be8
7
+ data.tar.gz: 89467d469d2d7547b03c04102a8c4a1216318daad0a463d03b7ccb3749e013acfcfb632d89e42ec7654ddd1825d089ac28f48c0158d5a325a513942cd963f50e
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TODO: Write your name
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.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # XML parser plugin for Embulk
2
+
3
+ Parser plugin for [Embulk](https://github.com/embulk/embulk).
4
+
5
+ Read data from input as xml and fetch each entries to output.
6
+
7
+ ## Overview
8
+
9
+ * **Plugin type**: parser
10
+ * **Load all or nothing**: yes
11
+ * **Resume supported**: no
12
+
13
+
14
+ ## Configuration
15
+
16
+ ```yaml
17
+ parser:
18
+ type: xml
19
+ root: data/students/student
20
+ schema:
21
+ - {name: name, type: string}
22
+ - {name: age, type: long}
23
+ ```
24
+
25
+ - **type**: specify this plugin as `xml`
26
+ - **root**: root property to start fetching each entries, specify in *path/to/node* style, required
27
+ - **schema**: specify the attribute of table and data type, required
28
+
29
+ Then you can fetch entries from the following xml:
30
+
31
+ ```xml
32
+ <data>
33
+ <result>true</result>
34
+ <students>
35
+ <student>
36
+ <name>John</name>
37
+ <age>10</name>
38
+ <student>
39
+ <student>
40
+ <name>Paul</name>
41
+ <age>16</name>
42
+ <student>
43
+ <student>
44
+ <name>George</name>
45
+ <age>17</name>
46
+ <student>
47
+ <student>
48
+ <name>Ringo</name>
49
+ <age>18</name>
50
+ <student>
51
+ </students>
52
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "embulk-parser-xml"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Takuma kanari"]
9
+ spec.email = ["chemtrails.t@gmail.com"]
10
+ spec.summary = %q{Embulk parser plugin for XML}
11
+ spec.description = %q{XML parser plugin is Embulk plugin to fetch entries in xml format.}
12
+ spec.homepage = "https://github.com/takumakanari/embulk-parser-xml"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.0"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ end
@@ -0,0 +1,63 @@
1
+ require "rexml/document"
2
+
3
+ module Embulk
4
+ module Parser
5
+
6
+ class XmlParserPlugin < ParserPlugin
7
+ Plugin.register_parser("xml", self)
8
+
9
+ def self.transaction(config, &control)
10
+ task = {
11
+ :schema => config.param("schema", :array),
12
+ :root => config.param("root", :string)
13
+ }
14
+ columns = task[:schema].each_with_index.map do |c, i|
15
+ Column.new(i, c["name"], c["type"].to_sym)
16
+ end
17
+ yield(task, columns)
18
+ end
19
+
20
+ def run(file_input)
21
+ schema = @task["schema"]
22
+ root = @task["root"]
23
+ while file = file_input.next_file
24
+ REXML::Document.new(file.read).elements.each(root) do |e|
25
+ dest = {}
26
+ e.elements.each do |d|
27
+ dest[d.name] = d.text
28
+ end
29
+ @page_builder.add(make_record(schema, dest))
30
+ end
31
+ end
32
+ @page_builder.finish
33
+ end
34
+
35
+ private
36
+
37
+ def make_record(schema, e)
38
+ schema.map do |c|
39
+ name = c["name"]
40
+ val = e[name]
41
+
42
+ v = val.nil? ? "" : val
43
+ type = c["type"]
44
+ case type
45
+ when "string"
46
+ v
47
+ when "long"
48
+ v.to_i
49
+ when "double"
50
+ v.to_f
51
+ when "boolean"
52
+ ["yes", "true", "1"].include?(v.downcase)
53
+ when "timestamp"
54
+ v.empty? ? nil : Time.strptime(v, c["format"])
55
+ else
56
+ raise "Unsupported type #{type}"
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-parser-xml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Takuma kanari
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-14 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.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
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
+ description: XML parser plugin is Embulk plugin to fetch entries in xml format.
42
+ email:
43
+ - chemtrails.t@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - embulk-parser-xml.gemspec
54
+ - lib/embulk/parser/xml.rb
55
+ homepage: https://github.com/takumakanari/embulk-parser-xml
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.2.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Embulk parser plugin for XML
79
+ test_files: []