Class: Kitchen::SearchQuery
Overview
Records the search history that was used to find a certain element
Instance Attribute Summary collapse
-
#css_or_xpath ⇒ Object
readonly
Returns the value of attribute css_or_xpath.
-
#except ⇒ Object
readonly
Returns the value of attribute except.
-
#only ⇒ Object
readonly
Returns the value of attribute only.
Instance Method Summary collapse
-
#apply_default_css_or_xpath_and_normalize(default_css_or_xpath = nil, config: nil) ⇒ Object
Replaces ‘$’ in the ‘css_or_xpath` with the provided value; also normalizes `css_or_xpath` to an array.
-
#as_type ⇒ Object
Returns the search query as a spaceless string suitable for use as an element type.
-
#conditions_match?(element) ⇒ Boolean
Returns true iff the element passes the ‘only` and `except` conditions.
-
#expects_substitution? ⇒ Boolean
Returns true if the query has the substitution character (‘$’).
-
#initialize(css_or_xpath: nil, only: nil, except: nil) ⇒ SearchQuery
constructor
Create a new SearchQuery.
-
#to_s ⇒ Object
Returns a string representation of the search query.
Constructor Details
#initialize(css_or_xpath: nil, only: nil, except: nil) ⇒ SearchQuery
Create a new SearchQuery
23 24 25 26 27 28 |
# File 'lib/kitchen/search_query.rb', line 23 def initialize(css_or_xpath: nil, only: nil, except: nil) @css_or_xpath = css_or_xpath @only = only.is_a?(String) ? only.to_sym : only @except = except.is_a?(String) ? except.to_sym : except @default_already_applied = false end |
Instance Attribute Details
#css_or_xpath ⇒ Object (readonly)
Returns the value of attribute css_or_xpath.
7 8 9 |
# File 'lib/kitchen/search_query.rb', line 7 def css_or_xpath @css_or_xpath end |
#except ⇒ Object (readonly)
Returns the value of attribute except.
9 10 11 |
# File 'lib/kitchen/search_query.rb', line 9 def except @except end |
#only ⇒ Object (readonly)
Returns the value of attribute only.
8 9 10 |
# File 'lib/kitchen/search_query.rb', line 8 def only @only end |
Instance Method Details
#apply_default_css_or_xpath_and_normalize(default_css_or_xpath = nil, config: nil) ⇒ Object
Replaces ‘$’ in the ‘css_or_xpath` with the provided value; also normalizes `css_or_xpath` to an array.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/kitchen/search_query.rb', line 47 def apply_default_css_or_xpath_and_normalize(default_css_or_xpath=nil, config: nil) return if @default_already_applied default_css_or_xpath = [default_css_or_xpath].flatten.map do |item| case item when Proc item.call(config) when Symbol config.selectors.send(item) else item end end @as_type = nil @css_or_xpath = [css_or_xpath || '$'].flatten.map do |item| item.gsub(/\$/, default_css_or_xpath.join(', ')) end @default_already_applied = true end |
#as_type ⇒ Object
Returns the search query as a spaceless string suitable for use as an element type
71 72 73 74 75 76 77 |
# File 'lib/kitchen/search_query.rb', line 71 def as_type @as_type ||= [ [css_or_xpath].flatten.join(','), stringify_condition(only, 'only'), stringify_condition(except, 'except') ].compact.join(';') end |
#conditions_match?(element) ⇒ Boolean
Returns true iff the element passes the ‘only` and `except` conditions
34 35 36 |
# File 'lib/kitchen/search_query.rb', line 34 def conditions_match?(element) condition_passes?(except, element, false) && condition_passes?(only, element, true) end |
#expects_substitution? ⇒ Boolean
Returns true if the query has the substitution character (‘$’)
87 88 89 |
# File 'lib/kitchen/search_query.rb', line 87 def expects_substitution? css_or_xpath.nil? || [css_or_xpath].flatten.all? { |item| item.include?('$') } end |
#to_s ⇒ Object
Returns a string representation of the search query
81 82 83 |
# File 'lib/kitchen/search_query.rb', line 81 def to_s as_type end |