Class: Minuteman::BitOperations::WithData

Inherits:
Struct
  • Object
show all
Includes:
KeysMethods
Defined in:
lib/minuteman/bit_operations/with_data.rb

Overview

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

Constant Summary

Constants included from KeysMethods

KeysMethods::BIT_OPERATION_PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



13
14
15
# File 'lib/minuteman/bit_operations/with_data.rb', line 13

def data
  @data
end

#redisObject

Returns the value of attribute redis

Returns:

  • (Object)

    the current value of redis



13
14
15
# File 'lib/minuteman/bit_operations/with_data.rb', line 13

def redis
  @redis
end

#source_keyObject

Returns the value of attribute source_key

Returns:

  • (Object)

    the current value of source_key



13
14
15
# File 'lib/minuteman/bit_operations/with_data.rb', line 13

def source_key
  @source_key
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



13
14
15
# File 'lib/minuteman/bit_operations/with_data.rb', line 13

def type
  @type
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/minuteman/bit_operations/with_data.rb', line 16

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