data_collector 0.4.0 → 0.5.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: 5fb3cc5c42f536a8bdc99421eb6f46972c6c97597f5c0af63e96463f320837ef
4
- data.tar.gz: d377133bf042985f6d68b2bb2960d9c4ddae169a39d4602df4a3f4003d6b6434
3
+ metadata.gz: f8b064bcc0483a98014157586cb18473d240486f3e4c1550b9eeba0cc026af6b
4
+ data.tar.gz: 503c959ca4d3ac06e65e41f0f721aed795b27871d220d676eeb6bc7b81a169d1
5
5
  SHA512:
6
- metadata.gz: cd48af243e1615e8cafaf8ed1ab4d9019661e3205286fbd32c9ec4bb3e2faa7e07025a62b378062f10dfc0f1775acb401ad4cb901851cbbaf4cb78a2e7c6474a
7
- data.tar.gz: c92eee26040f89ab0b691ba6bf4ad9792222e545e82bb9ebea8b4a4941831615a74d9f389e58d6feccf89ba42c6dd5a02c55bfed996fc670cd1d9600d5023476
6
+ metadata.gz: 34b2b890765598022e97ee914d6159bd6741ac6d2f711189c81144e880a6590b74183355417d32c3cf39197aad0be914c5d6c6c0089379beac3e14c4bf0b1b01
7
+ data.tar.gz: 860aa1bab4a0a0c580840f12bf42f77b76598a7433b033211d200647117c91754b49c76540cb52bf58a96184498293c8c0e73659481a7a938277dd53cbd9f7e1
@@ -10,29 +10,40 @@ module DataCollector
10
10
  rules.each do |tag, rule|
11
11
  apply_rule(tag, rule, input_data, output_data, options)
12
12
  end
13
+
14
+ output_data
13
15
  end
14
16
 
15
17
  private
18
+
16
19
  def apply_rule(tag, rule, input_data, output_data, options = {})
17
- if rule.is_a?(Array)
20
+ rule_filter = rule
21
+ rule_payload = ""
22
+
23
+ case rule
24
+ when Array
18
25
  rule.each do |sub_rule|
19
- apply_rule(tag, sub_rule, input_data, output_data, options)
26
+ apply_rule(tag, sub_rule, input_data, output_data, options)
20
27
  end
21
28
  return output_data
29
+ when String
30
+ rule_filter = rule
31
+ rule_payload = ""
32
+ else
33
+ rule_filter = rule.keys.first
34
+ rule_payload = rule.values.first
22
35
  end
23
36
 
24
- rule_filter = rule.keys.first
25
- rule_payload = rule.values.first
26
37
  case rule_filter
27
38
  when 'text'
28
39
  if rule_payload.is_a?(String)
29
40
  data = rule_payload
30
41
  else
31
- data = rule_payload.select{|s| s.is_a?(String)}
32
- rule_payload = rule_payload.delete_if{|s| s.is_a?(String)}
33
- if rule_payload.size == 1
34
- rule_payload = rule_payload.first
35
- end
42
+ data = rule_payload.select { |s| s.is_a?(String) }
43
+ rule_payload = rule_payload.delete_if { |s| s.is_a?(String) }
44
+ # if rule_payload.size == 1
45
+ # rule_payload = rule_payload.first
46
+ # end
36
47
  end
37
48
  when /json_path\:/
38
49
  data = json_path_filter(rule_filter.gsub(/^json_path\:/), input_data)
@@ -42,17 +53,22 @@ module DataCollector
42
53
 
43
54
  data = apply_filtered_data_on_payload(data, rule_payload, options)
44
55
 
45
- output_data << {tag.to_sym => data}
56
+ output_data << {tag.to_sym => data} unless data.nil? || (data.is_a?(Array) && data.empty?)
57
+ rescue StandardError => e
58
+ puts "error running rule '#{tag}'\n\t#{e.message}"
59
+ puts e.backtrace.join("\n")
46
60
  end
47
61
 
48
62
  def apply_filtered_data_on_payload(input_data, payload, options = {})
63
+ return nil if input_data.nil?
49
64
  output_data = nil
50
65
  case payload.class.name
51
66
  when 'Proc'
67
+ data = input_data.is_a?(Array) ? input_data : [input_data]
52
68
  if options && options.empty?
53
- output_data = payload.call(input_data)
69
+ output_data = data.map { |d| payload.call(d) }
54
70
  else
55
- output_data = payload.call(input_data, options)
71
+ output_data = data.map { |d| payload.call(d, options) }
56
72
  end
57
73
  when 'Hash'
58
74
  input_data = [input_data] unless input_data.is_a?(Array)
@@ -69,10 +85,12 @@ module DataCollector
69
85
  output_data = apply_filtered_data_on_payload(output_data, p, options)
70
86
  end
71
87
  else
72
- output_data = input_data
88
+ output_data = [input_data]
73
89
  end
74
90
 
91
+ output_data = output_data.first if output_data.is_a?(Array) && output_data.size == 1
75
92
  output_data.compact! if output_data.is_a?(Array)
93
+ output_data.flatten! if output_data.is_a?(Array)# || output_data.is_a?(Hash)
76
94
  output_data
77
95
  end
78
96
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module DataCollector
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.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.4.0
4
+ version: 0.5.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: 2020-03-20 00:00:00.000000000 Z
11
+ date: 2020-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  - !ruby/object:Gem::Version
227
227
  version: '0'
228
228
  requirements: []
229
- rubygems_version: 3.0.2
229
+ rubygems_version: 3.0.6
230
230
  signing_key:
231
231
  specification_version: 4
232
232
  summary: ETL helper library