Sha256: 387e7ada52cb27aaac57c1dd1b607c55eb63efe230cb40c46b79bf77313f7eaa

Contents?: true

Size: 1.43 KB

Versions: 14

Compression:

Stored size: 1.43 KB

Contents

require "komainu"

module Wally
  class SearchFeatures
    def initialize lists_features
      @lists_features = lists_features
    end

    def find(query)
      searchables = []

      @lists_features.features.each do |feature|
        feature_text = feature.gherkin["name"]
        if feature.gherkin["tags"]
          feature_text += " " + feature.gherkin["tags"].map { |tag| tag["name"] }.join(" ")
        end
        if feature.gherkin["description"]
          feature_text += " " + feature.gherkin["description"]
        end
        feature_data = OpenStruct.new
        feature_data.feature = feature.gherkin
        feature_data.text = feature_text
        searchables << feature_data

        if feature.gherkin["elements"]
          feature.gherkin["elements"].each do |element|
            element_text = [element["name"]]
            if element["steps"]
              element_text << element["steps"].map { |s| s["name"] }
            end
            if element["tags"]
              element_text << element["tags"].map { |t| t["name"] }
            end
            scenario_data = OpenStruct.new
            scenario_data.feature = feature.gherkin
            scenario_data.scenario = element
            scenario_data.text = element_text.join(" ")
            searchables << scenario_data
          end
        end
      end

      searches_text = Komainu::SearchesText.new(searchables)
      searches_text.search(query[:query])
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
wally-0.0.47 lib/wally/search_features.rb
wally-0.0.46 lib/wally/search_features.rb
wally-0.0.45 lib/wally/search_features.rb
wally-0.0.44 lib/wally/search_features.rb
wally-0.0.43 lib/wally/search_features.rb
wally-0.0.42 lib/wally/search_features.rb
wally-0.0.41 lib/wally/search_features.rb
wally-0.0.40 lib/wally/search_features.rb
wally-0.0.39 lib/wally/search_features.rb
wally-0.0.38 lib/wally/search_features.rb
wally-0.0.37 lib/wally/search_features.rb
wally-0.0.36 lib/wally/search_features.rb
wally-0.0.35 lib/wally/search_features.rb
wally-0.0.34 lib/wally/search_features.rb