Class: RDFMapper::Scope::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/lib/scope/condition.rb

Overview

-

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cls, att, value, eq = '=') ⇒ Condition

Returns a new instance of Condition.



10
11
12
# File 'lib/lib/scope/condition.rb', line 10

def initialize(cls, att, value, eq = '=')
  @cls, @att, @value, @eq = cls, att, value, eq
end

Instance Attribute Details

#eqObject (readonly)

Returns the value of attribute eq.



8
9
10
# File 'lib/lib/scope/condition.rb', line 8

def eq
  @eq
end

Instance Method Details

#inspectString

Developer-friendly representation of the instance.

Returns:

  • (String)


79
80
81
# File 'lib/lib/scope/condition.rb', line 79

def inspect #nodoc
  "#<Condition:(%s%s%s)>" % [name, eq, value]
end

#matches?(object) ⇒ Boolean

Checks whether specified object passes all conditions of the query.

Parameters:

Returns:

  • (Boolean)


42
43
44
# File 'lib/lib/scope/condition.rb', line 42

def matches?(object)
  object.send(name) == value
end

#nameObject

-


17
18
19
20
21
22
23
24
25
26
# File 'lib/lib/scope/condition.rb', line 17

def name
  if @att == :id
    return @att
  end
  if att = @cls.has?(@att)
    att.name
  else
    @att
  end
end

#to_statements(subject) ⇒ Object

-


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lib/scope/condition.rb', line 58

def to_statements(subject)
  if association?
    object = association.id
    rdf_type = association.to_triples(:short => true)
  else
    object = RDF::Query::Variable.new
    object.bind(value, eq)
    rdf_type = []
  end
  rdf_type + [{
    :subject => subject,
    :predicate => @cls.has?(@att).type,
    :object => object
  }]
end

#to_triples(subject) ⇒ Object

-


49
50
51
52
53
# File 'lib/lib/scope/condition.rb', line 49

def to_triples(subject)
  to_statements(subject).map do |statement|
    [ statement[:subject], statement[:predicate], statement[:object] ]
  end
end

#value(required = []) ⇒ Object Also known as: check

-


31
32
33
# File 'lib/lib/scope/condition.rb', line 31

def value(required = [])
  association? ? association(required) : literal
end