Class: OnboardOnRails::TourMatcher

Inherits:
Object
  • Object
show all
Defined in:
app/services/onboard_on_rails/tour_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user:, url:, session_id: nil, device_type: nil, request: nil) ⇒ TourMatcher

Returns a new instance of TourMatcher.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/services/onboard_on_rails/tour_matcher.rb', line 5

def initialize(user:, url:, session_id: nil, device_type: nil, request: nil)
  @user = user
  @url = url
  @session_id = session_id
  @device_type = device_type

  context_proc = OnboardOnRails.configuration.resolve_context
  context_proc.call(user, request) if context_proc && request

  @user_attributes = OnboardOnRails.configuration.resolve_attributes(user)
  @current_step_index = 0
end

Instance Attribute Details

#current_step_indexObject (readonly)

Returns the value of attribute current_step_index.



3
4
5
# File 'app/services/onboard_on_rails/tour_matcher.rb', line 3

def current_step_index
  @current_step_index
end

Instance Method Details

#matchObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/onboard_on_rails/tour_matcher.rb', line 18

def match
  # First: try to resume an in-progress tour
  resumed = find_in_progress_tour
  return resumed if resumed && matches_device?(resumed)

  # Otherwise: normal matching for new tours
  candidates = base_scope.to_a
  candidates = candidates.select { |t| t.matches_url?(@url) }
  candidates = candidates.select { |t| t.matches_segment?(@user_attributes) }
  candidates = candidates.select { |t| matches_device?(t) }
  candidates = candidates.reject { |t| excluded_by_frequency?(t) }
  candidates = candidates.reject { |t| excluded_by_event_trigger?(t) }
  candidates = candidates.select { |t| included_by_ab_test?(t) }

  result = candidates.max_by(&:priority)
  @current_step_index = 0
  result
end