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



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lookbook_visual_tester/scenario_finder.rb', line 26

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

  previews.each do |preview|
    preview.scenarios.each do |scenario|
      name = "#{preview.name} #{scenario.name}".downcase
      return ScenarioRun.new(scenario) if regex.match?(name.downcase) #name.downcase.include?(clean_search)
    end
  end

  nil
end

#clean_searchObject



22
23
24
# File 'lib/lookbook_visual_tester/scenario_finder.rb', line 22

def clean_search
  @clean_search ||= search.downcase.gsub(/[^a-z0-9\s]/, '').strip
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(clean_search.chars.join('.*'), Regexp::IGNORECASE)
end