Class: GaEvents::Event
- Inherits:
-
Object
- Object
- GaEvents::Event
- Defined in:
- lib/ga_events/event.rb
Instance Attribute Summary collapse
-
#event_name ⇒ Object
readonly
Returns the value of attribute event_name.
-
#event_params ⇒ Object
readonly
Returns the value of attribute event_params.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(event_name, event_params = {}) ⇒ Event
constructor
Default values are set here, see README.md for details.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#event_name ⇒ Object (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_params ⇒ Object (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_h ⇒ Object
18 19 20 |
# File 'lib/ga_events/event.rb', line 18 def to_h { event_name:, event_params: event_params.symbolize_keys } end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/ga_events/event.rb', line 14 def to_s JSON.generate({ __event__: event_name, **event_params }) end |