Class: SexpPath::SexpResult
- Inherits:
-
Hash
- Object
- Hash
- SexpPath::SexpResult
- Defined in:
- lib/sexp_path/sexp_result.rb
Overview
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
Instance Attribute Summary collapse
-
#sexp ⇒ Object
Matched Sexp.
Instance Method Summary collapse
-
#initialize(sexp, data = {}) ⇒ SexpResult
constructor
A new instance of SexpResult.
- #inspect ⇒ Object
-
#search(pattern, data = {}) ⇒ Object
(also: #/)
Shortcut for querying directly against a result's Sexp.
- #to_s ⇒ Object
Constructor Details
#initialize(sexp, data = {}) ⇒ SexpResult
Returns a new instance of SexpResult.
16 17 18 19 |
# File 'lib/sexp_path/sexp_result.rb', line 16 def initialize(sexp, data={}) @sexp = sexp merge! data end |
Instance Attribute Details
#sexp ⇒ Object
Matched Sexp
14 15 16 |
# File 'lib/sexp_path/sexp_result.rb', line 14 def sexp @sexp end |
Instance Method Details
#inspect ⇒ Object
37 38 39 |
# File 'lib/sexp_path/sexp_result.rb', line 37 def inspect "#{@sexp} #{super}" end |
#search(pattern, data = {}) ⇒ Object Also known as: /
Shortcut for querying directly against a result's Sexp.
23 24 25 |
# File 'lib/sexp_path/sexp_result.rb', line 23 def search(pattern, data={}) @sexp.search(pattern,data) end |
#to_s ⇒ Object
28 29 30 31 32 33 34 35 |
# 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 |