class Kitchen::SearchHistory

Records the search history that was used to find a certain element

Attributes

latest[R]
upstream[R]

Public Class Methods

empty() click to toggle source

Returns an empty search history

@return [SearchHistory]

# File lib/kitchen/search_history.rb, line 14
def self.empty
  new
end
new(upstream=nil, latest=nil) click to toggle source

Create a new instance

@param upstream [SearchHistory] prior search history @param latest [SearchQuery] the new history

# File lib/kitchen/search_history.rb, line 64
def initialize(upstream=nil, latest=nil)
  raise 'Upstream must be a SearchHistory' unless upstream.nil? || upstream.is_a?(SearchHistory)
  raise 'Latest must be a SearchQuery' unless latest.nil? || latest.is_a?(SearchQuery)

  @upstream = upstream
  @latest = latest
end

Public Instance Methods

add(search_query) click to toggle source

Returns a new SearchHistory that contains the current history plus the provided query

@param search_query [SearchQuery] the search query to add to the history @return [SearchHistory]

# File lib/kitchen/search_history.rb, line 24
def add(search_query)
  search_query = SearchQuery.new(css_or_xpath: search_query) if search_query.is_a?(String)
  self.class.new(self, search_query)
end
empty?() click to toggle source

Returns true if the search history is empty

@return [Boolean]

# File lib/kitchen/search_history.rb, line 53
def empty?
  upstream.nil? && latest.nil?
end
to_a() click to toggle source

Returns this instance as an array of selectors

@return [Array<String>]

# File lib/kitchen/search_history.rb, line 45
def to_a
  empty? ? [] : [upstream&.to_a || [], latest].flatten
end
to_s(missing_string='?') click to toggle source

Returns the history as a string

@param missing_string [String] if there's a missing part of the history, this string

is used in its place

@return [String]

# File lib/kitchen/search_history.rb, line 35
def to_s(missing_string='?')
  array = to_a
  array.shift while array.any? && array[0].nil?
  array.map { |item| "[#{item || missing_string}]" }.join(' ')
end