Class: Bluecap::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/bluecap/handlers/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Event

Initialize an Event handler.

data - A Hash containing event data:

:id        - The Integer identifer of the user that generated
             the event.
:name      - The String type of event.
:timestamp - The Integer UNIX timestamp when the event was created,
             defaults to current time (optional).

Examples

Bluecap::Event.new(
  id: 3,
  name: 'Created Account',
  timestamp: 1341845456
)


24
25
26
27
28
# File 'lib/bluecap/handlers/event.rb', line 24

def initialize(data)
  @id = data.fetch(:id)
  @name = data.fetch(:name)
  @timestamp = data.fetch(:timestamp, Time.now.to_i)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/bluecap/handlers/event.rb', line 6

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/bluecap/handlers/event.rb', line 6

def name
  @name
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



6
7
8
# File 'lib/bluecap/handlers/event.rb', line 6

def timestamp
  @timestamp
end

Instance Method Details

#dateObject

Converts the object’s timestamp to a %Y%m%d String.

Returns the String date.



33
34
35
# File 'lib/bluecap/handlers/event.rb', line 33

def date
  Time.at(@timestamp).strftime('%Y%m%d')
end

#handleObject

Store the user’s event in a bitset of all the events matching that name for the date.

Returns nil.



48
49
50
51
52
# File 'lib/bluecap/handlers/event.rb', line 48

def handle
  Bluecap.redis.setbit(key, @id, 1)

  nil
end

#keyObject

Proxy for an event key.

Returns the String key.



40
41
42
# File 'lib/bluecap/handlers/event.rb', line 40

def key
  Bluecap::Keys.event(@name, date)
end