Class: Kitchen::SearchHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/search_history.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#latestObject (readonly)

Returns the value of attribute latest.



7
8
9
# File 'lib/kitchen/search_history.rb', line 7

def latest
  @latest
end

#upstreamObject (readonly)

Returns the value of attribute upstream.



8
9
10
# File 'lib/kitchen/search_history.rb', line 8

def upstream
  @upstream
end

Class Method Details

.emptySearchHistory

Returns an empty search history

Returns:



14
15
16
# File 'lib/kitchen/search_history.rb', line 14

def self.empty
  new
end

Instance Method Details

#add(search_query) ⇒ SearchHistory

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

Parameters:

  • search_query (SearchQuery)

    the search query to add to the history

Returns:



24
25
26
27
# 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?Boolean

Returns true if the search history is empty

Returns:

  • (Boolean)


53
54
55
# File 'lib/kitchen/search_history.rb', line 53

def empty?
  upstream.nil? && latest.nil?
end

#to_aArray<String>

Returns this instance as an array of selectors

Returns:



45
46
47
# File 'lib/kitchen/search_history.rb', line 45

def to_a
  empty? ? [] : [upstream&.to_a || [], latest].flatten
end

#to_s(missing_string = '?') ⇒ String

Returns the history as a string

Parameters:

  • missing_string (String) (defaults to: '?')

    if there’s a missing part of the history, this string is used in its place

Returns:



35
36
37
38
39
# 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