Class: Amigo::Select

Inherits:
Object show all
Includes:
Hamster::Immutable
Defined in:
lib/amigo/select.rb

Instance Method Summary collapse

Constructor Details

#initialize(first_variable, *other_variables) ⇒ Select

Returns a new instance of Select.



16
17
18
19
# File 'lib/amigo/select.rb', line 16

def initialize(first_variable, *other_variables)
  @variables = Variables.new(first_variable, *other_variables)
  @where_clauses = Hamster.list
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


41
42
43
44
45
46
# File 'lib/amigo/select.rb', line 41

def eql?(other)
  return true if other.equal?(self)
  other.class.equal?(self.class) &&
    @variables.eql?(other.instance_variable_get(:@variables)) &&
    @where_clauses.eql?(other.instance_variable_get(:@where_clauses))
end

#execute(triples) ⇒ Object



31
32
33
34
35
# File 'lib/amigo/select.rb', line 31

def execute(triples)
  @where_clauses.
    reduce(InitialResult.new(@variables, triples), &:add).
    solutions
end

#from(store) ⇒ Object



27
28
29
# File 'lib/amigo/select.rb', line 27

def from(store)
  store.execute(self)
end

#hashObject



49
50
51
# File 'lib/amigo/select.rb', line 49

def hash
  @variables.hash ^ @where_clauses.hash
end

#to_sparqlObject



37
38
39
# File 'lib/amigo/select.rb', line 37

def to_sparql
  "SELECT #{@variables.to_sparql} WHERE {#{@where_clauses.reverse.map(&:to_sparql).join(" ")}}"
end

#where(subject, predicate, object) ⇒ Object



21
22
23
24
25
# File 'lib/amigo/select.rb', line 21

def where(subject, predicate, object)
  transform {
    @where_clauses = @where_clauses.cons(Amigo::Where.new(subject, predicate, object))
  }
end