Class: Interfacets::Test::Js::Receivers::Timer

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/interfacets/test/js/receivers/timer.rb

Defined Under Namespace

Classes: Registration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:) ⇒ Timer

Returns a new instance of Timer.



28
29
30
31
# File 'lib/interfacets/test/js/receivers/timer.rb', line 28

def initialize(name:)
  @name = name
  @registrations = []
end

Instance Attribute Details

#name ⇒ Object (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/interfacets/test/js/receivers/timer.rb', line 27

def name
  @name
end

#registrations ⇒ Object (readonly)

Returns the value of attribute registrations.



27
28
29
# File 'lib/interfacets/test/js/receivers/timer.rb', line 27

def registrations
  @registrations
end

Instance Method Details

#clear ⇒ Object



70
71
72
# File 'lib/interfacets/test/js/receivers/timer.rb', line 70

def clear
  @registrations = []
end

#each(&block) ⇒ Object



66
67
68
# File 'lib/interfacets/test/js/receivers/timer.rb', line 66

def each(&block)
  registrations.each(&block)
end

#first ⇒ Object



58
59
60
# File 'lib/interfacets/test/js/receivers/timer.rb', line 58

def first
  registrations.first
end

#handler ⇒ Object



54
55
56
# File 'lib/interfacets/test/js/receivers/timer.rb', line 54

def handler
  self
end

#last ⇒ Object



62
63
64
# File 'lib/interfacets/test/js/receivers/timer.rb', line 62

def last
  registrations.last
end

#receive(payload:, dispatch:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/interfacets/test/js/receivers/timer.rb', line 33

def receive(payload:, dispatch:)
  @dispatch = dispatch

  return if payload.nil?
  return if payload.empty?
  return if payload.dig("streams", "default").nil?
  return if payload.dig("streams", "default").empty?

  event = payload.dig("streams", "default")
  ms = event["ms"]
  response_payload = event["response"]

  return unless ms && response_payload

  @registrations << Registration.new(
    ms: ms,
    response_payload: response_payload,
    dispatch: dispatch
  )
end