Class: Hackle::Event

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

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, value:, properties:) ⇒ Event

Returns a new instance of Event.

Parameters:

  • key (String)
  • value (Numeric, nil)
  • properties (Hash{String => Object})


19
20
21
22
23
# File 'lib/hackle/event.rb', line 19

def initialize(key:, value:, properties:)
  @key = key
  @value = value
  @properties = properties
end

Instance Attribute Details

#keyString (readonly)

Returns:

  • (String)


8
9
10
# File 'lib/hackle/event.rb', line 8

def key
  @key
end

#propertiesHash{String => Object} (readonly)

Returns:

  • (Hash{String => Object})


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

def properties
  @properties
end

#valueFloat? (readonly)

Returns:

  • (Float, nil)


11
12
13
# File 'lib/hackle/event.rb', line 11

def value
  @value
end

Class Method Details

.builder(key) ⇒ Hackle::Event::Builder

Parameters:

  • key (String)

Returns:



49
50
51
# File 'lib/hackle/event.rb', line 49

def self.builder(key)
  Builder.new(key)
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/hackle/event.rb', line 39

def ==(other)
  other.is_a?(Event) && other.key == key && other.value == value && other.properties == properties
end

#error_or_nilString?

Returns:

  • (String, nil)


31
32
33
34
35
36
37
# File 'lib/hackle/event.rb', line 31

def error_or_nil
  return "Invalid event key: #{key} (expected: not empty string)" unless ValueType.not_empty_string?(key)
  return "Invalid event value: #{value} (expected: number)" if !value.nil? && !ValueType.number?(value)
  return "Invalid event properties: #{properties} (expected: Hash)" if !properties.nil? && !properties.is_a?(Hash)

  nil
end

#to_sObject



43
44
45
# File 'lib/hackle/event.rb', line 43

def to_s
  "Hackle::Event(key: #{key}, value: #{value}, properties: #{properties})"
end

#valid?boolean

Returns:

  • (boolean)


26
27
28
# File 'lib/hackle/event.rb', line 26

def valid?
  error_or_nil.nil?
end