Class: Minuteman::BitOperations::WithData
- Inherits:
-
Struct
- Object
- Struct
- Minuteman::BitOperations::WithData
- 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
-
#data ⇒ Object
Returns the value of attribute data.
-
#redis ⇒ Object
Returns the value of attribute redis.
-
#source_key ⇒ Object
Returns the value of attribute source_key.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data
13 14 15 |
# File 'lib/minuteman/bit_operations/with_data.rb', line 13 def data @data end |
#redis ⇒ Object
Returns the value of attribute redis
13 14 15 |
# File 'lib/minuteman/bit_operations/with_data.rb', line 13 def redis @redis end |
#source_key ⇒ Object
Returns the value of attribute source_key
13 14 15 |
# File 'lib/minuteman/bit_operations/with_data.rb', line 13 def source_key @source_key end |
#type ⇒ Object
Returns the value of attribute type
13 14 15 |
# File 'lib/minuteman/bit_operations/with_data.rb', line 13 def type @type end |
Instance Method Details
#call ⇒ Object
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 |