data_collector 0.2.0 → 0.2.1

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: b07f4470cd479e1e583e15471b3a6e8bd94cfb3b7fc8b544c5d87d300f3f3e52
4
- data.tar.gz: c678d753b77ef3205fe0a1864128299864292cc1a740e07351bc6e6ef389dbbd
3
+ metadata.gz: b38644344f6bcfa74d68a2281b83c803879334fbd0f281fde4de8f92b180c5ec
4
+ data.tar.gz: 582650f6f0237f4a45c45ab137b6eac0110117b77a7b917eae448d17285ae999
5
5
  SHA512:
6
- metadata.gz: 4eb7c54eaeb552d14eb97a260dc47882d0b69a527b73680f258909ab18bef424c3fe0203b13335801dcdb7b6f45ab7c96fb26fefee635e97d009709a68506193
7
- data.tar.gz: 22c9d32bfb1092e7135df2d5d2e12d8a3449ad2efe6d043ef6207cecab7094de2dcc94c45e0289e06c1a4ac866e7bc7287a657a778292437d4fa429f1b192531
6
+ metadata.gz: 550f42750545164f6e7f47347144023be9c1bb58ff661886e1a5ef51c2804fcea8d75b87c65ce29b6a288a3e24bcbfce26f5987c17424cdb1023fda510675b49
7
+ data.tar.gz: ee0d60db7824fda4688c0c41aed8f8e2884aeb5d9e0b4178c53685a4fcc44e3ef93f848f3b597d6c7b8fdb85a64ffe155f03e9e6bc59fcf54fc109b662a5d892
data/README.md CHANGED
@@ -73,6 +73,38 @@ filter data from a hash using [JsonPath](http://goessner.net/articles/JsonPath/i
73
73
  filtered_data = filter(data, "$..metadata.record")
74
74
  ```
75
75
 
76
+ #### rules
77
+
78
+ rules allows you to define a simple structure to run against a JSONPath filter
79
+
80
+ A rule is made up of a Hash the key is the map key field its value is a Hash with a JSONPath filter and options to apply a convert method on the filtered results.
81
+ Available convert methods are: time, map, each, call, suffix
82
+ - time: Parses a given time/date string into a Time object
83
+ - map: applies a mapping to a filter
84
+ - suffix: adds a suffix to a result
85
+ - call: executes a lambda on the filter
86
+ - each: runs a lambda on each row of a filter
87
+
88
+ example:
89
+ ```ruby
90
+ my_rules = {
91
+ 'identifier' => {"filter" => '$..id'},
92
+ 'language' => {'filter' => '$..lang',
93
+ 'options' => {'convert' => 'map',
94
+ 'map' => {'nl' => 'dut', 'fr' => 'fre', 'de' => 'ger', 'en' => 'eng'}
95
+ }
96
+ },
97
+ 'subject' => {'filter' => '$..keywords',
98
+ options' => {'convert' => 'each',
99
+ 'lambda' => lambda {|d| d.split(',')}
100
+ }
101
+ },
102
+ 'creationdate' => {'filter' => '$..published_date', 'convert' => 'time'}
103
+ }
104
+
105
+ rules.run(my_rules, record, output)
106
+ ```
107
+
76
108
  #### config
77
109
  config is an object that points to "config.yml" you can read and/or store data to this object.
78
110
 
@@ -47,6 +47,33 @@ module DataCollector
47
47
  @output ||= Output.new
48
48
  end
49
49
 
50
+ #You can apply rules to input
51
+ # A rule is made up of a Hash the key is the map key field its value is a Hash with a JSONPath filter and
52
+ # options to apply a convert method on the filtered results.
53
+ #
54
+ # available convert methods are: time, map, each, call, suffix
55
+ # - time: Parses a given time/date string into a Time object
56
+ # - map: applies a mapping to a filter
57
+ # - suffix: adds a suffix to a result
58
+ # - call: executes a lambda on the filter
59
+ # - each: runs a lambda on each row of a filter
60
+ #
61
+ # example:
62
+ # my_rules = {
63
+ # 'identifier' => {"filter" => '$..id'},
64
+ # 'language' => {'filter' => '$..lang',
65
+ # 'options' => {'convert' => 'map',
66
+ # 'map' => {'nl' => 'dut', 'fr' => 'fre', 'de' => 'ger', 'en' => 'eng'}
67
+ # }
68
+ # },
69
+ # 'subject' => {'filter' => '$..keywords',
70
+ # options' => {'convert' => 'each',
71
+ # 'lambda' => lambda {|d| d.split(',')}
72
+ # }
73
+ # },
74
+ # 'creationdate' => {'filter' => '$..published_date', 'convert' => 'time'}
75
+ # }
76
+ # rules.run(my_rules, input, output)
50
77
  def rules
51
78
  @rules ||= Rules.new
52
79
  end
@@ -25,7 +25,7 @@ module DataCollector
25
25
 
26
26
  private
27
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')
28
+ if rule.has_key?('options') && rule['options'].has_key?('convert') && rule['options']['convert'].eql?('each')
29
29
  result = get_value_for(map_to_key, rule['filter'], from_record, rule['options'])
30
30
 
31
31
  if result.is_a?(Array)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module DataCollector
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Celik