Sha256: 4824e48672cd4c6516d39996e7972856f08b8156abeca07093fa68779c797d18

Contents?: true

Size: 977 Bytes

Versions: 2

Compression:

Stored size: 977 Bytes

Contents

require "minuteman/keys_methods"
require "minuteman/bit_operations/data"

class Minuteman
  module BitOperations
    # Public: The class to handle operations with datasets
    #
    #   redis:      The Redis connection
    #   type:       The operation type
    #   data:       The data to be permuted
    #   source_key: The original key to do the operation
    #
    class WithData < Struct.new(:redis, :type, :data, :source_key)
      include KeysMethods

      def call
        normalized_data = Array(data)
        key = destination_key("data-#{type}", normalized_data)
        command = case type
                  when "AND"    then :select
                  when "MINUS"  then :reject
                  end

        intersected_data = normalized_data.send(command) do |id|
          redis.getbit(source_key, id) == 1
        end

        intersected_data.each { |id| redis.setbit(key, id, 1) }
        Data.new(redis, key, intersected_data)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
minuteman-0.2.0 lib/minuteman/bit_operations/with_data.rb
minuteman-0.2.0.pre lib/minuteman/bit_operations/with_data.rb