Sha256: 488950e5c1954367a68d64210a938ed525a92443baebb93b41a06f80d897b82b

Contents?: true

Size: 1.36 KB

Versions: 17

Compression:

Stored size: 1.36 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["name"]
        if feature["tags"]
          feature_text += " " + feature["tags"].map { |tag| tag["name"] }.join(" ")
        end
        if feature["description"]
          feature_text += " " + feature["description"]
        end
        feature_data = OpenStruct.new
        feature_data.feature = feature
        feature_data.text = feature_text
        searchables << feature_data

        if feature["elements"]
          feature["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
            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

17 entries across 17 versions & 1 rubygems

Version Path
wally-0.0.29 lib/wally/search_features.rb
wally-0.0.28 lib/wally/search_features.rb
wally-0.0.27 lib/wally/search_features.rb
wally-0.0.26 lib/wally/search_features.rb
wally-0.0.25 lib/wally/search_features.rb
wally-0.0.24 lib/wally/search_features.rb
wally-0.0.22 lib/wally/search_features.rb
wally-0.0.21 lib/wally/search_features.rb
wally-0.0.20 lib/wally/search_features.rb
wally-0.0.19 lib/wally/search_features.rb
wally-0.0.18 lib/wally/search_features.rb
wally-0.0.17 lib/wally/search_features.rb
wally-0.0.16 lib/wally/search_features.rb
wally-0.0.15 lib/wally/search_features.rb
wally-0.0.14 lib/wally/search_features.rb
wally-0.0.13 lib/wally/search_features.rb
wally-0.0.12 lib/wally/search_features.rb