class SexpPath::SexpResult
Wraps the results of a SexpPath
query. The matching Sexp
is placed in SexpResult#sexp
. Any named captures will be available with SexpResult#[].
For instance:
res = s(:a) / Q?{ s( _ % 'name') } res.first.sexp == s(:a) res.first['name'] == :a
Attributes
sexp[RW]
Public Class Methods
new(sexp, data={})
click to toggle source
# File lib/sexp_path/sexp_result.rb, line 16 def initialize(sexp, data={}) @sexp = sexp merge! data end
Public Instance Methods
inspect()
click to toggle source
# File lib/sexp_path/sexp_result.rb, line 37 def inspect "#{@sexp} #{super}" end
search(pattern, data={})
click to toggle source
Shortcut for querying directly against a result’s Sexp
.
# File lib/sexp_path/sexp_result.rb, line 23 def search(pattern, data={}) @sexp.search(pattern,data) end
Also aliased as: /
to_s()
click to toggle source
# File lib/sexp_path/sexp_result.rb, line 28 def to_s if empty? @sexp.to_s else matches = self.map{|k,v| "#{k}:#{v}"}.join(", ") "#{@sexp} [#{matches}]" end end