Class: GaEvents::Event

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_name, event_params = {}) ⇒ Event

Default values are set here, see README.md for details.



8
9
10
11
12
# File 'lib/ga_events/event.rb', line 8

def initialize(event_name, event_params = {})
  @event_name = event_name
  @event_params = event_params
  GaEvents::List << self
end

Instance Attribute Details

#event_nameObject (readonly)

Returns the value of attribute event_name.



5
6
7
# File 'lib/ga_events/event.rb', line 5

def event_name
  @event_name
end

#event_paramsObject (readonly)

Returns the value of attribute event_params.



5
6
7
# File 'lib/ga_events/event.rb', line 5

def event_params
  @event_params
end

Class Method Details

.from_hash(event_hash) ⇒ Object



26
27
28
29
30
# File 'lib/ga_events/event.rb', line 26

def self.from_hash(event_hash)
  if event_name = event_hash.delete('__event__')
    new(event_name, event_hash)
  end
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
35
# File 'lib/ga_events/event.rb', line 32

def ==(other)
  self.class == other.class && event_name == other.event_name &&
    event_params == other.event_params
end

#deconstruct_keys(keys) ⇒ Object



22
23
24
# File 'lib/ga_events/event.rb', line 22

def deconstruct_keys(keys)
  keys ? to_h.slice(*keys) : to_h
end

#to_hObject



18
19
20
# File 'lib/ga_events/event.rb', line 18

def to_h
  { event_name:, event_params: event_params.symbolize_keys }
end

#to_sObject



14
15
16
# File 'lib/ga_events/event.rb', line 14

def to_s
  JSON.generate({ __event__: event_name, **event_params })
end