Module: Tripod::CriteriaExecution

Extended by:
ActiveSupport::Concern
Included in:
Criteria
Defined in:
lib/tripod/criteria/execution.rb

Overview

this module provides execution methods to a criteria object

Instance Method Summary collapse

Instance Method Details

#count(opts = {}) ⇒ Object

Return how many records the current criteria would return

Parameters:

  • options (Hash)

    a customizable set of options



43
44
45
46
47
48
# File 'lib/tripod/criteria/execution.rb', line 43

def count(opts={})
  sq = Tripod::SparqlQuery.new(build_select_query(opts))
  count_sparql = sq.as_count_query_str
  result = Tripod::SparqlClient::Query.select(count_sparql)
  result[0]["tripod_count_var"]["value"].to_i
end

#first(opts = {}) ⇒ Object

Execute the query and return the first result as a hydrated resource

Parameters:

  • options (Hash)

    a customizable set of options



34
35
36
37
38
# File 'lib/tripod/criteria/execution.rb', line 34

def first(opts={})
  sq = Tripod::SparqlQuery.new(build_select_query(opts))
  first_sparql = sq.as_first_query_str
  self.resource_class._resources_from_sparql(first_sparql).first
end

#resources(opts = {}) ⇒ Object

Execute the query and return a ResourceCollection of all hydrated resources ResourceCollection is an Enumerable, Array-like object.

Parameters:

  • options (Hash)

    a customizable set of options



13
14
15
16
17
18
19
20
# File 'lib/tripod/criteria/execution.rb', line 13

def resources(opts={})
  Tripod::ResourceCollection.new(
    self.resource_class._resources_from_sparql(build_select_query(opts)),
     # pass in the criteria that was used to generate this collection, as well as whether the user specified return graph
    :return_graph => (opts.has_key?(:return_graph) ? opts[:return_graph] : true),
    :criteria => self
  )
end

#serialize(opts = {}) ⇒ Object

run a query to get the raw serialisation of the results of this criteria object.

Parameters:

  • options (Hash)

    a customizable set of options



26
27
28
29
# File 'lib/tripod/criteria/execution.rb', line 26

def serialize(opts={})
  select_sparql = build_select_query(:return_graph => opts[:return_graph])
  self.resource_class._raw_describe_select_results(select_sparql, :accept_header => opts[:accept_header]) # note that this method defaults to using application/n-triples.
end