Class: Saper::Arguments::XPath

Inherits:
Saper::Argument show all
Defined in:
lib/saper/arguments/xpath.rb

Instance Method Summary collapse

Methods inherited from Saper::Argument

[], #action, exists?, inherited, #initialize, #mandatory?, new, #normalize, #optional?, #serialize, #set, subclasses, #to_string, type, #value

Constructor Details

This class inherits a constructor from Saper::Argument

Instance Method Details

#valid?(value) ⇒ Boolean

TODO:

6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/saper/arguments/xpath.rb', line 6

def valid?(value)
  unless value.is_a?(String)
    return false
  end
  if value =~ Nokogiri::XML::Searchable::LOOKS_LIKE_XPATH
    return true
  end
  Nokogiri::CSS.parse(value.to_s)
rescue Nokogiri::CSS::SyntaxError
  false
else
  true
end