Class: RDF::Query::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/query/result.rb

Overview

A set of bindings for a graph.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*bindings) ⇒ Result

Creates an instance of Result with the specified bindings.



14
15
16
17
# File 'lib/rdf/query/result.rb', line 14

def initialize(*bindings)
  @success = false
  @bindings = Set.new((bindings || []).flatten.reject{|b| b.empty?})
end

Instance Attribute Details

#bindingsObject (readonly)

Returns the value of attribute bindings.



11
12
13
# File 'lib/rdf/query/result.rb', line 11

def bindings
  @bindings
end

Class Method Details

.success!(*a) ⇒ Object



5
6
7
8
9
# File 'lib/rdf/query/result.rb', line 5

def self.success!(*a)
  r = Result.new(*a)
  r.success!
  r
end

Instance Method Details

#<<(o) ⇒ Object

Merges the Result o into this Result.

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rdf/query/result.rb', line 35

def <<(o)
  raise ArgumentError, "Must be RDF::Query::Result" unless o.is_a?(Result)
  if o.success?
    if failure?
      success!
      bindings.clear
    end
    
    o.bindings.each do |b|
      bindings << b unless b.empty?
    end
  end
end

#failure?Boolean

Returns true if the executed query failed.

Returns:

  • (Boolean)


20
21
22
# File 'lib/rdf/query/result.rb', line 20

def failure?
  !@success
end

#success!Object

Sets the success indicator to true.



30
31
32
# File 'lib/rdf/query/result.rb', line 30

def success!
  @success = true
end

#success?Boolean

Returns true if the executed query succeeded.

Returns:

  • (Boolean)


25
26
27
# File 'lib/rdf/query/result.rb', line 25

def success?
  @success
end

#to_sObject



49
50
51
# File 'lib/rdf/query/result.rb', line 49

def to_s
  "{#{bindings.collect{|b| b.to_s}.join(', ')}}"
end