streamer 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
  SHA1:
3
- metadata.gz: 2ec94108449b6143b468bc841cf65296564d1273
4
- data.tar.gz: b1dd939f742f67d21ebbff7498f9506244bc254c
3
+ metadata.gz: 88c63cc9998dbe3ae65b37738ac19c3faf23b44c
4
+ data.tar.gz: 5a2bf3b5b8f6b0cb4440e927dcf77bc94167c160
5
5
  SHA512:
6
- metadata.gz: 96a144b31e30015954ae677574b6b65b5dc72610e097af4bdcc094625aab92b4c24d2d727aa07b881c56c1c4d332554a1eeac8f1b6729c86ab2ebc608a0e7448
7
- data.tar.gz: f70c324ca3ccbaee3e894707b8e9bfb4056efb2ae3a0a7633da85ef6f7754b4f75c8b6838b3a1d75c953bdbfbb2b5d548b523d3453491949df3f7d498f055fee
6
+ metadata.gz: 153f8a814e055843c837b4d3d80c81d9d4134aef72fcdc203a2f90bf101ab6d63c21ce09aed91c25ffa78f2d008d1c68934cfaa9260bf828498186adc16cc5f7
7
+ data.tar.gz: 071b2a6bb0118435dc21467136ccd226e54799a5633676cbdf028e8bf1eccf280cd115d7935ecbc6f7ea6db353a9241a2781b3315b7a7dfcb8d4755d8abc4838
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- streamer (0.1.1)
4
+ streamer (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/docker-compose.yml CHANGED
@@ -10,7 +10,7 @@ app: &base
10
10
  command: "rake test"
11
11
  guard:
12
12
  <<: *base
13
- command: "nohup guard start --force-polling --no-interactions"
13
+ command: "nohup guard start --no-interactions"
14
14
  ports: []
15
15
  bundle_data:
16
16
  image: tianon/true
@@ -4,19 +4,26 @@ require 'streamer'
4
4
  require 'csv'
5
5
  require 'pry'
6
6
 
7
+ # create a base document to house the sales data
7
8
  sales_numbers = {
8
- 'date' => '2016-02-02',
9
+ 'name' => 'example sales filtering and calculation',
9
10
  'sales' => []
10
11
  }
11
12
 
13
+ # load sales data from a csv and place it into the document
12
14
  data_file_path = File.join(__dir__, 'data.csv')
13
15
  CSV.foreach(data_file_path, headers: true) do |row|
14
16
  sales_numbers['sales'] << row.to_hash
15
17
  end
16
18
 
19
+ # configure a new stream, loading the configuration from a file
17
20
  config_file_path = File.join(__dir__, 'sb_config.yml')
18
21
  sb = Streamer::StreamBuilder.new(YAML.load_file(config_file_path))
22
+
23
+ # process the data document using the configured stream
19
24
  sb.process(sales_numbers)
25
+
26
+ # output the results to stdout
20
27
  sb.payload['summary']['sales_by_product'].each do |k, v|
21
28
  printf "%-20s %d\n", k, v
22
29
  end
@@ -19,7 +19,18 @@
19
19
  :property: summary.sales_by_product
20
20
  :function:
21
21
  :type: group
22
- :list: sales
22
+ :list:
23
+ :function:
24
+ :type: list_filter
25
+ :list: sales
26
+ :filters:
27
+ - :function:
28
+ :type: member
29
+ :properties:
30
+ - customer_state
31
+ :facts:
32
+ - IA
33
+ - KS
23
34
  :by: product
24
35
  :operator: +
25
36
  :operand: amount
@@ -1,5 +1,6 @@
1
1
  require 'streamer/fact_providers/yaml_provider'
2
2
  require 'streamer/fact_providers/hash_provider'
3
+ require 'streamer/fact_providers/csv_provider'
3
4
 
4
5
  module Streamer
5
6
  # FactProviders are used by finders to find facts
@@ -0,0 +1,52 @@
1
+ require 'csv'
2
+
3
+ module Streamer
4
+ module FactProviders
5
+ # CSVProvider implements Finder Provider interface
6
+ class CSVProvider
7
+ attr_reader :path, :key
8
+
9
+ def initialize(path)
10
+ @path = path
11
+ end
12
+
13
+ def find(key)
14
+ @key = key
15
+ return hash_result if segments.size == 2
16
+ return scalar_result if segments.size == 3
17
+ end
18
+
19
+ def segments
20
+ key.split('.')
21
+ end
22
+
23
+ def hash_result
24
+ Hash[headers.zip CSV.parse_line(lines)]
25
+ end
26
+
27
+ def scalar_result
28
+ hash_result[segments[2]]
29
+ end
30
+
31
+ def lines
32
+ `#{processing_statement}`.strip
33
+ end
34
+
35
+ def headers
36
+ @headers ||= CSV.parse_line(`head -n 1 #{path}`)
37
+ end
38
+
39
+ def field_number(field)
40
+ headers.index(field) + 1
41
+ end
42
+
43
+ def processing_statement
44
+ segs = segments
45
+ return unless segs.size > 1 && segs.size < 4
46
+ <<-STMT
47
+ awk -F'","|,' '($#{field_number(segs[0])} ~ /^#{segs[1]}$/){print $0}' #{path}
48
+ STMT
49
+ end
50
+ end
51
+ end
52
+ end
@@ -7,7 +7,6 @@ module Streamer
7
7
  total + item[options.fetch(:property)]
8
8
  end
9
9
  end
10
-
11
10
  end
12
11
  end
13
12
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Streamer
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
data/script/example1 ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ echo "running example 1"
4
+ docker-compose run --rm guard examples/example1/example.rb
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streamer
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
  - Scott Helm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-10 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -177,6 +177,7 @@ files:
177
177
  - examples/example1/sb_config.yml
178
178
  - lib/streamer.rb
179
179
  - lib/streamer/fact_providers.rb
180
+ - lib/streamer/fact_providers/csv_provider.rb
180
181
  - lib/streamer/fact_providers/hash_provider.rb
181
182
  - lib/streamer/fact_providers/yaml_provider.rb
182
183
  - lib/streamer/finder.rb
@@ -202,6 +203,7 @@ files:
202
203
  - lib/streamer/stream_builder.rb
203
204
  - lib/streamer/version.rb
204
205
  - script/console
206
+ - script/example1
205
207
  - script/init
206
208
  - script/itest
207
209
  - script/shell
@@ -228,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
230
  version: '0'
229
231
  requirements: []
230
232
  rubyforge_project:
231
- rubygems_version: 2.5.1
233
+ rubygems_version: 2.5.2
232
234
  signing_key:
233
235
  specification_version: 4
234
236
  summary: streams a hash through a set of configurable functions