embulk-parser-xml 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,9 +22,18 @@ parser:
22
22
  - {name: age, type: long}
23
23
  ```
24
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
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
+ If you need to parse column as timestamp type, *schema* supports 2 optional parameters:
30
+
31
+ ```yaml
32
+ schema:
33
+ - {name: timestamp_column, type: timestamp, format: "%Y-%m-%d", timezone: "+0000"}
34
+ ```
35
+ - **format**: timestamp format to parse, required.
36
+ - **timezone**: timestamp will be parsing in this timezone, `"+0900"` is used by default.
28
37
 
29
38
  Then you can fetch entries from the following xml:
30
39
 
@@ -50,4 +59,4 @@ Then you can fetch entries from the following xml:
50
59
  </student>
51
60
  </students>
52
61
  </data>
53
- ```
62
+ ```
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "embulk-parser-xml"
7
- spec.version = "0.0.4"
7
+ spec.version = "0.0.5"
8
8
  spec.authors = ["Takuma kanari"]
9
9
  spec.email = ["chemtrails.t@gmail.com"]
10
10
  spec.summary = %q{Embulk parser plugin for XML}
@@ -9,7 +9,13 @@ module Embulk
9
9
  def self.transaction(config, &control)
10
10
  schema = config.param("schema", :array)
11
11
  schema_serialized = schema.inject({}) do |memo, s|
12
- memo[s["name"]] = s["type"]
12
+ memo[s["name"]] = {"type" => s["type"]}
13
+ if s["type"] == "timestamp"
14
+ memo[s["name"]].merge!({
15
+ "format" => s["format"],
16
+ "timezone" => s["timezone"] || "+0900"
17
+ })
18
+ end
13
19
  memo
14
20
  end
15
21
  task = {
@@ -100,9 +106,9 @@ module Embulk
100
106
  end
101
107
  end
102
108
 
103
- def convert(val, type)
109
+ def convert(val, config)
104
110
  v = val.nil? ? "" : val
105
- case type
111
+ case config["type"]
106
112
  when "string"
107
113
  v
108
114
  when "long"
@@ -112,7 +118,14 @@ module Embulk
112
118
  when "boolean"
113
119
  ["yes", "true", "1"].include?(v.downcase)
114
120
  when "timestamp"
115
- v.empty? ? nil : Time.strptime(v, c["format"])
121
+ unless v.empty?
122
+ dest = Time.strptime(v, config["format"])
123
+ utc_offset = dest.utc_offset
124
+ zone_offset = Time.zone_offset(config["timezone"])
125
+ dest.localtime(zone_offset) + utc_offset - zone_offset
126
+ else
127
+ nil
128
+ end
116
129
  else
117
130
  raise "Unsupported type '#{type}'"
118
131
  end
metadata CHANGED
@@ -1,55 +1,62 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-parser-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Takuma kanari
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-08-02 00:00:00.000000000 Z
12
+ date: 2016-02-27 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: nokogiri
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - "~>"
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '1.6'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - "~>"
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.6'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: bundler
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - "~>"
35
+ - - ~>
32
36
  - !ruby/object:Gem::Version
33
37
  version: '1.0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - "~>"
43
+ - - ~>
39
44
  - !ruby/object:Gem::Version
40
45
  version: '1.0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rake
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - "~>"
51
+ - - ~>
46
52
  - !ruby/object:Gem::Version
47
53
  version: '10.0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - "~>"
59
+ - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: '10.0'
55
62
  description: XML parser plugin is Embulk plugin to fetch entries in xml format.
@@ -59,7 +66,7 @@ executables: []
59
66
  extensions: []
60
67
  extra_rdoc_files: []
61
68
  files:
62
- - ".gitignore"
69
+ - .gitignore
63
70
  - Gemfile
64
71
  - LICENSE.txt
65
72
  - README.md
@@ -69,25 +76,26 @@ files:
69
76
  homepage: https://github.com/takumakanari/embulk-parser-xml
70
77
  licenses:
71
78
  - MIT
72
- metadata: {}
73
79
  post_install_message:
74
80
  rdoc_options: []
75
81
  require_paths:
76
82
  - lib
77
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
78
85
  requirements:
79
- - - ">="
86
+ - - ! '>='
80
87
  - !ruby/object:Gem::Version
81
88
  version: '0'
82
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
83
91
  requirements:
84
- - - ">="
92
+ - - ! '>='
85
93
  - !ruby/object:Gem::Version
86
94
  version: '0'
87
95
  requirements: []
88
96
  rubyforge_project:
89
- rubygems_version: 2.2.2
97
+ rubygems_version: 1.8.23
90
98
  signing_key:
91
- specification_version: 4
99
+ specification_version: 3
92
100
  summary: Embulk parser plugin for XML
93
101
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: ace02cec80163c6715578043b31500af1783e4bd
4
- data.tar.gz: 8ebd59d04f9ac7ae966b1c5bfff085a4dae0f1fa
5
- SHA512:
6
- metadata.gz: ed2ee84816accf96eb8b391f7bc11f2a771d545a1f48ebb994a25ff7c0ed9042ccc0030caaa4a1a567b5688c0f79c12665971c8d063205e6d1b1683663fef0ff
7
- data.tar.gz: fa8dfb6de0f1953f2eaffb3c1003081c3095d8dc27d9097c500327dadb46c4460ad99700703ea8f70f5ce3b76c443034e8d785ffb03be389fafc064921eb3211