Class: Boffin::Hit

Inherits:
Object
  • Object
show all
Defined in:
lib/boffin/hit.rb

Overview

Represents a Hit instance, immutable once created. Interacting with and instantiating Hit directly is not necessary.

Instance Method Summary collapse

Constructor Details

#initialize(tracker, type, instance, opts = {}) ⇒ Hit

Creates a new Hit instance

Parameters:

  • tracker (Tracker)

    Tracker that is issuing the hit

  • type (Symbol)

    Hit type identifier

  • instance (Object)

    The instance that is being hit, any object that responds to #to_member, #id, or #to_s

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :unique (Array) — default: []

    An array of which the first object is used to generate a session identifier for hit uniqueness

  • :increment (Fixnum) — default: 1

    The hit increment


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/boffin/hit.rb', line 19

def initialize(tracker, type, instance, opts = {})
  uniquenesses = opts.delete(:unique) || []
  @increment   = opts.delete(:increment) || 1
  @now         = Time.now
  @sessid      = Utils.uniquenesses_as_uid(uniquenesses)
  @type        = type
  @tracker     = tracker
  @instance    = instance
  @member      = Utils.object_as_member(@instance)
  store
  freeze
end