streamer 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/streamer/functors/functor.rb +41 -10
- data/lib/streamer/functors/list_filter.rb +25 -0
- data/lib/streamer/functors.rb +1 -0
- data/lib/streamer/version.rb +1 -1
- data/script/itest +4 -0
- data/script/test +1 -1
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 90dbc68e3c8adf372f06c4381cc35b74dc080534
         | 
| 4 | 
            +
              data.tar.gz: 71c4278b1e1aac8d7b7f602f4102758207f9cdfe
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: bdc5d83f093256515d60679c91d419d3d9c8a26ddf889bd8c47a36ba0dcd200fa7c63d1c82a9a344248dc8605cf2d66208960264ab4bdd538cbd8358dfec448a
         | 
| 7 | 
            +
              data.tar.gz: edcc7555b28a958055e362fcde5dbc27004e94b209ed864eb34ef16ac5e1b1ae8b7fadfb75f5c676a5998ef68d252e31e41ba8bcde7c125638f95be592f2a25e
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,6 @@ | |
| 1 1 | 
             
            # Streamer
         | 
| 2 2 |  | 
| 3 | 
            +
            [](https://badge.fury.io/rb/streamer)
         | 
| 3 4 | 
             
            [](https://travis-ci.org/scotthelm/streamer)
         | 
| 4 5 | 
             
            [](https://codeclimate.com/github/scotthelm/streamer)
         | 
| 5 6 | 
             
            [](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::#{ | 
| 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( | 
| 22 | 
            -
                     | 
| 23 | 
            -
                     | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
                     | 
| 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( | 
| 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
         | 
    
        data/lib/streamer/functors.rb
    CHANGED
    
    | @@ -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'
         | 
    
        data/lib/streamer/version.rb
    CHANGED
    
    
    
        data/script/itest
    ADDED
    
    
    
        data/script/test
    CHANGED
    
    
    
        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. | 
| 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- | 
| 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
         |