streamer 0.1.0 → 0.1.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: 655dc75a47e90878f04948b1351522153a219642
4
- data.tar.gz: 74dcb7d677292c677d23a23cfc223a5688e13a82
3
+ metadata.gz: 90dbc68e3c8adf372f06c4381cc35b74dc080534
4
+ data.tar.gz: 71c4278b1e1aac8d7b7f602f4102758207f9cdfe
5
5
  SHA512:
6
- metadata.gz: 32be140c573eb44976662a107f1e8af0167ba470cd2f1b74eb196279fb1f5f59111c534a9c90e94e4f0d6fcbb8d67a43c00490a9845ba9ec43e046d5cce75711
7
- data.tar.gz: a9d0874e28eea23d1e968f691423231aa0d9145d50b718c69e294e65ed785abefd2441a5745d1c7323757507966d744cc9ff879366986f34bf650bf5203f8189
6
+ metadata.gz: bdc5d83f093256515d60679c91d419d3d9c8a26ddf889bd8c47a36ba0dcd200fa7c63d1c82a9a344248dc8605cf2d66208960264ab4bdd538cbd8358dfec448a
7
+ data.tar.gz: edcc7555b28a958055e362fcde5dbc27004e94b209ed864eb34ef16ac5e1b1ae8b7fadfb75f5c676a5998ef68d252e31e41ba8bcde7c125638f95be592f2a25e
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ nohup.out
3
3
  incentive_config.yml
4
4
  coverage
5
5
  *.gem
6
+ playground
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- streamer (0.1.0)
4
+ streamer (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Streamer
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/streamer.svg)](https://badge.fury.io/rb/streamer)
3
4
  [![Build Status](https://travis-ci.org/scotthelm/streamer.svg?branch=master)](https://travis-ci.org/scotthelm/streamer)
4
5
  [![Code Climate](https://codeclimate.com/github/scotthelm/streamer/badges/gpa.svg)](https://codeclimate.com/github/scotthelm/streamer)
5
6
  [![Test Coverage](https://codeclimate.com/github/scotthelm/streamer/badges/coverage.svg)](https://codeclimate.com/github/scotthelm/streamer/coverage)
@@ -13,18 +13,37 @@ module Streamer
13
13
  end
14
14
 
15
15
  def class_name
16
- "Streamer::Functors::#{options.fetch(:type).capitalize}"
16
+ "Streamer::Functors::#{type_name}"
17
+ end
18
+
19
+ def type_name
20
+ options.fetch(:type).to_s.split('_').map(&:capitalize).join
17
21
  end
18
22
 
19
23
  private
20
24
 
21
- def compare(op_symbol)
22
- tar = target(options.fetch(:target))
23
- function = options[:function]
24
- value = options[:value]
25
- return functor(function).call.send(op_symbol, tar) if function
26
- return value.send(op_symbol, tar) unless value.nil?
27
- fail 'Streamer::Functor#gte no value or fuction given'
25
+ def compare(op)
26
+ fail 'Streamer::Functor::Compare no comparison' unless valid_compare
27
+ compare_function(op) || compare_value(op) || compare_property(op)
28
+ end
29
+
30
+ def valid_compare
31
+ option_value || function || property
32
+ end
33
+
34
+ def compare_function(op_symbol)
35
+ return unless function
36
+ functor(function).call.send(op_symbol, target(options.fetch(:target)))
37
+ end
38
+
39
+ def compare_value(op_symbol)
40
+ return if option_value.nil?
41
+ option_value.send(op_symbol, target(options.fetch(:target)))
42
+ end
43
+
44
+ def compare_property(op_symbol)
45
+ return if property.nil?
46
+ prop(property).send(op_symbol, target(options.fetch(:target)))
28
47
  end
29
48
 
30
49
  def numerify(terms)
@@ -39,8 +58,8 @@ module Streamer
39
58
  payload.dig(*p.split('.'))
40
59
  end
41
60
 
42
- def functor(function_hash)
43
- Functor.new(payload, function_hash)
61
+ def functor(function_hash, pl = payload)
62
+ Functor.new(pl, function_hash)
44
63
  end
45
64
 
46
65
  def target(options)
@@ -54,6 +73,18 @@ module Streamer
54
73
  return data.map { |x| value(pk, x) } if data.is_a? Array
55
74
  value(pk, data)
56
75
  end
76
+
77
+ def function
78
+ options[:function]
79
+ end
80
+
81
+ def option_value
82
+ options[:value]
83
+ end
84
+
85
+ def property
86
+ options[:property]
87
+ end
57
88
  end
58
89
  end
59
90
  end
@@ -0,0 +1,25 @@
1
+ module Streamer
2
+ module Functors
3
+ # ListFilter returns items in the list matching the filter parameters
4
+ class ListFilter < Functor
5
+ attr_reader :list
6
+ def call
7
+ @list = payload[options.fetch(:list)]
8
+ reduce_list(options.fetch(:filters))
9
+ end
10
+
11
+ def reduce_list(filters)
12
+ list.each_with_object([]) do |item, val|
13
+ val << item if match(item, filters)
14
+ end
15
+ end
16
+
17
+ def match(item, filters)
18
+ filters.inject(true) do |val, filter|
19
+ val &&= functor(filter[:function], item).call
20
+ val
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -7,6 +7,7 @@ require 'streamer/functors/group'
7
7
  require 'streamer/functors/gt'
8
8
  require 'streamer/functors/gte'
9
9
  require 'streamer/functors/least'
10
+ require 'streamer/functors/list_filter'
10
11
  require 'streamer/functors/lookup'
11
12
  require 'streamer/functors/lt'
12
13
  require 'streamer/functors/lte'
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Streamer
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.1.1'.freeze
4
4
  end
data/script/itest ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ docker-compose run --rm guard guard
4
+
data/script/test CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/bin/bash
2
2
 
3
- docker-compose run --rm guard guard
3
+ docker-compose run --rm guard guard -i -p
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.1.0
4
+ version: 0.1.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-08 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -190,6 +190,7 @@ files:
190
190
  - lib/streamer/functors/gt.rb
191
191
  - lib/streamer/functors/gte.rb
192
192
  - lib/streamer/functors/least.rb
193
+ - lib/streamer/functors/list_filter.rb
193
194
  - lib/streamer/functors/lookup.rb
194
195
  - lib/streamer/functors/lt.rb
195
196
  - lib/streamer/functors/lte.rb
@@ -202,6 +203,7 @@ files:
202
203
  - lib/streamer/version.rb
203
204
  - script/console
204
205
  - script/init
206
+ - script/itest
205
207
  - script/shell
206
208
  - script/stop
207
209
  - script/test