Class: Kitchen::SearchHistory
Overview
Records the search history that was used to find a certain element
Instance Attribute Summary collapse
-
#latest ⇒ Object
readonly
Returns the value of attribute latest.
-
#upstream ⇒ Object
readonly
Returns the value of attribute upstream.
Class Method Summary collapse
-
.empty ⇒ SearchHistory
Returns an empty search history.
Instance Method Summary collapse
-
#add(search_query) ⇒ SearchHistory
Returns a new
SearchHistory
that contains the current history plus the provided query. -
#empty? ⇒ Boolean
Returns true if the search history is empty.
-
#to_a ⇒ Array<String>
Returns this instance as an array of selectors.
-
#to_s(missing_string = '?') ⇒ String
Returns the history as a string.
Instance Attribute Details
#latest ⇒ Object (readonly)
Returns the value of attribute latest.
7 8 9 |
# File 'lib/kitchen/search_history.rb', line 7 def latest @latest end |
#upstream ⇒ Object (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
.empty ⇒ SearchHistory
Returns an empty search history
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
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
53 54 55 |
# File 'lib/kitchen/search_history.rb', line 53 def empty? upstream.nil? && latest.nil? end |
#to_a ⇒ Array<String>
Returns this instance as an array of selectors
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
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 |