Sha256: ff46e7990c709ea77e8e6fe44508dd852254c1c852f4554262cb6dd04605fbd1

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

module Wally
  class SearchFeatures
    def find(query)
      results = []
      ListsFeatures.features.each do |feature|
        result = SearchResult.new(feature)

        if feature["tags"]
          feature["tags"].each do |tag|
            if tag["name"].downcase.include? query[:query].downcase
              result.matched_feature = feature
            end
          end
        end

        if feature["name"].downcase.include? query[:query].downcase
          result.matched_feature = feature
        end

        if feature["elements"]
          result.matched_scenarios = feature["elements"].select do |element|
            if element["name"].downcase.include? query[:query].downcase
              true
            elsif element["steps"]
              element["steps"].any? do |step|
                step["name"].downcase.include? query[:query].downcase
              end
            elsif element["tags"]
              element["tags"].any? do |tag|
                tag["name"].downcase.include? query[:query].downcase
              end
            end
          end
        end

        if result.matches?
          results << result
        end
      end
      results
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wally-0.0.2 lib/wally/search_features.rb
wally-0.0.1 lib/wally/search_features.rb