data_collector 0.1.1 → 0.2.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 +4 -4
- data/lib/data_collector/core.rb +7 -0
- data/lib/data_collector/rules.rb +87 -0
- data/lib/data_collector/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b07f4470cd479e1e583e15471b3a6e8bd94cfb3b7fc8b544c5d87d300f3f3e52
|
4
|
+
data.tar.gz: c678d753b77ef3205fe0a1864128299864292cc1a740e07351bc6e6ef389dbbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eb7c54eaeb552d14eb97a260dc47882d0b69a527b73680f258909ab18bef424c3fe0203b13335801dcdb7b6f45ab7c96fb26fefee635e97d009709a68506193
|
7
|
+
data.tar.gz: 22c9d32bfb1092e7135df2d5d2e12d8a3449ad2efe6d043ef6207cecab7094de2dcc94c45e0289e06c1a4ac866e7bc7287a657a778292437d4fa429f1b192531
|
data/lib/data_collector/core.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|