Class: LookbookVisualTester::ScenarioFinder

Inherits:
Service
  • Object
show all
Defined in:
lib/lookbook_visual_tester/scenario_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Service

call

Constructor Details

#initialize(search, fuzzy: true, previews: Lookbook.previews) ⇒ ScenarioFinder

Returns a new instance of ScenarioFinder.



8
9
10
11
12
# File 'lib/lookbook_visual_tester/scenario_finder.rb', line 8

def initialize(search, fuzzy: true, previews: Lookbook.previews)
  @search = search
  @fuzzy = fuzzy
  @previews = previews
end

Instance Attribute Details

#fuzzeObject (readonly)

Returns the value of attribute fuzze.



6
7
8
# File 'lib/lookbook_visual_tester/scenario_finder.rb', line 6

def fuzze
  @fuzze
end

#previewsObject (readonly)

Returns the value of attribute previews.



6
7
8
# File 'lib/lookbook_visual_tester/scenario_finder.rb', line 6

def previews
  @previews
end

#searchObject (readonly)

Returns the value of attribute search.



6
7
8
# File 'lib/lookbook_visual_tester/scenario_finder.rb', line 6

def search
  @search
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lookbook_visual_tester/scenario_finder.rb', line 22

def call
  return nil if search.nil? || search == '' || previews.empty?

  previews.each do |preview|
    preview.scenarios.each do |scenario|
      return ScenarioRun.new(scenario) if scenario.name.downcase.include?(search.downcase)
    end
  end

  nil
end

#matched_previewsObject



18
19
20
# File 'lib/lookbook_visual_tester/scenario_finder.rb', line 18

def matched_previews
  @matched_previews ||= previews.select { |preview| regex.match?(preview.name.downcase) }
end

#regexObject



14
15
16
# File 'lib/lookbook_visual_tester/scenario_finder.rb', line 14

def regex
  @regex = Regexp.new(search.chars.join('.*'), Regexp::IGNORECASE)
end