minuteman 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- minuteman (0.0.2)
4
+ minuteman (0.1.0)
5
5
  redis (~> 3.0.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -101,7 +101,19 @@ today_events.include?(User.all.map(&:id))
101
101
 
102
102
  ## Bitwise operations
103
103
 
104
- You can intersect sets using AND(`&`), OR(`|`), NOT(`-`) and XOR(`^`).
104
+ You can intersect sets using bitwise AND(`&`), OR(`|`), NOT(`-`) and XOR(`^`).
105
+ Also you can use plus(`+`) and minus(`-`) operations.
106
+
107
+ ```ruby
108
+ set1 + set2
109
+ set1 - set2
110
+ set1 & set2
111
+ set1 | set2
112
+ set1 ^ set2
113
+ -set1
114
+ ```
115
+
116
+ ### Example
105
117
 
106
118
  ```ruby
107
119
  invited = analytics.month("email:invitation", Time.now.utc)
@@ -113,3 +125,13 @@ successful_buys_after_invitation.include?(user.id)
113
125
  # Clean up all the operations cache
114
126
  analytics.reset_operations_cache
115
127
  ```
128
+
129
+ Also you can write more complex set operations
130
+
131
+ ```ruby
132
+ invited = analytics.month("email:invitation")
133
+ from_adsense = analytics.month("adsense:promo")
134
+ successful_buys = analytics.month("buy:complete")
135
+
136
+ conversion_rate = (invited | from_adsense) & successful_buys
137
+ ```
@@ -29,6 +29,12 @@ class Minuteman
29
29
  bit_operation("NOT", key)
30
30
  end
31
31
 
32
+ # Public: Calculates the substract of one set to another
33
+ #
34
+ def -(timespan)
35
+ self ^ (self & timespan)
36
+ end
37
+
32
38
  # Public: Calculates the XOR against another timespan
33
39
  #
34
40
  # timespan: Another BitOperations enabled class
@@ -44,6 +50,7 @@ class Minuteman
44
50
  def |(timespan)
45
51
  bit_operation("OR", [key, timespan.key])
46
52
  end
53
+ alias :+ :|
47
54
 
48
55
  # Public: Calculates the AND against another timespan
49
56
  #
@@ -76,11 +83,15 @@ class Minuteman
76
83
  #
77
84
  def bit_operation(type, events)
78
85
  key = destination_key(type, Array(events))
79
- @redis.bitop(type, key, events)
80
- BitOperation.new(@redis, key)
86
+ redis.bitop(type, key, events)
87
+ BitOperation.new(redis, key)
81
88
  end
82
89
  end
83
90
 
91
+ # Public: The result of intersecting results
92
+ # redis - The Redis connection
93
+ # key - The key where the result it's stored
94
+ #
84
95
  class BitOperation < Struct.new(:redis, :key)
85
96
  include BitOperations
86
97
  end
data/minuteman.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "minuteman"
3
- s.version = "0.0.2"
3
+ s.version = "0.1.0"
4
4
  s.summary = "Bit Analytics"
5
5
  s.description = "Fast and furious tracking system using Redis bitwise operations"
6
6
  s.authors = ["elcuervo"]
@@ -110,4 +110,30 @@ describe Minuteman do
110
110
  assert !not_operation.include?(2)
111
111
  end
112
112
 
113
+ it "should have an alias for the OR operator" do
114
+ or_operation = @week_events + @last_week_events
115
+
116
+ assert @week_events.include?(2)
117
+ assert @last_week_events.include?(2)
118
+ assert !@last_week_events.include?(12)
119
+
120
+ assert_equal 3, or_operation.length
121
+
122
+ assert or_operation.include?(12)
123
+ assert or_operation.include?(2)
124
+ end
125
+
126
+ it "should accept the substraction of a set" do
127
+ substract_operation = @year_events - @week_events
128
+
129
+ assert @week_events.include?(2)
130
+ assert @year_events.include?(2)
131
+ assert !substract_operation.include?(2)
132
+ end
133
+
134
+ it "should accept multiple consecutive operations" do
135
+ multi_operation = @week_events & @last_week_events | @year_events
136
+
137
+ assert_kind_of Minuteman::BitOperation, multi_operation
138
+ end
113
139
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minuteman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-01 00:00:00.000000000 Z
12
+ date: 2012-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis