Class: BitOperation

Inherits:
BitAnalytics show all
Includes:
MixinContains, MixinCounts, MixinEventsMisc, RedisConnection
Defined in:
lib/bit_analytics.rb

Overview

Base class for bit operations (AND, OR, XOR). Please note that each bit operation creates a new key prefixed with ‘bitanalytics_bitop_`. These temporary keys can be deleted with `delete_temporary_bitop_keys`. You can even nest bit operations.

Example

active_2_months = @bit_analytics.bit_op_and(
    @bit_analytics.month_events('active', last_month.year, last_month.month),
    @bit_analytics.month_events('active', now.year, now.month)
)
active_2_months = @bit_analytics.bit_op_and(
    @bit_analytics.bit_op_and(
        @bit_analytics.month_events('active', last_month.year, last_month.month),
        @bit_analytics.month_events('active', now.year, now.month)
    ),
    @bit_analytics.month_events('active', now.year, now.month)
)

Constant Summary

Constants inherited from BitAnalytics

BitAnalytics::VERSION

Instance Attribute Summary

Attributes inherited from BitAnalytics

#redis

Instance Method Summary collapse

Methods inherited from BitAnalytics

#_prefix_key, #bit_op_and, #bit_op_or, #bit_op_xor, #day_events, #delete_all_events, #delete_temporary_bitop_keys, #hour_events, #mark_event, #month_events, #week_events

Constructor Details

#initialize(op_name, *events) ⇒ BitOperation

Returns a new instance of BitOperation.



251
252
253
254
255
# File 'lib/bit_analytics.rb', line 251

def initialize(op_name, *events)
  @op_name = op_name
  @event_redis_keys = events.map(&:redis_key)
  @redis_key = 'bitanalytics_bitop_%s_%s' % [@op_name, @event_redis_keys.join('-')]
end

Instance Method Details

#executeObject



257
258
259
# File 'lib/bit_analytics.rb', line 257

def execute
  @redis.bitop(@op_name, @redis_key, @event_redis_keys)
end