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

#id ⇒ Object (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#timestamp ⇒ Object (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

#date ⇒ Object

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

#handle ⇒ Object

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

#key ⇒ Object

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