Class: SpectatorSport::Event

Inherits:
ApplicationRecord show all
Defined in:
app/models/spectator_sport/event.rb

Defined Under Namespace

Classes: Explanation

Constant Summary collapse

PAGE_LIMIT =
1_000
EVENT_TYPES =
%w[DomContentLoaded Load FullSnapshot IncrementalSnapshot Meta Custom]
EVENT_SOURCES =
%w[Mutation MouseMove MouseInteraction Scroll ViewportResize Input TouchMove MediaInteraction
StyleSheetRule CanvasMutation Font Log Drag StyleDeclaration Selection AdoptedStyleSheet]
MOUSE_INTERACTIONS =
%w[MouseUp MouseDown Click ContextMenu DblClick Focus Blur TouchStart TouchMove_Departed
TouchEnd TouchCancel]

Instance Method Summary collapse

Instance Method Details

#event_sourceObject



45
46
47
48
49
# File 'app/models/spectator_sport/event.rb', line 45

def event_source
  return unless event_data.dig("data", "source")

  EVENT_SOURCES[event_data.dig("data", "source")]
end

#event_typeObject



41
42
43
# File 'app/models/spectator_sport/event.rb', line 41

def event_type
  EVENT_TYPES[event_data["type"]]
end

#explanationObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/spectator_sport/event.rb', line 22

def explanation
  explanation = Explanation.new(title, [])

  if event_type == "Meta"
    explanation.details << "visited #{event_data.dig("data", "href")}"
  end

  if event_source
    explanation.details << "source: #{event_source}"
  end

  if event_source == "MouseInteraction"
    mouse_interaction = MOUSE_INTERACTIONS[event_data.dig("data", "type")]
    explanation.details << "#{mouse_interaction}"
  end

  explanation
end

#pageObject



60
61
62
# File 'app/models/spectator_sport/event.rb', line 60

def page
  event_data.dig("data", "href")
end

#titleObject



51
52
53
54
55
56
57
58
# File 'app/models/spectator_sport/event.rb', line 51

def title
  if event_type == "IncrementalSnapshot" && event_source == "MouseInteraction" &&
      MOUSE_INTERACTIONS[event_data.dig("data", "type")] == "Click"
    "Mouse Click"
  else
    event_type
  end
end