fluent-plugin-xml-simple-filter 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e71f20dcf406059270bbe86f573734211d820e61
4
- data.tar.gz: 553de083b32816f6d41b0426be486aa106fb5755
3
+ metadata.gz: c32107fa948e00e92889c682466802ec27f2c4d2
4
+ data.tar.gz: 49514123fdf57baecabda91fbe9cf5855e220c13
5
5
  SHA512:
6
- metadata.gz: 5aa8d7d3c281c796ae4579a16d5ae1d0c455321786e47da9a2b2f8cbe7614df87792ded4ef1f9300f7f8f2bfb63d6b6feaf6996aa42b6a23cb6c90b2c9a127ed
7
- data.tar.gz: e1bbb77be64758f8967cf2484d618d1735ed541a84c0a06535d27f98f0d21eedd6b070f374d2b11e8b20a4a9fdb4c7014d4f8c2e324a841f1a79235818dd21e3
6
+ metadata.gz: c932123d6bcf1a3a6f189299811ac44a32449a910c62a99c734f97d590cca597335697b33e9a8a9dcd3c6d65e4b04aa342f77d06026b7c91d950a0d5061f1bbe
7
+ data.tar.gz: bba3e2c033915283c5524ab6ca582fa603240a75af86f3643399e4f3ae5a6030964c2e596c609fdbd29be22cb56dcbdda54585ec3dfc37b177dbdca7d0007fd7
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: fluent-plugin-xml-simple-filter 0.0.5 ruby lib
5
+ # stub: fluent-plugin-xml-simple-filter 0.0.6 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "fluent-plugin-xml-simple-filter".freeze
9
- s.version = "0.0.5"
9
+ s.version = "0.0.6"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
@@ -6,6 +6,9 @@ module Fluent
6
6
 
7
7
  config_param :fields, :string
8
8
 
9
+ config_param :try_convert_times, :boolean, :default => true # try to convert values in hash to times
10
+ config_param :field_name_postfix, :string, :default => 'hash' # if set will create hash in new field with postfix (xml => xml_hash)
11
+
9
12
  def configure(conf)
10
13
  super
11
14
 
@@ -31,11 +34,35 @@ module Fluent
31
34
  def filter(tag, time, record)
32
35
  self.fields.each { |field|
33
36
  if record.key?(field)
34
- record[field] = @parser.parse(record[field])
37
+ field_name = field
38
+
39
+ if self.field_name_postfix
40
+ field_name = [field, self.field_name_postfix].join '_'
41
+ end
42
+
43
+ hash = @parser.parse(record[field])
44
+
45
+ if try_convert_times
46
+ hash = convert_times(hash)
47
+ end
48
+
49
+ record[field_name] = hash
35
50
  end
36
51
  }
37
52
 
38
53
  record
39
54
  end
55
+
56
+ private
57
+
58
+ def convert_times(hash)
59
+ hash.each { |key, value| value.class == Hash ? convert_times(value) : try_to_convert(value) { |x| Time.parse(x) } }
60
+ end
61
+
62
+ def try_to_convert(value, &block)
63
+ block.call(value)
64
+ rescue ArgumentError
65
+ value
66
+ end
40
67
  end
41
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-xml-simple-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Lukyanov