Module: Trivet::Querier

Included in:
Document, Node
Defined in:
lib/trivet.rb

Overview

This module provides the query_first() method for Trivet::Node and Trivet::Document.

Instance Method Summary collapse

Instance Method Details

#query_first(qobj, opts = {}) ⇒ Object

Works like query(), but only returns/yields the first find.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/trivet.rb', line 45

def query_first(qobj, opts={})
  # run a query
  query(qobj, opts) do |node|
    # yield
    if block_given?
      yield node
    end
    
    # return
    return node
  end
  
  # didn't find any such node
  return nil
end