embulk-parser-flexml 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a99a2091abdafdf69fdcc88e000bc6ce2c8e5cb
4
+ data.tar.gz: e157fc931e663f42d69011eacfae825dfb860790
5
+ SHA512:
6
+ metadata.gz: 15c101ea8ccaac10911ae71de566684d246824b9ff3bcbd0dbb9c118784434074299fe31ee9f2fd88191ab0d37ee25467f59004f93d4dfa84316a5e1c6fb52f1
7
+ data.tar.gz: 79f44d9eaede4fd1b1f62775bf728fceb9304e25bc9c2a492507f6f4c2ca1c3db386d25a85c022b3187d597f3d7a72f64d9f25621f6bb31e42e2944dd5257093
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Surya Asriadie
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # embulk-parser-flexml
2
+ Flexible xml parser for embulk - supports xpath and attributes
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "embulk-parser-flexml"
6
+ spec.version = "0.0.0"
7
+ spec.authors = ["Surya Asriadie"]
8
+ spec.email = ["surya.asriadie@gmail.com"]
9
+ spec.summary = %q{Flexible Embulk parser plugin for XML}
10
+ spec.description = %q{XML parser plugin is Embulk plugin to fetch entries in xml format. Supports xpath and attributes}
11
+ spec.homepage = "https://github.com/Fs02/embulk-parser-flexml"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "rexml", "~> 3.1"
19
+ spec.add_development_dependency "bundler", "~> 1.0"
20
+ spec.add_development_dependency 'embulk', ['>= 0.9.15']
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,91 @@
1
+ require 'rexml/document'
2
+
3
+ module Embulk
4
+ module Parser
5
+ include REXML
6
+
7
+ class Flexml < ParserPlugin
8
+ Plugin.register_parser("flexml", self)
9
+
10
+ def self.transaction(config, &control)
11
+ schema = config.param("schema", :array)
12
+ schema_serialized = schema.inject({}) do |memo, s|
13
+ memo[s["name"]] = s
14
+ if s["type"] == "timestamp"
15
+ memo[s["name"]].merge!({
16
+ "format" => s["format"],
17
+ "timezone" => s["timezone"] || "+0900"
18
+ })
19
+ end
20
+ memo
21
+ end.to_h
22
+ task = {
23
+ :schema => schema_serialized,
24
+ :root => config.param("root", :string)
25
+ }
26
+ columns = schema.each_with_index.map do |c, i|
27
+ Column.new(i, c["name"], c["type"].to_sym)
28
+ end
29
+ yield(task, columns)
30
+ end
31
+
32
+ def run(file_input)
33
+ while file = file_input.next_file
34
+ begin
35
+ xml_text = file.read
36
+ doc = Document.new(xml_text)
37
+ doc.elements.each(@task[:root]) do |e|
38
+ values = @task[:schema].map do |f, c|
39
+ row = if c.has_key?("xpath")
40
+ XPath.first(e, c["xpath"])
41
+ elsif c.has_key?("element")
42
+ e.element(c["element"])
43
+ else
44
+ e
45
+ end
46
+
47
+ val = if c.has_key?("attribute")
48
+ row.attributes[c["attribute"]]
49
+ else
50
+ row.text
51
+ end
52
+ convert(val, c)
53
+ end
54
+
55
+ @page_builder.add(values)
56
+ end
57
+ rescue Exception => e
58
+ puts "=>>>> ERROR: #{e}"
59
+ end
60
+ end
61
+
62
+ @page_builder.finish
63
+ end
64
+
65
+ def convert(val, config)
66
+ v = val.nil? ? "" : val
67
+ case config["type"]
68
+ when "string"
69
+ v
70
+ when "long"
71
+ v.to_i
72
+ when "double"
73
+ v.to_f
74
+ when "boolean"
75
+ ["yes", "true", "1"].include?(v.downcase)
76
+ when "timestamp"
77
+ unless v.empty?
78
+ dest = Time.strptime(v, config["format"])
79
+ utc_offset = dest.utc_offset
80
+ zone_offset = Time.zone_offset(config["timezone"])
81
+ dest.localtime(zone_offset) + utc_offset - zone_offset
82
+ else
83
+ nil
84
+ end
85
+ else
86
+ raise "Unsupported type '#{type}'"
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-parser-flexml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Surya Asriadie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-11-15 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: '3.1'
19
+ name: rexml
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
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.0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.15
47
+ name: embulk
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.15
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ name: rake
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: XML parser plugin is Embulk plugin to fetch entries in xml format. Supports
70
+ xpath and attributes
71
+ email:
72
+ - surya.asriadie@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - LICENSE
79
+ - README.md
80
+ - embulk-parser-flexml.gemspec
81
+ - lib/embulk/parser/flexml.rb
82
+ homepage: https://github.com/Fs02/embulk-parser-flexml
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.6.14
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Flexible Embulk parser plugin for XML
106
+ test_files: []