Class: Tripod::Criteria

Inherits:
Object
  • Object
show all
Includes:
CriteriaExecution
Defined in:
lib/tripod/criteria.rb

Overview

This module defines behaviour for criteria

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CriteriaExecution

#count, #first, #resources, #serialize

Constructor Details

#initialize(resource_class) ⇒ Criteria

Returns a new instance of Criteria.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tripod/criteria.rb', line 22

def initialize(resource_class)
  self.resource_class = resource_class
  self.where_clauses = []
  self.extra_clauses = []

  if resource_class._RDF_TYPE
    self.where("?uri a <#{resource_class._RDF_TYPE.to_s}>")
  end

  self.graph_uri = resource_class._GRAPH_URI.to_s if resource_class._GRAPH_URI
end

Instance Attribute Details

#extra_clausesObject

Returns the value of attribute extra_clauses.



15
16
17
# File 'lib/tripod/criteria.rb', line 15

def extra_clauses
  @extra_clauses
end

#graph_uriObject

Returns the value of attribute graph_uri.



20
21
22
# File 'lib/tripod/criteria.rb', line 20

def graph_uri
  @graph_uri
end

#limit_clauseObject

Returns the value of attribute limit_clause.



17
18
19
# File 'lib/tripod/criteria.rb', line 17

def limit_clause
  @limit_clause
end

#offset_clauseObject

Returns the value of attribute offset_clause.



19
20
21
# File 'lib/tripod/criteria.rb', line 19

def offset_clause
  @offset_clause
end

#order_clauseObject

Returns the value of attribute order_clause.



18
19
20
# File 'lib/tripod/criteria.rb', line 18

def order_clause
  @order_clause
end

#resource_classObject

the resource class that this criteria is for.



12
13
14
# File 'lib/tripod/criteria.rb', line 12

def resource_class
  @resource_class
end

#where_clausesObject

Returns the value of attribute where_clauses.



14
15
16
# File 'lib/tripod/criteria.rb', line 14

def where_clauses
  @where_clauses
end

Instance Method Details

#==(other) ⇒ Object

they’re equal if they return the same query



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

def ==(other)
  build_select_query == other.send(:build_select_query)
end

#extras(sparql_snippet) ⇒ Object

 takes a string and adds an extra clause to this criteria. e.g. my_criteria.extras(“LIMIT 10 OFFSET 20”).extrass

 TODO: make it also take a hash?



54
55
56
57
# File 'lib/tripod/criteria.rb', line 54

def extras(sparql_snippet)
  extra_clauses << sparql_snippet
  self
end

#graph(graph_uri) ⇒ Tripod::Criteria

Restrict htis query to the graph uri passed in

Examples:

.graph(RDF::URI.new(‘graphoid’)


.graph(‘graphoid’)


Parameters:

  • The (Stirng, RDF::URI)

    graph uri

Returns:



85
86
87
88
# File 'lib/tripod/criteria.rb', line 85

def graph(graph_uri)
  self.graph_uri = graph_uri.to_s
  self
end

#limit(the_limit) ⇒ Object

 replaces this criteria’s limit clause



60
61
62
63
# File 'lib/tripod/criteria.rb', line 60

def limit(the_limit)
  self.limit_clause = "LIMIT #{the_limit.to_s}"
  self
end

#offset(the_offset) ⇒ Object

 replaces this criteria’s offset clause



66
67
68
69
# File 'lib/tripod/criteria.rb', line 66

def offset(the_offset)
  self.offset_clause = "OFFSET #{the_offset.to_s}"
  self
end

#order(param) ⇒ Object

 replaces this criteria’s order clause



72
73
74
75
# File 'lib/tripod/criteria.rb', line 72

def order(param)
  self.order_clause = "ORDER BY #{param}"
  self
end

#where(sparql_snippet) ⇒ Object

 Takes a string and adds a where clause to this criteria. Returns a criteria object. Note: the subject being returned by the query must be identified by ?uri  e.g. my_criteria.where(“?uri a <my-type>”)

 TODO: make it also take a hash?



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

def where(sparql_snippet)
  where_clauses << sparql_snippet
  self
end