data_collector 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8410e7e260bf1989dfee0d4279b4c7d57dcd6276a5219c3bfb48663659044436
4
- data.tar.gz: 0d0e78c365f927287ea7875392e83ac946da4e9ca8a764e86dc34d0e03e195b5
3
+ metadata.gz: b07f4470cd479e1e583e15471b3a6e8bd94cfb3b7fc8b544c5d87d300f3f3e52
4
+ data.tar.gz: c678d753b77ef3205fe0a1864128299864292cc1a740e07351bc6e6ef389dbbd
5
5
  SHA512:
6
- metadata.gz: 72ed7c28c8f9513be5ff136827dcf07336b1fee931c17049448c8c915530e919a278dd6e478119dac3c8fb1c20e98cce1314cdbd33dd71110cb07e0fc7ab7286
7
- data.tar.gz: 20ea6369d094f13ce763305369037591a5c3412562fe350fccd58b9f4de8bfd5d37b830e49214d835c2ef039ca2252bac001ea41f571bde2ab51302e3d4c3146
6
+ metadata.gz: 4eb7c54eaeb552d14eb97a260dc47882d0b69a527b73680f258909ab18bef424c3fe0203b13335801dcdb7b6f45ab7c96fb26fefee635e97d009709a68506193
7
+ data.tar.gz: 22c9d32bfb1092e7135df2d5d2e12d8a3449ad2efe6d043ef6207cecab7094de2dcc94c45e0289e06c1a4ac866e7bc7287a657a778292437d4fa429f1b192531
@@ -3,6 +3,7 @@ require 'jsonpath'
3
3
 
4
4
  require_relative 'input'
5
5
  require_relative 'output'
6
+ require_relative 'rules'
6
7
  require_relative 'config_file'
7
8
 
8
9
  module DataCollector
@@ -46,6 +47,10 @@ module DataCollector
46
47
  @output ||= Output.new
47
48
  end
48
49
 
50
+ def rules
51
+ @rules ||= Rules.new
52
+ end
53
+
49
54
  # evaluator http://jsonpath.com/
50
55
  # uitleg http://goessner.net/articles/JsonPath/index.html
51
56
  def filter(data, filter_path)
@@ -72,5 +77,7 @@ module DataCollector
72
77
  def log(message)
73
78
  @logger.info(message)
74
79
  end
80
+
75
81
  end
82
+
76
83
  end
@@ -0,0 +1,87 @@
1
+ require 'logger'
2
+ #require_relative 'core'
3
+
4
+ module DataCollector
5
+ class Rules
6
+ def initialize()
7
+ @logger = Logger.new(STDOUT)
8
+ end
9
+
10
+ def run(rule_map, from_record, to_record)
11
+ rule_map.each do |map_to_key, rule|
12
+ if rule.is_a?(Array)
13
+ rule.each do |sub_rule|
14
+ apply_rule(map_to_key, sub_rule, from_record, to_record)
15
+ end
16
+ else
17
+ apply_rule(map_to_key, rule, from_record, to_record)
18
+ end
19
+ end
20
+
21
+ to_record.each do |element|
22
+ element = element.delete_if{||}
23
+ end
24
+ end
25
+
26
+ private
27
+ def apply_rule(map_to_key, rule, from_record, to_record)
28
+ if rulev.has_key?('options') && rule['options'].has_key?('convert') && rule['options']['convert'].eql?('each')
29
+ result = get_value_for(map_to_key, rule['filter'], from_record, rule['options'])
30
+
31
+ if result.is_a?(Array)
32
+
33
+ result.each do |m|
34
+ to_record << {map_to_key.to_sym => m}
35
+ end
36
+
37
+ else
38
+ to_record << {map_to_key.to_sym => result}
39
+ end
40
+ else
41
+ to_record << {map_to_key.to_sym => get_value_for(map_to_key, rule['filter'], from_record, rule['options'])}
42
+ end
43
+ end
44
+
45
+ def get_value_for(tag_key, filter_path, record, options = {})
46
+ data = nil
47
+ if record
48
+ data = Core::filter(record, filter_path)
49
+
50
+ if data && options
51
+ if options.key?('convert')
52
+ case options['convert']
53
+ when 'time'
54
+ data = Time.parse(data).strftime('%Y-%m-%d')
55
+ when 'map'
56
+ if data.is_a?(Array)
57
+ data = data.map do |r|
58
+ return options['map'][r] if options['map'].key?(r)
59
+ end
60
+
61
+ data.compact!
62
+ else
63
+ return options['map'][data] if options['map'].key?(data)
64
+ end
65
+ when 'each'
66
+ data = [data] unless data.is_a?(Array)
67
+ data = data.map {|d| options['lambda'].call(d)}
68
+ #pp data
69
+ when 'call'
70
+ return options['lambda'].call(data)
71
+ end
72
+ end
73
+
74
+ if options.key?('suffix')
75
+ data = data.to_s
76
+ data += options['suffix']
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+
83
+ return data
84
+ end
85
+
86
+ end
87
+ end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module DataCollector
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Celik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-08 00:00:00.000000000 Z
11
+ date: 2019-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -200,6 +200,7 @@ files:
200
200
  - lib/data_collector/ext/xml_utility_node.rb
201
201
  - lib/data_collector/input.rb
202
202
  - lib/data_collector/output.rb
203
+ - lib/data_collector/rules.rb
203
204
  - lib/data_collector/runner.rb
204
205
  - lib/data_collector/version.rb
205
206
  homepage: https://github.com/mehmetc/data_collector